#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, nn, a[10];
  cin >> n, nn = n * n;
  for (int i = 0; i < nn; i++) cin >> a[i];
  sort(a, a + nn);
  do {
    int s1[4], s2[4], s3 = 0, s4 = 0;
    for (int i = 0; i < n; i++)
      s1[i] = s2[i] = 0, s3 += a[i * n + i], s4 += a[i * n + n - i - 1];
    for (int i = 0; i < nn; i++) s2[i % n] += a[i];
    for (int i = 0; i < nn; i++) s1[i / n] += a[i];
    bool flag = true;
    for (int i = 0; i < n; i++)
      if (s1[i] != s2[i] || s1[i] != s1[0]) flag = false;
    if (flag && s3 == s1[0] && s4 == s1[0]) {
      cout << s1[0] << '\n';
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
          if (j != n - 1)
            cout << a[i * n + j] << ' ';
          else
            cout << a[i * n + j];
        if (i != n - 1) cout << '\n';
      }
      return 0;
    }
  } while (next_permutation(a, a + nn));
}
