#include <bits/stdc++.h>
using namespace std;
const int maxl = 5;
const int maxn = 17;
const int maxh = 3001;
struct Thash {
  int hash[maxh];
  int next[maxn];
  int key[maxn];
  int cnt[maxn];
  int hs;
  void Init() {
    memset(hash, -1, sizeof(hash));
    hs = 0;
  }
  void Add(int x) {
    int s = x % maxh;
    if (s < 0) s += maxh;
    for (int i = hash[s]; i != -1; i = next[i])
      if (key[i] == x) {
        cnt[i]++;
        return;
      }
    key[hs] = x;
    cnt[hs] = 1;
    next[hs] = hash[s];
    hash[s] = hs++;
  }
  int Check(int x) {
    int s = x % maxh;
    if (s < 0) s += maxh;
    for (int i = hash[s]; i != -1; i = next[i])
      if (key[i] == x) {
        if (cnt[i]) {
          cnt[i]--;
          return 1;
        }
        return 0;
      }
    return 0;
  }
} Set;
int vis[maxn];
int num[maxn];
int ans[maxl][maxl];
int n, m, s;
int sum;
void init() {
  scanf("%d", &n);
  s = n * n;
  Set.Init();
  for (int i = 1; i <= s; i++) {
    scanf("%d", &num[i]);
    sum += num[i];
    Set.Add(num[i]);
  }
  sum /= n;
  m = n - 1;
}
bool checksum() {
  int cnt = 0, cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    cnt += ans[i][i];
    cnt1 += ans[n][i];
    cnt2 += ans[i][n - i + 1];
  }
  if (cnt != sum || cnt1 != sum || cnt2 != sum) return 0;
  return 1;
}
bool checkit() {
  int w[7], ws = 0;
  for (int i = 1; i <= n; i++) {
    int cnt = sum, flag = 0;
    for (int j = 1; j <= m; j++) cnt -= ans[j][i];
    if (!Set.Check(cnt)) {
      for (int i = 1; i <= ws; i++) Set.Add(w[i]);
      return 0;
    }
    ans[n][i] = cnt;
    w[++ws] = cnt;
  }
  if (!checksum()) {
    for (int i = 1; i <= ws; i++) Set.Add(w[i]);
    return 0;
  }
  return 1;
}
bool dfs(int x, int y, int s) {
  if (x > m) return checkit();
  for (int i = 0; i < Set.hs; i++)
    if (Set.cnt[i] > 0) {
      Set.cnt[i]--;
      ans[x][y] = Set.key[i];
      if (y < m) {
        if (dfs(x, y + 1, s + ans[x][y])) return 1;
      } else if (Set.Check(sum - s - ans[x][y])) {
        ans[x][n] = sum - s - ans[x][y];
        if (dfs(x + 1, 1, 0)) return 1;
        Set.Add(sum - s - ans[x][y]);
      }
      Set.cnt[i]++;
    }
  return 0;
}
void work() { dfs(1, 1, 0); }
void print() {
  printf("%d\n", sum);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < n; j++) printf("%d ", ans[i][j]);
    printf("%d\n", ans[i][n]);
  }
}
int main() {
  init();
  work();
  print();
  return 0;
}
