#include <bits/stdc++.h>
using namespace std;
int r[9];
int n;
int a[9];
int b[3][3];
int x[3], y[3], z, k;
set<int> s;
int main() {
  cin >> n;
  for (int i = 0; i < n * n; i++) {
    cin >> a[i];
    r[i] = i;
  }
  do {
    for (int i = 0; i < 9; i++) b[i / n][i % n] = a[r[i]];
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    z = k = 0;
    s.clear();
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        x[i] += b[i][j], y[j] += b[i][j];
        if (i == j) z += b[i][j];
        if (n - 1 - i == j) k += b[i][j];
      }
      s.insert(x[i]);
    }
    s.insert(z);
    s.insert(k);
    for (int i = 0; i < n; i++) {
      s.insert(y[i]);
    }
    if (s.size() == 1) break;
  } while (next_permutation(r, r + n * n));
  cout << *s.begin() << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j) cout << " ";
      cout << b[i][j];
    }
    cout << endl;
  }
}
