#include <bits/stdc++.h>
using namespace std;
const static int inf = 10000000;
const static int mod = 1000000007;
int main() {
  int n;
  while (cin >> n) {
    vector<int> a(n * n);
    vector<int> ind(n * n);
    int sum = 0;
    for (int i = 0; i < (int)(n * n); i++) {
      cin >> a[i];
      ind[i] = i;
      sum += a[i];
    }
    sum /= n;
    do {
      bool ok = true;
      for (int i = 0; i < (int)(n); i++) {
        int buf = 0;
        for (int j = 0; j < (int)(n); j++) {
          buf += a[ind[i * n + j]];
        }
        if (buf != sum) {
          ok = false;
        }
      }
      for (int i = 0; i < (int)(n); i++) {
        int buf = 0;
        for (int j = 0; j < (int)(n); j++) {
          buf += a[ind[j * n + i]];
        }
        if (buf != sum) {
          ok = false;
        }
      }
      int now = 0;
      int buf = 0;
      for (int i = 0; i < (int)(n); i++) {
        buf += a[ind[now]];
        now += (n + 1);
      }
      if (buf != sum) {
        ok = false;
      }
      now = (n - 1);
      buf = 0;
      for (int i = 0; i < (int)(n); i++) {
        buf += a[ind[now]];
        now += (n - 1);
      }
      if (buf != sum) {
        ok = false;
      }
      if (ok) {
        cout << sum << endl;
        for (int i = 0; i < (int)(n); i++) {
          for (int j = 0; j < (int)(n); j++) {
            cout << a[ind[i * n + j]] << " ";
          }
          cout << endl;
        }
        break;
      }
    } while (next_permutation(ind.begin(), ind.end()));
  }
  return 0;
}
