#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int n;
int num[20];
int buf[5][5];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * n; ++i) scanf("%d", &num[i]);
  sort(num, num + n * n);
  int sum = accumulate(num, num + n * n, 0) / n;
  do {
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) buf[i][j] = num[i * n + j];
    int failed = 0;
    for (int i = 0; i < n; ++i) {
      int tmp = 0;
      for (int j = 0; j < n; ++j) tmp += buf[i][j];
      if (tmp != sum) failed = 1;
    }
    for (int i = 0; i < n; ++i) {
      int tmp = 0;
      for (int j = 0; j < n; ++j) tmp += buf[j][i];
      if (tmp != sum) failed = 1;
    }
    int tmp = 0;
    for (int i = 0; i < n; ++i) tmp += buf[i][i];
    if (tmp != sum) failed = 1;
    tmp = 0;
    for (int i = 0; i < n; ++i) tmp += buf[i][n - 1 - i];
    if (tmp != sum) failed = 1;
    if (!failed) {
      printf("%d\n", sum);
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
          printf("%d%c", buf[i][j], j == n - 1 ? '\n' : ' ');
      return 0;
    }
  } while (next_permutation(num, num + n * n));
  return 0;
}
