#include <bits/stdc++.h>
using namespace std;
int n;
int a[25];
int check() {
  int last = -1, now;
  for (int i = 0; i < n; ++i) {
    now = 0;
    for (int j = 0; j < n; ++j) now += a[i * n + j];
    if (last == -1 || now == last)
      last = now;
    else
      return -1;
    now = 0;
    for (int j = 0; j < n; ++j) now += a[j * n + i];
    if (now != last) return -1;
  }
  now = 0;
  for (int i = 0; i < n; ++i) now += a[i * n + i];
  if (now != last) return -1;
  now = 0;
  for (int i = 0; i < n; ++i) now += a[i * n + (n - 1 - i)];
  if (now != last) return -1;
  return last;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * n; ++i) scanf("%d", &a[i]);
  sort(a, a + n * n);
  do {
    int x = check();
    if (x != -1) {
      printf("%d\n", x);
      for (int i = 0; i < n; ++i, puts(""))
        for (int j = 0; j < n; ++j) printf("%d ", a[i * n + j]);
      return 0;
    }
  } while (next_permutation(a, a + n * n));
  return 0;
}
