#include <bits/stdc++.h>
using namespace std;
long long sum;
int n;
int in[20], m[20][20];
bool ok(long long a, long long b, long long c) { return a + b + c == sum; }
bool ok3() {
  for (int i = 0; i < 3; ++i) {
    if (!ok(in[i * 3], in[i * 3 + 1], in[i * 3 + 2])) return false;
    if (!ok(in[i], in[i + 3], in[i + 6])) return false;
  }
  return (ok(in[0], in[4], in[8]) && ok(in[2], in[4], in[6]));
}
int main() {
  cin.tie(0), cout.tie(0);
  cout << boolalpha << setprecision(6) << fixed;
  clog.copyfmt(cout);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> m[i][j];
      sum += m[i][j];
      in[i * n + j] = m[i][j];
    }
  }
  sum /= n;
  cout << sum << endl;
  if (n == 1)
    cout << sum << endl;
  else if (n == 2) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j) cout << " ";
        cout << m[i][j];
      }
      cout << endl;
    }
  } else if (n == 3) {
    int sq = n * n;
    sort(in, in + sq);
    do {
      if (ok3()) break;
    } while (next_permutation(in, in + sq));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j) cout << " ";
        cout << in[i * n + j];
      }
      cout << endl;
    }
  }
  return 0;
}
