#include <bits/stdc++.h>
using namespace std;
int a[20], b[5][5], s, dif[20], cnt[20], n, t;
void dfs(int x, int y) {
  if (y == n + 1) {
    cout << s << endl;
    for (int i = 1; i <= n; i++, cout << endl)
      for (int j = 1; j <= n; j++) cout << b[i][j] << " ";
    exit(0);
  }
  int nx = x + 1, ny = y;
  if (nx == n + 1) nx = 1, ny++;
  for (int i = 0; i <= t; i++) {
    if (cnt[i]) {
      cnt[i]--;
      b[x][y] = dif[i];
      bool ok = true;
      if (x == n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) sum += b[i][y];
        if (sum != s) ok = false;
      }
      if (y == n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) sum += b[x][i];
        if (sum != s) ok = false;
      }
      if (x == n && y == n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) sum += b[i][i];
        if (sum != s) ok = false;
      }
      if (x == 1 && y == n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) sum += b[i][n - i + 1];
        if (sum != s) ok = false;
      }
      if (ok) dfs(nx, ny);
      cnt[i]++;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n * n; i++) cin >> a[i], s += a[i];
  sort(a, a + n * n);
  dif[0] = a[0];
  cnt[0] = 1;
  for (int i = 1; i < n * n; i++)
    if (a[i] != a[i - 1])
      dif[++t] = a[i], cnt[t] = 1;
    else
      cnt[t]++;
  s /= n;
  dfs(1, 1);
  return 0;
}
