#include <bits/stdc++.h>
using namespace std;
int g[10];
int d[4][4];
int p[10];
bool mark[10];
int n, s = 0, u = 0, y = 0, b = 0, sum[30], P, cnt = 0;
void f(int i) {
  if (i == n * n) {
    for (int j = 0; j < 2 * n + 2; j++) {
      sum[j] = 0;
    }
    u = 0, y = 0;
    for (int k = 0; k < n * n; k++) {
      d[u][y] = g[k];
      y++;
      if ((k + 1) % n == 0 && k != 0) {
        y = 0;
        u++;
      }
    }
    b = 0;
    cnt = n;
    for (int k = 0; k < n; k++)
      for (int j = 0; j < n; j++) sum[k] += d[k][j];
    int cnt = n;
    for (int k = 0; k < n; k++) {
      for (int j = 0; j < n; j++) sum[cnt] += d[j][k];
      cnt++;
    }
    for (int k = 0; k < n; k++) sum[cnt] += d[k][k];
    cnt++;
    for (int k = 0; k < n; k++) sum[cnt] += d[k][n - k - 1];
    bool ip = true;
    P = sum[0];
    for (int i = 0; i < (2 * n) + 2; i++) {
      if (sum[i] != P) {
        ip = false;
        break;
      }
    }
    if (ip) {
      for (int h = 0; h < n; h++) {
        for (int f = 0; f < n; f++) {
          cout << d[h][f] << " ";
        }
        cout << endl;
      }
      exit(0);
    }
  }
  for (int j = 0; j < n * n; j++) {
    if (mark[j] == 0) {
      mark[j] = 1;
      g[i] = p[j];
      f(i + 1);
      mark[j] = 0;
    }
  }
}
int main() {
  cin >> n;
  if (n == 1) {
    int nima;
    cin >> nima;
    cout << nima << endl << nima;
    return 0;
  }
  for (int i = 0; i < n * n; i++) {
    cin >> p[i];
    s += p[i];
  }
  s /= n;
  cout << s << endl;
  for (int a = 0; a < n - 1; a++) {
    f(a);
  }
}
