#include <bits/stdc++.h>
using namespace std;
int sqbf[3][3];
void Check(int n, vector<int> order) {
  int tot = 0;
  for (int(i) = 0; (i) < (n * n); ++(i)) tot += order[i];
  int piece = tot / n;
  for (int(i) = 0; (i) < (n); ++(i))
    for (int(j) = 0; (j) < (n); ++(j)) sqbf[i][j] = order[i * n + j];
  for (int(i) = 0; (i) < (n); ++(i)) {
    int sum1 = 0;
    int sum2 = 0;
    for (int(j) = 0; (j) < (n); ++(j)) {
      sum1 += sqbf[i][j];
      sum2 += sqbf[j][i];
    }
    if (sum1 != piece || sum2 != piece) return;
  }
  int sum1 = 0;
  int sum2 = 0;
  for (int(i) = 0; (i) < (n); ++(i)) {
    sum1 += sqbf[i][i];
    sum2 += sqbf[i][n - i - 1];
  }
  if (sum1 != piece || sum2 != piece) return;
  cout << piece << endl;
  for (int(i) = 0; (i) < (n); ++(i)) {
    for (int(j) = 0; (j) < (n); ++(j)) {
      if (j) cout << " ";
      cout << sqbf[i][j];
    }
    cout << endl;
  }
  exit(0);
}
char yes[205000000];
int vals[18];
int jml;
int main() {
  int n;
  cin >> n;
  if (n <= 3) {
    vector<int> z;
    for (int(i) = 0; (i) < (n * n); ++(i)) {
      int a;
      cin >> a;
      z.push_back(a);
    }
    sort(z.begin(), z.end());
    do {
      Check(n, z);
    } while (next_permutation(z.begin(), z.end()));
    exit(0);
  }
  for (int(i) = 0; (i) < (n * n); ++(i)) {
    int z;
    cin >> z;
    yes[z + 100000000]++;
    vals[i] = z;
  }
  sort(vals, vals + n * n);
  jml = unique(vals, vals + n * n) - vals;
}
