#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
template <class T>
T SQR(const T &a) {
  return a * a;
}
void run() {
  int A[4][4];
  int n;
  cin >> n;
  int B[16];
  for (int i = (0), ei = (n * n); i < ei; i++) scanf("%d", B + i);
  int nsq = n * n;
  sort(B, B + nsq);
  int S[4], G[4];
  do {
    memset(S, 0, 16);
    for (int i = (0), ei = (n); i < ei; i++)
      for (int j = (0), ej = (n); j < ej; j++) S[i] += B[i * n + j];
    bool ok = 1;
    for (int i = (1), ei = (n); i < ei; i++)
      if (S[i] != S[0]) ok = 0;
    if (!ok) continue;
    memset(G, 0, 16);
    for (int j = (0), ej = (n); j < ej; j++)
      for (int i = (0), ei = (n); i < ei; i++) G[j] += B[i * n + j];
    if (S[0] != G[0]) continue;
    for (int i = (1), ei = (n); i < ei; i++)
      if (G[i] != G[0]) ok = 0;
    int d = 0;
    for (int i = (0), ei = (n); i < ei; i++) d += B[i * n + i];
    if (d != S[0]) continue;
    d = 0;
    for (int i = (0), ei = (n); i < ei; i++) d += B[i * n + n - i - 1];
    if (d != S[0]) continue;
    if (ok) {
      printf("%d\n", S[0]);
      for (int i = (0), ei = (n); i < ei; i++)
        for (int j = (0), ej = (n); j < ej; j++) {
          printf("%d", B[i * n + j]);
          if (j != n - 1)
            putchar(' ');
          else
            putchar('\n');
        }
      return;
    }
  } while (next_permutation(B, B + nsq));
}
int main() {
  time_t beg = clock();
  run();
  return 0;
}
