#include <bits/stdc++.h>
using namespace std;
int a[10][10];
int b[100];
int main(void) {
  int n;
  cin >> n;
  for (int i = 0; i < (n * n); ++i) cin >> b[i];
  int s = accumulate(b, b + n * n, 0) / n;
  sort(b, b + n * n);
  do {
    bool tag = true;
    int cc = 0;
    for (int i = 0; i < (n); ++i)
      for (int j = 0; j < (n); ++j) a[i][j] = b[cc++];
    for (int i = 0; i < (n); ++i) {
      int c = 0;
      for (int j = 0; j < (n); ++j) c += a[i][j];
      if (c != s) tag = false;
    }
    for (int j = 0; j < (n); ++j) {
      int c = 0;
      for (int i = 0; i < (n); ++i) c += a[i][j];
      if (c != s) tag = false;
    }
    int c = 0;
    for (int i = 0; i < (n); ++i) c += a[i][i];
    if (c != s) tag = false;
    c = 0;
    for (int i = 0; i < (n); ++i) c += a[i][n - 1 - i];
    if (c != s) tag = false;
    if (tag) {
      cout << s << endl;
      for (int i = 0; i < (n); ++i) {
        for (int j = 0; j < (n); ++j) cout << a[i][j] << ' ';
        cout << endl;
      }
      return 0;
    }
  } while (next_permutation(b, b + n * n));
}
