#C7894. Magic Square Verification
Magic Square Verification
Magic Square Verification
This problem requires you to determine whether a given 3x3 grid forms a magic square. A magic square is defined as a 3x3 grid of integers such that the sum of the numbers in each row, each column, and the two main diagonals are all equal. In mathematical terms, if the constant sum is \(S\), then:
- \(a_{1,1} + a_{1,2} + a_{1,3} = S\)
- \(a_{2,1} + a_{2,2} + a_{2,3} = S\)
- \(a_{3,1} + a_{3,2} + a_{3,3} = S\)
- \(a_{1,1} + a_{2,1} + a_{3,1} = S\)
- \(a_{1,2} + a_{2,2} + a_{3,2} = S\)
- \(a_{1,3} + a_{2,3} + a_{3,3} = S\)
- \(a_{1,1} + a_{2,2} + a_{3,3} = S\)
- \(a_{1,3} + a_{2,2} + a_{3,1} = S\)
Your task is to determine, given a space-separated string of integers, if it represents a valid magic square. If the input does not contain exactly 9 integers, then it should be considered as Not a Magic Square.
inputFormat
The input is provided in a single line through stdin
. It contains space-separated integers representing the 3x3 grid in row-major order. There must be exactly 9 integers; otherwise, the square is not valid.
outputFormat
The output, printed to stdout
, is a single line string. It should be "Magic Square" if the grid is a magic square, or "Not a Magic Square" otherwise.
8 1 6 3 5 7 4 9 2
Magic Square