#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;
void gen(int i) {
  if (i == n * n) {
    for (int j = 0; j < n * n; j++) b[j / n][j % n] = cur[j];
    int sum = 0;
    for (int j = 0; j < n; j++) sum += b[0][j];
    for (int i1 = 0; i1 < n; i1++) {
      int cur = 0;
      for (int j1 = 0; j1 < n; j1++) cur += b[i1][j1];
      if (cur != sum) return;
    }
    for (int j1 = 0; j1 < n; j1++) {
      int cur = 0;
      for (int i1 = 0; i1 < n; i1++) cur += b[i1][j1];
      if (cur != sum) return;
    }
    int cur = 0;
    for (int i1 = 0; i1 < n; i1++) cur += b[i1][i1];
    if (cur != sum) return;
    cur = 0;
    for (int i1 = 0; i1 < n; i1++) cur += b[i1][n - i1 - 1];
    if (cur != sum) return;
    cout << sum << 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;
  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;
  }
  for (int j = 0; j < k; j++)
    if (was[j] < cnt[j]) {
      was[j]++;
      cur[i] = a[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;
  gen(0);
}
