public static void main(String[] args) throws IOException {
        int[][] grid = getGrid();
        int maxProduct = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (j + 4 < N)
                    maxProduct = Math.max(maxProduct, grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3]);
                if (i + 4 < N)
                    maxProduct = Math.max(maxProduct, grid[i][j] * grid[i + 1][j] * grid[i + 2][j] * grid[i + 3][j]);
                if (i + 4 < N && j + 4 < N)
                    maxProduct = Math.max(maxProduct, grid[i][j] * grid[i + 1][j + 1] * grid[i + 2][j + 2] * grid[i + 3][j + 3]);
                if (i + 4 < N && j - 4 >= 0)
                    maxProduct = Math.max(maxProduct, grid[i][j] * grid[i + 1][j - 1] * grid[i + 2][j - 2] * grid[i + 3][j - 3]);
            }
        }
        System.out.println(maxProduct);
    }