← Home
write a go solution for Description:
You are given a prime number n, and an array of n integers b_1,b_2,ldots,b_n, where 0<=b_i<n for each 1<=i<=n.

You have to find a matrix a of size nxn such that all of the following requirements hold:

- 0<=a_i,j<n for all 1<=i,j<=n.
- a_r_1,c_1+a_r_2,c_2notequiva_r_1,c_2+a_r_2,c_1pmodn for all positive integers r_1, r_2, c_1, and c_2 such that 1<=r_1<r_2<=n and 1<=c_1<c_2<=n.
- a_i,i=b_i for all 1<=i<=n.

Here xnotequivypmodm denotes that x and y give different remainders when divided by m.

If there are multiple solutions, output any. It can be shown that such a matrix always exists under the given constraints.

Input Format:
The first line contains a single positive integer n (2<=n<350).

The second line contains n integers b_1,b_2,ldots,b_n (0<=b_i<n) — the required values on the main diagonal of the matrix.

It is guaranteed that n is prime.

Output Format:
Print n lines. On the i-th line, print n integers a_i,1,a_i,2,ldots,a_i,n, each separated with a space.

If there are multiple solutions, output any.

Note:
In the first example, the answer is valid because all entries are non-negative integers less than n=2, and a_1,1+a_2,2notequiva_1,2+a_2,1pmod2 (because a_1,1+a_2,2=0+0equiv0pmod2 and a_1,2+a_2,1=1+0equiv1pmod2). Moreover, the values on the main diagonals are equal to 0,0 as required.

In the second example, the answer is correct because all entries are non-negative integers less than n=3, and the second condition is satisfied for all quadruplets (r_1,r_2,c_1,c_2). For example:

- When r_1=1, r_2=2, c_1=1 and c_2=2, a_1,1+a_2,2notequiva_1,2+a_2,1pmod3 because a_1,1+a_2,2=1+1equiv2pmod3 and a_1,2+a_2,1=2+1equiv0pmod3.
- When r_1=2, r_2=3, c_1=1, and c_2=3, a_2,1+a_3,3notequiva_2,3+a_3,1pmod3 because a_2,1+a_3,3=1+1equiv2pmod3 and a_2,3+a_3,1=0+1equiv1pmod3.. Output only the code with no comments, explanation, or additional text.