cho.sh
Notes
Loading...

Magic Square Classification

Time limit

1s

Memory limit

128 MB

Problem

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.

23
32

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.

816
357
492

Given a sequence of squares, write a program that determines which of the five classifications applies to each square.

Input

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.

Output

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 Square
  • Strongly-Magick Square
  • Weakly-Magick Square
  • Semi-Magick Square
  • Not a Magick Square