#include <bits/stdc++.h>
using namespace std;
int n, m, Magic, md, pd, L;
int a[99], b[99], cnt[99], row[99], col[99];
int t[99][99];
int q[99];
void giveans() {
  printf("%d\n", Magic);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) printf("%d%c", t[i][j], " \n"[j + 1 == n]);
  exit(0);
}
inline void swap(int &a, int &b) {
  int t = a;
  a = b;
  b = t;
}
void dfs(int x, int y) {
  if (x == n) {
    if (row[n - 1] == Magic && md == Magic && pd == Magic) giveans();
  } else if (x == n - 1) {
    int tmp = lower_bound(b, b + m, Magic - col[y]) - b;
    if (b[tmp] != Magic - col[y]) return;
    if (!cnt[tmp]) return;
    cnt[tmp]--;
    t[x][y] = b[tmp];
    if (y == n - 1) md += b[tmp];
    if (!y) pd += b[tmp];
    row[x] += b[tmp];
    if (y == n - 1)
      dfs(x + 1, 0);
    else
      dfs(x, y + 1);
    if (!y) pd -= b[tmp];
    if (y == n - 1) md -= b[tmp];
    row[x] -= b[tmp];
    cnt[tmp]++;
  } else if (y == n - 1) {
    int tmp = lower_bound(b, b + m, Magic - row[x]) - b;
    if (b[tmp] != Magic - row[x]) return;
    if (!cnt[tmp]) return;
    cnt[tmp]--;
    t[x][y] = b[tmp];
    if (!x) pd += b[tmp];
    col[y] += b[tmp];
    dfs(x + 1, 0);
    col[y] -= b[tmp];
    if (!x) pd -= b[tmp];
    cnt[tmp]++;
  } else {
    for (int i = 0, j, k; i < L; i++) {
      k = q[i];
      if (!cnt[k]) {
        continue;
      }
      assert(cnt[k] > 0);
      cnt[k]--;
      t[x][y] = b[k];
      row[x] += b[k];
      col[y] += b[k];
      if (x == y) md += b[k];
      if (x + y == n - 1) pd += b[k];
      int prev = q[L - 1];
      if (!cnt[k]) swap(q[i], q[--L]);
      if (!cnt[k]) {
        assert(k == q[L]);
      }
      dfs(x, y + 1);
      if (!cnt[k]) {
        assert(k == q[L]);
        assert(q[i] == prev);
      }
      if (x + y == n - 1) pd -= b[k];
      if (x == y) md -= b[k];
      col[y] -= b[k];
      row[x] -= b[k];
      if (!cnt[k]) swap(q[i], q[L++]);
      cnt[k]++;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * n; i++)
    scanf("%d", a + i), Magic += a[i], b[i] = a[i];
  if (n == 1) {
    printf("%d\n%d\n", a[0], a[0]);
    return 0;
  }
  sort(b, b + n * n);
  m = unique(b, b + n * n) - b;
  b[m] = 1000000000;
  for (int i = 0; i < n * n; i++) cnt[lower_bound(b, b + m, a[i]) - b]++;
  for (int i = 0; i < m; i++) q[i] = i;
  L = m;
  Magic /= n;
  dfs(0, 0);
  return 0;
}
