import java.util.*;
import java.io.*;

/**
 * MagicSquare.java
 *
 * Ask a user for the test case file name, and read in each array
 * to see if it is a magic square.
 *
 * @author 1:              discussion section time:
 *
 * @author 2:              discussion section time:
 *
 * @date:
 *
 *
 */


public class MagicSquare
{

    /**
     * isMagic
     *
     * Compute the sums of each column, row and diagonal to see
     * if the given 2-dimensional array is a magic square. If it
     * is, then return true, and if not, then return false;
     *
     * @param array a two dimensional array to test
     *
     * @return boolean true if a magic square
     *                 false if not
     */

    public boolean isMagic ( int[][] array ) {
        int sum=0;
        int lastSum=0;
        boolean magic=true;

        // if the array is not a square then set magic to be false
        for (int i=0; i< array.length; i++) {
            if (array.length!=array[i].length) {
                magic = false;
            }
        }

        // compute the sums of rows and
        // set magic to be false if any of the sums are different
        System.out.print("Sums of rows: ");
        for (int i=0; i < array[0].length; i++) {
            sum=0;
            for (int j=0; j < array.length; j++) {
                sum+=array[i][j];
            }
            System.out.print(sum+" ");
            if (i==0) {
                lastSum=sum;
            } else if (lastSum!=sum) {
                magic = false;
            }
        }
        System.out.println();

		// Here you need to fill in the code to check for the
		// sums of columns and the sums of the diagonals.

        return magic;

    }

    public static void main(String[] args) throws Exception {

        // ask user for the test case file name
        System.out.print("Enter the test case file name: ");
        Scanner stdin = new Scanner(System.in);
        Scanner fs = new Scanner(new File(stdin.nextLine()));

        while (fs.hasNextInt()) {
            // read the array size from the file
            int arraySize = fs.nextInt();
            int[][] xArray = new int[arraySize][arraySize];

            // read the elements of the array from the file
            for (int i=0; i<arraySize; i++) {
                for (int j=0; j<arraySize; j++) {
                    xArray[i][j] = fs.nextInt();
                }
            }

            // print the elements of the array
            for (int i=0; i<arraySize; i++) {
                for (int j=0; j<arraySize; j++) {
                    System.out.print(xArray[i][j]+" ");
                }
                System.out.println();
            }
            System.out.println();

            // test if it is a magic square
            MagicSquare ms = new MagicSquare();
            if (ms.isMagic(xArray)) {
                System.out.println("The array is a magic square\n");
            } else {
                System.out.println("The array is not a magic square\n");
            }
        }
    }

}
