#include <bits/stdc++.h>
using namespace std;
ifstream in("in.txt");
ofstream out("out.txt");
int more = 100000000;
int ha[100000], h, n, m;
int __TRY(int L, int R, int v) {
  int t = (L + R) / 2;
  if (L == R) return ha[(v + L * m) % h] == -1 ? L : more;
  if (ha[(v + t * m) % h] == -1)
    return min(t, __TRY(L, m, v));
  else
    return min(__TRY(L, m, v), __TRY(m + 1, R, v));
}
int main() {
  cin >> n;
  vector<int> A(n * n);
  vector<int> B(n * 2 + 2);
  if (n == 1) {
    cin >> A[0];
    cout << A[0] << endl << A[0];
  }
  for (int i = 0; i < n * n; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  if (n == 3) {
    do {
      B[0] = A[0] + A[1] + A[2];
      B[1] = A[3] + A[4] + A[5];
      B[2] = A[6] + A[7] + A[8];
      B[3] = A[0] + A[4] + A[8];
      B[4] = A[2] + A[4] + A[6];
      B[5] = A[0] + A[3] + A[6];
      B[6] = A[1] + A[4] + A[7];
      B[7] = A[2] + A[5] + A[8];
      if (B[0] == B[1] && B[1] == B[2] && B[2] == B[3] && B[3] == B[4] &&
          B[4] == B[5] && B[5] == B[6] && B[6] == B[7]) {
        cout << B[0] << endl;
        cout << A[0] << ' ' << A[1] << ' ' << A[2] << endl
             << A[3] << ' ' << A[4] << ' ' << A[5] << endl
             << A[6] << ' ' << A[7] << ' ' << A[8];
        return 0;
      }
    } while (next_permutation(A.begin(), A.end()));
  } else {
    do {
      B[0] = A[0] + A[1];
      B[1] = A[2] + A[3];
      B[2] = A[0] + A[2];
      B[3] = A[1] + A[3];
      B[4] = A[0] + A[3];
      B[5] = A[1] + A[2];
      if (B[0] == B[1] && B[1] == B[2] && B[2] == B[3] && B[3] == B[4] &&
          B[4] == B[5]) {
        cout << B[0] << endl;
        cout << A[0] << ' ' << A[1] << endl << A[2] << ' ' << A[3];
        return 0;
      }
    } while (next_permutation(A.begin(), A.end()));
  }
  return 0;
}
