#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, a[16];
  cin >> n;
  for (int i = 0; i < n * n; ++i) cin >> a[i];
  sort(a, a + n);
  int d = accumulate(a, a + n * n, 0) / n;
  do {
    int g[4][4];
    for (int i = 0; i < n * n; ++i) g[i / n][i % n] = a[i];
    bool ok = true;
    for (int i = 0; ok && i < n; ++i) {
      int s = 0, t = 0;
      for (int j = 0; j < n; ++j) s += g[i][j], t += g[j][i];
      if (s != d || t != d) ok = false;
    }
    if (ok) {
      int s = 0, t = 0;
      for (int i = 0; i < n; ++i) s += g[i][i], t += g[i][n - 1 - i];
      if (s != d || t != d) ok = false;
    }
    if (ok) {
      cout << d << endl;
      for (int i = 0; i < n; ++i, cout << endl)
        for (int j = 0; j < n; ++j) cout << (j > 0 ? " " : "") << g[i][j];
      break;
    }
  } while (next_permutation(a, a + n * n));
  return 0;
}
