#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> rep;
int a[4][4];
int suma;
bool force(int x, int y) {
  if (x == n) {
    int d1 = 0;
    for (int i = 0; i < n; i++) d1 += a[i][i];
    int d2 = 0;
    for (int i = 0; i < n; i++) d2 += a[i][n - 1 - i];
    bool ok = d1 == suma && d2 == suma;
    if (ok == 0) return 0;
    cout << suma << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) printf("%d%c", a[i][j], j == n - 1 ? 10 : 32);
    }
    return 1;
  }
  if (y == n - 1) {
    int num = suma;
    for (int i = 0; i < n - 1; i++) num -= a[x][i];
    if (rep.count(num) == 0 || rep[num] == 0) return 0;
    a[x][y] = num;
    rep[num]--;
    if (force(x + 1, 0)) return 1;
    rep[num]++;
    return 0;
  }
  if (x == n - 1) {
    int num = suma;
    for (int i = 0; i < n - 1; i++) num -= a[i][y];
    if (rep.count(num) == 0 || rep[num] == 0) return 0;
    a[x][y] = num;
    rep[num]--;
    if (force(x, y + 1)) return 1;
    rep[num]++;
    return 0;
  }
  for (typeof rep.begin() it = rep.begin(); it != rep.end(); it++)
    if (it->second) {
      it->second--;
      a[x][y] = it->first;
      if (force(x, y + 1)) return 1;
      it->second++;
    }
  return 0;
}
int main() {
  cin >> n;
  int x;
  for (int i = 0; i < n * n; i++) cin >> x, rep[x]++, suma += x;
  suma /= n;
  force(0, 0);
}
