#include <bits/stdc++.h>
using namespace std;
const int N = 4;
int num[N * N], cnt[N * N];
int rs[N], cs[N];
int m;
const int A1[7] = {1, 1, 1, 2, 2, 2, 3};
const int A2[7] = {1, 2, 3, 1, 2, 3, 1};
int b[16];
int s;
bool fnd(int x) {
  for (int i = 0; i < m; ++i)
    if (num[i] == x) return cnt[i] != 0;
  return false;
}
bool fnder(int x) {
  for (int i = 0; i < m; ++i)
    if (num[i] == x) {
      if (cnt[i] != 0) {
        cnt[i]--;
        return true;
      } else
        return false;
    }
  return false;
}
void rec(int k) {
  if (k == 7) {
    int bb[16];
    memcpy(bb, cnt, sizeof(bb));
    int tmp = s - (b[0] + b[1] + b[2]);
    if (!fnder(tmp)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    tmp = s - (b[3] + b[4] + b[5]);
    if (!fnder(tmp)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    int v1 = -s + 2 * b[0] + b[1] + b[2] + b[3] - b[5] + b[6];
    if (!fnder(v1)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    int v2 = 2 * s - 2 * b[0] - b[1] - b[2] - b[3] - b[4] - b[6];
    if (!fnder(v2)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    int v3 = b[4] + b[5] - b[6];
    if (!fnder(v3)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    int v4 = s - b[0] - b[3] - b[6];
    if (!fnder(v4)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    int v5 = 2 * s - 2 * b[0] - 2 * b[1] - b[2] - b[3] - b[4] + b[5] - b[6];
    if (!fnder(v5)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    int v6 = -s + 2 * b[0] + b[1] + b[3] + b[4] - b[5] + b[6];
    if (!fnder(v6)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    int v7 = -s + b[0] + b[1] + b[2] + b[3] + b[6];
    if (!fnder(v7)) {
      memcpy(cnt, bb, sizeof(bb));
      return;
    }
    cout << s << '\n';
    cout << b[0] << ' ' << b[1] << ' ' << b[2] << ' ' << s - b[0] - b[1] - b[2]
         << '\n';
    cout << b[3] << ' ' << b[4] << ' ' << b[5] << ' ' << s - b[3] - b[4] - b[5]
         << '\n';
    cout << b[6] << ' ' << v1 << ' ' << v2 << ' ' << v3 << '\n';
    cout << v4 << ' ' << v5 << ' ' << v6 << ' ' << v7 << '\n';
    exit(0);
  } else {
    for (int i = 0; i < m; ++i)
      if (cnt[i] != 0) {
        cnt[i]--;
        b[k] = num[i];
        if (!((k == 2 && !fnd(s - (b[0] + b[1] + b[2]))) ||
              (k == 5 && !fnd(s - (b[3] + b[4] + b[5])))))
          rec(k + 1);
        cnt[i]++;
      }
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n * n);
  for (int i = 0; i < n * n; ++i) {
    cin >> a[i];
    s += a[i];
  }
  s /= n;
  int b[N][N];
  if (n <= 3) {
    vector<int> p(n * n);
    for (int i = 0; i < n * n; ++i) p[i] = i;
    do {
      int cur = 0;
      for (int ii = 0; ii < n; ++ii)
        for (int jj = 0; jj < n; ++jj) b[ii][jj] = a[p[ii * n + jj]];
      bool ok = true;
      for (int i = 0; i < n; ++i) {
        cur = 0;
        for (int j = 0; j < n; ++j) cur += b[i][j];
        if (cur != s) {
          ok = false;
          goto cont;
        }
      }
      for (int j = 0; j < n; ++j) {
        cur = 0;
        for (int i = 0; i < n; ++i) cur += b[i][j];
        if (cur != s) {
          ok = false;
          goto cont;
        }
      }
      if (!ok) goto cont;
      cur = 0;
      for (int i = 0; i < n; ++i) cur += b[i][i];
      if (cur != s) ok = false;
      cur = 0;
      for (int i = 0; i < n; ++i) cur += b[n - i - 1][i];
      if (cur != s) ok = false;
      if (ok) {
        cout << s << '\n';
        for (int i = 0; i < n; ++i)
          for (int j = 0; j < n; ++j)
            cout << b[i][j] << (j + 1 != n ? ' ' : '\n');
        return 0;
      }
    cont:;
    } while (next_permutation(p.begin(), p.end()));
  }
  map<int, int> mp;
  for (int i = 0; i < n * n; ++i) mp[a[i]]++;
  m = 0;
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
    num[m] = it->first;
    cnt[m] = it->second;
    ++m;
  }
  rec(0);
  return 0;
}
