#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
int n, N, A[MAXN], s, T[MAXN][MAXN], F[MAXN], C[MAXN], D[2], FN[MAXN], CN[MAXN],
    DN[2];
bool used[MAXN], solved;
int WF[MAXN], WC[MAXN];
bool tenta(int i, int x, int y) {
  if (used[i]) return false;
  int fn = FN[x] + 1;
  int cn = CN[y] + 1;
  int d = (x == y) ? DN[0] + 1 : ((n - 1 - x == y) ? DN[1] + 1 : -1);
  if (fn == n) {
    if (F[x] + A[i] != s) return false;
  }
  if (cn == n) {
    if (C[y] + A[i] != s) return false;
  }
  if (d == n) {
    if (x == y && D[0] + A[i] != s) return false;
    if (n - 1 - x == y && D[1] + A[i] != s) return false;
  }
  if (fn == n - 1) {
    bool ok = false;
    int t = s - F[x] - A[i];
    for (int z = (0); z < (int)(N); z++) {
      if (z == i) continue;
      if (used[z]) continue;
      if (A[z] == t) {
        ok = true;
        break;
      }
    }
    if (!ok) return false;
  }
  if (cn == n - 1) {
    bool ok = false;
    int t = s - C[y] - A[i];
    for (int z = (0); z < (int)(N); z++) {
      if (z == i) continue;
      if (used[z]) continue;
      if (A[z] == t) {
        ok = true;
        break;
      }
    }
    if (!ok) return false;
  }
  return true;
}
void bf(int f, int c, int pos) {
  if (f == n) {
    printf("%d\n", s);
    for (int i = (0); i < (int)(n); i++) {
      for (int j = (0); j < (int)(n); j++) {
        if (j) printf(" ");
        printf("%d", T[i][j]);
      }
      puts("");
    }
    solved = true;
    return;
  }
  int nf = c + 1 == n ? f + 1 : f;
  int nc = c + 1 == n ? 0 : c + 1;
  if (n == 4) {
    nf = WF[pos + 1];
    nc = WC[pos + 1];
  }
  for (int i = (0); i < (int)(N); i++) {
    if (tenta(i, f, c)) {
      used[i] = true;
      F[f] += A[i];
      FN[f]++;
      C[c] += A[i];
      CN[c]++;
      if (f == c) {
        D[0] += A[i];
        DN[0]++;
      }
      if (n - 1 - f == c) {
        D[1] += A[i];
        DN[1]++;
      }
      T[f][c] = A[i];
      bf(nf, nc, pos + 1);
      if (solved) return;
      F[f] -= A[i];
      FN[f]--;
      C[c] -= A[i];
      CN[c]--;
      if (f == c) {
        D[0] -= A[i];
        DN[0]--;
      }
      if (n - 1 - f == c) {
        D[1] -= A[i];
        DN[1]--;
      }
      used[i] = false;
    }
  }
}
int main() {
  WF[0] = 0;
  WF[4] = 1;
  WF[8] = 3;
  WF[12] = 2;
  WF[1] = 0;
  WF[5] = 2;
  WF[9] = 3;
  WF[13] = 1;
  WF[2] = 0;
  WF[6] = 3;
  WF[10] = 2;
  WF[14] = 1;
  WF[3] = 0;
  WF[7] = 3;
  WF[11] = 1;
  WF[15] = 2;
  WF[16] = 4;
  WC[0] = 0;
  WC[4] = 3;
  WC[8] = 1;
  WC[12] = 2;
  WC[1] = 1;
  WC[5] = 3;
  WC[9] = 0;
  WC[13] = 1;
  WC[2] = 2;
  WC[6] = 3;
  WC[10] = 1;
  WC[14] = 0;
  WC[3] = 3;
  WC[7] = 2;
  WC[11] = 2;
  WC[15] = 0;
  WC[16] = 4;
  while (scanf("%d", &n) >= 1) {
    memset(F, 0, sizeof(F));
    memset(C, 0, sizeof(C));
    memset(D, 0, sizeof(D));
    memset(FN, 0, sizeof(FN));
    memset(CN, 0, sizeof(CN));
    memset(DN, 0, sizeof(DN));
    solved = false;
    N = n * n;
    s = 0;
    for (int i = (0); i < (int)(N); i++) {
      scanf("%d", &A[i]);
      s += A[i];
    }
    srand(time(NULL));
    random_shuffle(A, A + N);
    s /= n;
    memset(used, false, sizeof(used));
    bf(0, 0, 0);
    if (!solved) {
      printf("geeez\n");
    }
  }
  return 0;
}
