#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MAXn = 100;
long long a[MAXn];
long long t[MAXn][MAXn];
int n;
bool check() {
  long long s = 0;
  for (int i = 0, __e = n; i < __e; i++) s += t[0][i];
  for (int i = 0, __e = n; i < __e; i++) {
    long long x = 0;
    for (int j = 0, __e = n; j < __e; j++) x += t[i][j];
    if (x != s) return false;
  }
  for (int i = 0, __e = n; i < __e; i++) {
    long long x = 0;
    for (int j = 0, __e = n; j < __e; j++) x += t[j][i];
    if (x != s) return false;
  }
  long long x = 0;
  for (int i = 0, __e = n; i < __e; i++) x += t[i][i];
  if (x != s) return false;
  x = 0;
  for (int i = 0, __e = n; i < __e; i++) x += t[i][n - 1 - i];
  if (x != s) return false;
  return true;
}
long long EX;
map<long long, int> mp;
long long csum[10], rsum[10];
void bt(int lvl) {
  int r = lvl / n, c = lvl % n;
  if (r == n - 1) {
    if (check()) {
      long long sum = 0;
      for (int i = 0, __e = n; i < __e; i++) sum += t[0][i];
      cout << sum << endl;
      for (int i = 0, __e = n; i < __e; i++) {
        for (int j = 0, __e = n; j < __e; j++) cout << t[i][j] << " ";
        cout << endl;
      }
      exit(0);
    }
    return;
  }
  if (c != n - 1) {
    for (__typeof(mp.begin()) _ind = (mp).begin(); _ind != (mp).end(); _ind++)
      for (bool _flag = true; _flag; _flag = false)
        for (__typeof(*(mp).begin()) &el = *_ind; _flag; _flag = false) {
          long long x = el.first;
          bool ok = true;
          if (el.second == 0) continue;
          t[r][c] = x;
          csum[c] += x;
          rsum[r] += x;
          if (r == n - 2) {
            t[n - 1][c] = EX - csum[c];
            if (mp.count(t[n - 1][c]) == 0 || mp[t[n - 1][c]] == 0)
              ok = false;
            else
              mp[t[n - 1][c]]--;
          }
          if (ok && mp[x] > 0) {
            mp[x]--;
            bt(lvl + 1);
            mp[x]++;
          }
          csum[c] -= x;
          rsum[r] -= x;
          if (r == n - 2 && ok) mp[t[n - 1][c]]++;
        }
  } else {
    t[r][c] = EX - rsum[r];
    if (mp.count(t[r][c]) == 0 || mp[t[r][c]] == 0) return;
    csum[c] += t[r][c];
    rsum[r] += t[r][c];
    bool ok = true;
    if (r == n - 2) {
      t[n - 1][c] = EX - csum[c];
      if (mp.count(t[n - 1][c]) == 0 || mp[t[n - 1][c]] == 0)
        ok = false;
      else
        mp[t[n - 1][c]]--;
    }
    if (ok && mp[t[r][c]] > 0) {
      mp[t[r][c]]--;
      bt(lvl + 1);
      mp[t[r][c]]++;
    }
    csum[c] -= t[r][c];
    rsum[r] -= t[r][c];
    if (r == n - 2 && ok) mp[t[n - 1][c]]++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int m = n * n;
  for (int i = 0, __e = m; i < __e; i++) cin >> a[i], mp[a[i]]++;
  if (n == 1) {
    cout << a[0] << endl;
    cout << a[0] << endl;
    return 0;
  }
  long long p = 0, q = 0;
  for (int i = 0, __e = m; i < __e; i++) {
    q += a[i];
    p += q / n;
    q %= n;
  }
  EX = p;
  bt(0);
  return 0;
}
