#P1406. 方格填数
方格填数
Description
Given an grid and integers, fill these integers into the grid so that the sum of the integers in every row, every column, and each diagonal are all equal. Several examples are shown below.

Input Format
The first line contains an integer .
The second line contains integers .
Output Format
Output an integer on the first line, representing the common sum of every row, every column, and each diagonal.
Then output an matrix, representing a valid filling scheme.
The testdata guarantees that there is a solution. There may be multiple solutions; output the lexicographically smallest one (after concatenating the rows in order).
3
1 2 3 4 5 6 7 8 9
15
2 7 6
9 5 1
4 3 8
Hint
Constraints and Conventions
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号