C. Palindromic Matrix
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Let’s call some square matrix with integer values in its cells palindromic if it doesn’t change after the order of rows is reversed and it doesn’t change after the order of columns is reversed.
For example, the following matrices are palindromic:
The following matrices are not palindromic because they change after the order of rows is reversed:
The following matrices are not palindromic because they change after the order of columns is reversed:
You are given n2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print “NO”.
Input
The first line contains one integer n (1≤n≤20).
The second line contains n2 integers a1,a2,…,an2 (1≤ai≤1000) — the numbers to put into a matrix of n rows and n columns.
Output
If it is possible to put all of the n2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print “YES”. Then pr