#K47102. Magic Square Checker
Magic Square Checker
Magic Square Checker
In this problem, you are given a grid that is supposed to be a 3×3 magic square. A 3×3 magic square is defined as a grid containing all distinct numbers from 1 to 9 such that the sums of all rows, all columns, and both of the main diagonals are equal. Formally, if the grid is represented as:
[
\begin{bmatrix}
a & b & c \
d & e & f \
g & h & i
\end{bmatrix}
]
then it is a magic square if it satisfies:
[
a+b+c = d+e+f = g+h+i = a+d+g = b+e+h = c+f+i = a+e+i = c+e+g
]
If any of these conditions fail, or if the grid is incomplete or contains numbers not in the range (1 \leq n \leq 9), output not magic
. Otherwise, print magic
.
Your solution must read the input from standard input (stdin) and write the result to standard output (stdout).
inputFormat
The input consists of three lines. Each line contains exactly three space-separated integers representing a row of the grid. If the input does not form a 3×3 grid, your program should output not magic
.
outputFormat
Output a single word: magic
if the grid is a valid magic square, or not magic
otherwise.## sample
2 7 6
9 5 1
4 3 8
magic