#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int N = 110000;
int n, a[100], cnt[100], ar[100], k;
int cur[100], b[10][10], was[100], endprog, need;
int por[] = {0, 5, 10, 15, 3, 6, 9, 12, 4, 7, 8, 11, 1, 2, 13, 14};
void sgen(int i) {
  if (i == 4) {
    if (cur[0] + cur[5] + cur[10] + cur[15] != need) return;
  } else if (i == 8) {
    if (cur[3] + cur[6] + cur[9] + cur[12] != need) return;
  } else if (i == 10) {
    if (cur[4] + cur[5] + cur[6] + cur[7] != need) return;
  } else if (i == 12) {
    if (cur[8] + cur[9] + cur[10] + cur[11] != need) return;
    if (cur[0] + cur[4] + cur[8] + cur[12] != need) return;
    if (cur[3] + cur[7] + cur[11] + cur[15] != need) return;
  } else if (i == 14) {
    if (cur[0] + cur[1] + cur[2] + cur[3] != need) return;
  } else if (i == 16) {
    if (cur[12] + cur[13] + cur[14] + cur[15] != need) return;
    if (cur[1] + cur[5] + cur[9] + cur[13] != need) return;
    if (cur[2] + cur[6] + cur[10] + cur[14] != need) return;
  }
  if (i == n * n) {
    for (int j = 0; j < n * n; j++) b[j / n][j % n] = cur[j];
    cout << need << endl;
    for (int i1 = 0; i1 < n; i1++) {
      for (int j1 = 0; j1 < n; j1++) {
        cout << b[i1][j1] << " ";
      }
      puts("");
    }
    endprog = 1;
    return;
  }
  if (endprog) return;
  for (int j = 0; j < k; j++)
    if (was[j] < cnt[j]) {
      cur[por[i]] = a[j];
      was[j]++;
      sgen(i + 1);
      if (endprog) return;
      was[j]--;
    }
}
void gen(int i) {
  if (i == n) {
    int sum = 0;
    for (int j = 0; j < n; j++) sum += cur[j];
    if (sum != need) return;
  }
  if (i == 2 * n) {
    int sum = 0;
    for (int j = n; j < 2 * n; j++) sum += cur[j];
    if (sum != need) return;
  }
  if (i == 3 * n) {
    int sum = 0;
    for (int j = 2 * n; j < 3 * n; j++) sum += cur[j];
    if (sum != need) return;
  }
  if (n == 4) {
    if (i == 13) {
      int sum = 0;
      for (int j = 0; j < 4; j++) sum += cur[3 * (j + 1)];
      if (sum != need) return;
      sum = 0;
      for (int j = 0; j < 16; j += 4) sum += cur[j];
      if (sum != need) return;
    }
    if (i == 15) {
      int sum = 0;
      for (int j = 2; j < 16; j += 4) sum += cur[j];
      if (sum != need) return;
    }
  }
  if (i == n * n) {
    for (int j = 0; j < n * n; j++) b[j / n][j % n] = cur[j];
    int cur = 0;
    for (int i1 = 0; i1 < n; i1++) cur += b[i1][i1];
    if (n < 4) {
      for (int i1 = 0; i1 < n; i1++) {
        int cur = 0;
        for (int j1 = 0; j1 < n; j1++) cur += b[i1][j1];
        if (cur != need) return;
      }
      for (int j1 = 0; j1 < n; j1++) {
        int cur = 0;
        for (int i1 = 0; i1 < n; i1++) cur += b[i1][j1];
        if (cur != need) return;
      }
      int cur = 0;
      for (int i1 = 0; i1 < n; i1++) cur += b[i1][i1];
      if (cur != need) return;
      cur = 0;
      for (int i1 = 0; i1 < n; i1++) cur += b[i1][n - i1 - 1];
      if (cur != need) return;
    }
    if (cur != need) return;
    cout << need << endl;
    for (int i1 = 0; i1 < n; i1++) {
      for (int j1 = 0; j1 < n; j1++) {
        cout << b[i1][j1] << " ";
      }
      puts("");
    }
    endprog = 1;
    return;
  }
  if (endprog) return;
  for (int j = 0; j < k; j++)
    if (was[j] < cnt[j]) {
      if (i == 13) {
        cur[15] = a[j];
        if (cur[0] + cur[5] + cur[10] + cur[15] != need) continue;
        int sum = 0;
        for (int j = 3; j < 16; j += 4) sum += cur[j];
        if (sum != need) continue;
      } else if (i == 15) {
        cur[13] = a[j];
        int sum = 0;
        for (int j = 1; j < 16; j += 4) sum += cur[j];
        if (sum != need) continue;
      } else
        cur[i] = a[j];
      was[j]++;
      gen(i + 1);
      if (endprog) return;
      was[j]--;
    }
}
int main() {
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n * n; i++) {
    cin >> ar[i];
    sum += ar[i];
    int was = 0;
    for (int j = 0; j < k; j++)
      if (a[j] == ar[i]) {
        cnt[j]++;
        was = 1;
        break;
      }
    if (!was) {
      a[k++] = ar[i];
      cnt[k - 1] = 1;
    }
  }
  need = sum / n;
  if (n != 4)
    gen(0);
  else
    sgen(0);
}
