#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2, typename T3>   T2 x_pow_y(T1 x, T3 y, T2 mod) {     T2 ans = 1;     long long a = x % mod;     while (y) {       if (y & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       y >>= 1;     }     return ans;   }   template <typename T1, typename T2>   T2 inv_mod(T1 x, T2 mod) {     return x_pow_y(x, mod - 2, mod);   }   template <typename T>   vector<T> find_factors(T &n) {     vector<T> factors;     int i;     for (i = 1; i * i < n; i++) {       if (n % i == 0) {         factors.push_back(i);         factors.push_back(n / i);       }     }     if (i * i == n) factors.push_back(i);     return factors;   }   void sieve(vector<int> &prime, size_t max) {     vector<int> ar(max + 1, 1);     ar[0] = ar[1] = 0;     for (int i = 2; i * i <= max; i++) {       if (!ar[i]) continue;       for (int j = i * i; j <= max; j++) ar[j] = 0;     }     for (int i = 2; i <= max; i++) {       if (ar[i]) prime.push_back(i);     }   }   template <typename T1, typename T2>   void make_pascal_triangle_mod_p(vector<vector<T1>> &binomial_coefficient,                                   size_t size, T2 &mod) {     for (int i = 0; i <= size; i++) {       vector<T1> temp(i + 1, 1);       for (int j = 1; j <= i / 2; j++) {         temp[i - j] = temp[j] = (binomial_coefficient[i - 1][j] +                                  binomial_coefficient[i - 1][j - 1]) %                                 mod;       }       binomial_coefficient.push_back(temp);     }   }   template <typename T1, typename T2>   void find_factorial_mod_p(vector<T1> &fact, size_t size, T2 mod) {     fact.resize(size + 1, 1);     for (size_t i = 2; i <= size; i++) {       fact[i] = (i * fact[i - 1]) % mod;     }   }   template <typename T1, typename T2>   T2 nCr_mod_p(vector<T1> &fact, size_t n, size_t r, T2 &mod) {     if (fact.empty()) find_factorial(fact, n, mod);     size_t f_n = fact[n];     size_t f_r = inv_mod(fact[r], mod);     size_t f_nr = inv_mod(fact[n - r], mod);     return (f_nr * ((f_n * f_r) % mod)) % mod;   }   size_t nCr(size_t n, size_t r) {     if (n - r < r) r = n - r;     size_t ans = 1;     for (int i = 0; i < n; i++) {       ans *= (n - i);       ans /= (i + 1);     }     return ans;   }   vector<vector<int>> out_;   bool fill_requirements(int s, int n) {     int r_sum[n], c_sum[n];     memset(r_sum, 0, n * sizeof(int));     memset(c_sum, 0, n * sizeof(int));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         r_sum[i] += out_[i][j];         c_sum[j] += out_[i][j];       }     }     bool flag = true;     for (int i = 0; i < n; i++) {       if (r_sum[i] != s) {         flag = false;         break;       }       if (c_sum[i] != s) {         flag = false;         break;       }     }     int diag_sum = 0;     for (int i = 0; i < n; i++) {       diag_sum += out_[i][i];     }     if (diag_sum != s) flag = false;     int i = n - 1, j = 0;     diag_sum = 0;     while (j != n) {       diag_sum += out_[i][j];       i--;       j++;     }     if (diag_sum != s) flag = false;     return flag;   }   bool flag = false;   void fill_array(int s, vector<int> &ar, int n, int i, int j, vector<int> &vis) {     if (i == n - 1 && j == n) {       flag = fill_requirements(s, n);       return;     }     if (j == n) {       j = 0;       i++;     }     for (int indx = 0; indx < n * n; indx++) {       if (vis[indx]) continue;       vis[indx] = 1;       out_[i][j] = ar[indx];       fill_array(s, ar, n, i, j + 1, vis);       if (flag) {         return;       } else {         vis[indx] = 0;       }     }   }   void solve() {     int n;     cin >> n;     vector<int> ar(n * n);     for (int i = 0; i < n * n; i++) cin >> ar[i];     int sum = 0;     for (int i = 0; i < n * n; i++) sum += ar[i];     out_ = vector<vector<int>>(n, vector<int>(n));     int s = sum / n;     vector<int> vis(n * n);     fill_array(s, ar, n, 0, 0, vis);     cout << s <<   n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << out_[i][j] <<    ;       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }