#include <bits/stdc++.h>
using namespace std;
int n, b[10][10], sum, a[100], q[100], st[100];
bool check, f[100];
void kiemtra() {
  int i, j, tong;
  for (i = 0; i <= n - 1; i++) {
    tong = 0;
    for (j = 0; j <= n - 1; j++) tong += b[i][j];
    if (tong != sum) return;
    tong = 0;
    for (j = 0; j <= n - 1; j++) tong += b[j][i];
    if (tong != sum) return;
  }
  tong = 0;
  for (i = 0; i <= n - 1; i++) tong += b[i][i];
  if (tong != sum) return;
  tong = 0;
  for (i = 0; i <= n - 1; i++) tong += b[i][n - i - 1];
  if (tong != sum) return;
  check = true;
}
void backtrack(int k) {
  int i, j, t;
  for (i = 1; i <= n * n; i++)
    if (f[i]) {
      b[k / n][k % n] = a[i];
      f[i] = false;
      if (k == n * n - 1) {
        kiemtra();
        if (check) {
          for (j = 0; j <= n - 1; j++) {
            for (t = 0; t <= n - 1; t++) cout << b[j][t] << " ";
            cout << endl;
          }
        }
      } else
        backtrack(k + 1);
      if (check) return;
      f[i] = true;
    }
}
int rest(int k) {
  int i;
  for (i = 1; i <= n * n; i++)
    if ((a[i] == k) && (f[i])) {
      f[i] = false;
      return i;
    }
  return 0;
}
void update() {
  b[0][0] = st[1];
  b[0][1] = st[2];
  b[0][3] = st[3];
  b[1][0] = st[4];
  b[1][1] = st[5];
  b[1][2] = st[6];
  b[2][1] = st[7];
  b[2][2] = st[8];
  b[3][0] = sum - st[7] - st[6] - st[3];
  q[7] = rest(b[3][0]);
  b[3][3] = sum - st[1] - st[5] - st[8];
  q[8] = rest(b[3][3]);
  b[0][2] = sum - b[0][0] - b[0][1] - b[0][3];
  q[1] = rest(b[0][2]);
  b[3][1] = sum - b[0][1] - b[1][1] - b[2][1];
  q[2] = rest(b[3][1]);
  b[3][2] = sum - b[3][0] - b[3][1] - b[3][3];
  q[3] = rest(b[3][2]);
  b[2][0] = sum - b[0][0] - b[1][0] - b[3][0];
  q[4] = rest(b[2][0]);
  b[2][3] = sum - b[2][0] - b[2][1] - b[2][2];
  q[5] = rest(b[2][3]);
  b[1][3] = sum - b[0][3] - b[2][3] - b[3][3];
  q[6] = rest(b[1][3]);
  int i, j;
  for (i = 1; i <= 8; i++)
    if (q[i] == 0) {
      for (j = 1; j <= 8; j++) f[q[j]] = true;
      return;
    }
  check = true;
  for (i = 0; i <= 3; i++) {
    for (j = 0; j <= 3; j++) cout << b[i][j] << " ";
    cout << endl;
  }
}
void pick(int k) {
  int i;
  for (i = rand() % 16 + 1; i <= min(i + 11 - 1, 16); i++)
    if (f[i]) {
      f[i] = false;
      st[k] = a[i];
      if (k == 8)
        update();
      else
        pick(k + 1);
      if (check) return;
      f[i] = true;
    }
}
int random(int x) { return (((x + 231645978) % 21123) % (x)); }
int main() {
  int i, x, temp;
  temp = 2;
  cin >> n;
  check = false;
  for (i = 1; i <= n * n; i++) cin >> a[i];
  sum = 0;
  for (i = 1; i <= n * n; i++) sum += a[i];
  sum /= n;
  memset(f, true, sizeof(f));
  cout << sum << endl;
  srand(time(NULL));
  if (n <= 3)
    backtrack(0);
  else {
    while (!check) {
      for (i = 1; i <= n * n; i++) {
        x = rand() % i + 1;
        temp = a[x];
        a[x] = a[i];
        a[i] = temp;
      }
      pick(1);
      if (check) break;
    }
  }
  return 0;
}
