• + 0 comments

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        // 6x6 2D Array input using List of List
        List<List<Integer>> arr = new ArrayList<>();
    
        for (int i = 0; i < 6; i++) {
            String[] arrRowTempItems = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
            List<Integer> arrRowItems = new ArrayList<>();
    
            for (int j = 0; j < 6; j++) {
                int arrItem = Integer.parseInt(arrRowTempItems[j]);
                arrRowItems.add(arrItem);
            }
    
            arr.add(arrRowItems);
        }
    
        bufferedReader.close();
    
        // Initialize maxSum to minimum possible integer value
        int maxSum = Integer.MIN_VALUE;
    
        // Loop through all possible hourglass starting positions
        for (int i = 0; i < 4; i++) {  // rows
            for (int j = 0; j < 4; j++) {  // columns
    
                // Calculate sum of current hourglass
                int currentSum = arr.get(i).get(j) + arr.get(i).get(j+1) + arr.get(i).get(j+2)
                               + arr.get(i+1).get(j+1)
                               + arr.get(i+2).get(j) + arr.get(i+2).get(j+1) + arr.get(i+2).get(j+2);
    
                // Update maxSum if needed
                if (currentSum > maxSum) {
                    maxSum = currentSum;
                }
            }
        }
    
        // Output the result
        System.out.println(maxSum);
    }
    

    }