#include <bits/stdc++.h>
using namespace std;
const int N = 6;
const int M = 10010;
const int K = 510;
const int LIT = 2500;
const long long INF = 1LL << 60;
int n, m[N][N], tot;
vector<int> v, vis;
void init() {
  memset(m, 0, sizeof(m));
  tot = n * n;
  v = vector<int>(n * n);
  vis = vector<int>(n * n);
  for (int i = 0; i < tot; i++) cin >> v[i];
  sort(v.begin(), v.end());
}
bool dfs1(int x, int y) {
  if (x > n) {
    int sum = 0;
    for (int i = 1; i <= n; i++) sum += m[1][i];
    for (int i = 2; i <= n; i++) {
      int tmp = 0;
      for (int j = 1; j <= n; j++) tmp += m[i][j];
      if (tmp != sum) return 0;
    }
    for (int i = 1; i <= n; i++) {
      int tmp = 0;
      for (int j = 1; j <= n; j++) tmp += m[j][i];
      if (tmp != sum) return 0;
    }
    int tmp1 = 0, tmp2 = 0;
    for (int i = 1; i <= n; i++) tmp1 += m[i][i], tmp2 += m[i][n - i + 1];
    if (tmp1 != sum || tmp2 != sum) return 0;
    printf("%d\n", sum);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) printf("%d ", m[i][j]);
      printf("\n");
    }
    return 1;
  }
  int xx = x, yy = y + 1;
  if (yy > n) xx++, yy = 1;
  for (int i = 0; i < tot; i++) {
    if (vis[i]) continue;
    m[x][y] = v[i];
    vis[i] = 1;
    if (dfs1(xx, yy)) return 1;
    m[x][y] = 0;
    vis[i] = 0;
  }
  return 0;
}
void solve() {
  if (n <= 3) dfs1(1, 1);
}
int main() {
  while (cin >> n) {
    init();
    solve();
  }
}
