Time limit
1s
Memory limit
128 MB
Matheos the magician wants to classify square tables of integers by their magical properties. A square has the same number of rows and columns. For each square, define the reference sum S as the sum of the first column.
Classify each square by the following rules.
Not Magick: at least one row or column does not sum to S.Semi-Magick Square: every row and every column sums to S, but at least one of the two diagonals does not.Weakly-Magick Square: every row, every column, and both diagonals sum to S.Strongly-Magick Square: every row, every column, and both diagonals sum to S, and all numbers in the square are distinct.Magically-Magick Square: every row, every column, and both diagonals sum to S; all numbers are distinct; and the numbers are consecutive integers with no gaps.The following 2 x 2 square is a Semi-Magick Square because every row and column sums to 5, but the diagonals do not.
| 2 | 3 |
| 3 | 2 |
The following 3 x 3 square is a Magically-Magick Square because every row, column, and diagonal sums to 15, all numbers are distinct, and the numbers are consecutive from 1 through 9.
| 8 | 1 | 6 |
| 3 | 5 | 7 |
| 4 | 9 | 2 |
Given a sequence of squares, write a program that determines which of the five classifications applies to each square.
The input consists of a sequence of squares. Each square begins with an integer n on its own line, the number of rows and columns. It is guaranteed that 2 <= n <= 8. The next n lines each contain n integers. The input ends with a line containing only 0.
For each square, print one line in the form Square k: result, where k is the square number starting from 1. The result must be exactly one of the following strings.
Magically-Magick SquareStrongly-Magick SquareWeakly-Magick SquareSemi-Magick SquareNot a Magick Square