#include <bits/stdc++.h>
using namespace std;
int n, a[55], e[5][5], q, s, f[55], A[5], B[5];
void rec(int x, int y) {
  if (y == n) {
    if (A[x] * n != s) return;
    y = 0, x++;
  }
  if (x == n) {
    for (int i = 0; i < n; i++)
      if (A[i] * n != s) return;
    for (int i = 0; i < n; i++)
      if (B[i] * n != s) return;
    q = 0;
    for (int i = 0; i < n; i++) q += e[i][i];
    if (q * n != s) return;
    q = 0;
    for (int i = 0; i < n; i++) q += e[i][n - 1 - i];
    if (q * n != s) return;
    cout << (q) << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) cout << e[i][j] << " ";
      puts("");
    }
    exit(0);
  }
  for (int i = 0; i < n * n; i++)
    if (!f[i]) {
      if (i > 0 && f[i - 1] == 0 && a[i] == a[i - 1]) continue;
      e[x][y] = a[i];
      A[x] += a[i];
      B[y] += a[i];
      f[i] = 1;
      rec(x, y + 1);
      f[i] = 0;
      A[x] -= a[i];
      B[y] -= a[i];
    }
}
int main() {
  cin >> n;
  for (int i = 0; i < n * n; i++) cin >> a[i], s += a[i];
  sort(a, a + n * n);
  rec(0, 0);
  return 0;
}
