#K34067. Magic Square Checker
Magic Square Checker
Magic Square Checker
Given an n × n matrix containing distinct positive integers from 1 to n², determine whether the matrix is a magic square.
A magic square is one where the sum of numbers in every row, every column, and both main diagonals is equal to a common magic constant. The magic constant is given by \( m = \frac{n(n^2+1)}{2} \).
Your task is to verify whether the given matrix meets these criteria.
inputFormat
The first line of input contains a single integer n (the size of the matrix). Each of the next n lines contains n space-separated integers representing a row of the matrix.
outputFormat
Output a single line: "YES" if the matrix is a magic square, otherwise "NO".
## sample3
2 7 6
9 5 1
4 3 8
YES