import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Homework {
    public static void main(String[] args) {
        // Scanner class to receive input on array size
        Scanner input = new Scanner(System.in);
        // Random class to generate random values
        Random rand = new Random();

        // receive user input
        System.out.print("Enter the array size: ");
        int n = input.nextInt(); // nextInt() to scan integer

        // initialize matrix
        ArrayList<ArrayList<Integer>> mat = new ArrayList<>();

        // generate random values in the matrix
        for (int i = 0; i < n; i++) {
            // create new row
            ArrayList<Integer> row = new ArrayList<>();

            // generate a value for each row
            for (int j = 0; j < n; j++) {
                // from 0 (inclusive) to 2 (exclusive)
                row.add(rand.nextInt(0, 2));
            }

            // add the row to the matrix
            mat.add(row);
        }

        // print the random array
        System.out.println("The random array is");
        for (ArrayList<Integer> row : mat) { // for each looping through each row
            for (int c : row) { // for each looping through each integer value
                System.out.print(c + " ");
            }
            System.out.println(); // print empty line for next row
        }

        // new ArrayLists to store max row and column indexes
        ArrayList<Integer> maxRow = new ArrayList<>();
        ArrayList<Integer> maxCol = new ArrayList<>();

        // initialize sum and max value
        int sum, max = 0;

        // add up each row
        for (int i = 0; i < n; i++) {
            // clear sum for each row
            sum = 0;

            // for each looping through the row
            for (int c : mat.get(i)) {
                sum += c; // add all values to sum
            }
            if (sum > max) { // if sum is greater than max, update max to sum
                max = sum; // set max to sum
                maxRow.clear(); // clear previous max and
                maxRow.add(i); // add new max
            } else if (sum == max) { // if the new sum is equal to max
                maxRow.add(i); // then add it to max
            }
        }

        // print out the largest row indexes
        System.out.print("The largest row index: ");
        for (int c : maxRow) {
            System.out.print(c + " ");
        }

        System.out.println(); // add a new line for formatting

        // same logic
        max = 0;
        for (int i = 0; i < n; i++) {
            sum = 0;

            for (int j = 0; j < n; j++) {
                sum += mat.get(j).get(i); // add the sum in every column
            }

            // same logic as above
            if (sum > max) {
                max = sum;
                maxCol.clear();
                maxCol.add(i);
            } else if (sum == max) {
                maxCol.add(i);
            }
        }

        // print out largest column indexes
        System.out.print("The largest column index: ");
        for (int c : maxCol) {
            System.out.print(c + " ");
        }
    }
}