#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 228;
int T = 1228, t, i, j, n, m, a[N], o[N][N], k[2];
int check() {
  int i, j, k, ot = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) o[i][j] = a[i * n + j];
  for (i = k = 0; i < n; i++, k = 0) {
    for (j = 0; j < n; j++) k += o[i][j];
    ot += abs(k - t);
  }
  for (j = k = 0; j < n; j++, k = 0) {
    for (i = 0; i < n; i++) k += o[i][j];
    ot += abs(k - t);
  }
  k = 0;
  for (i = 0; i < n; i++) k += o[i][i];
  ot += abs(k - t);
  k = 0;
  for (i = 0; i < n; i++) k += o[i][n - i - 1];
  ot += abs(k - t);
  return ot;
}
int main() {
  srand((unsigned)time(NULL));
  cin >> n, m = n * n;
  for (i = 0; i < m; i++) cin >> a[i], t += a[i];
  t /= n;
  random_shuffle(a, a + m);
  k[0] = check();
  while (k[0]) {
    random_shuffle(a, a + m);
    T = 1228, k[0] = check();
    while (T--) {
      i = rand() % m, j = rand() % m;
      while (i == j) j = rand() % m;
      swap(a[i], a[j]), k[1] = check();
      if (k[1] > k[0])
        swap(a[i], a[j]);
      else
        k[0] = k[1];
    }
    k[0] = check();
  }
  cout << t << "\n";
  for (i = 0; i < n; i++, cout << "\n")
    for (j = 0; j < n; j++) cout << o[i][j] << " ";
}
