class Solution {
    public long maxMatrixSum(int[][] matrix) {
        int min = Integer.MAX_VALUE;
        long sum = 0;
        long mul = 1;
        int count = 0;
        for (int[] ints : matrix) {
            for (int j = 0; j < matrix[0].length; j++) {
                sum += Math.abs(ints[j]);
                if (ints[j] != 0) {
                    mul = mul * ints[j] > 0 ? 1 : -1;
                    min = Math.min(min, Math.abs(ints[j]));
                } else {
                    count++;
                }
            }
        }
        return mul < 0 && count == 0 ? sum - 2L * min : sum;
    }
}
//runtime:8 ms
//memory:47.9 MB
