#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110001;
int ans[4][4];
int n, t;
map<int, int> num;
bool judge() {
  int x, y;
  x = y = t;
  for (int k = 0; k < n; k++) {
    x -= ans[k][k];
    y -= ans[k][n - 1 - k];
  }
  if (x == 0 && y == 0)
    return true;
  else
    return false;
}
bool gao(int i, int j) {
  map<int, int>::iterator it;
  int k, x;
  if (i == n - 1) {
    x = t;
    for (k = 0; k < n; k++) {
      x -= ans[n - 1][k];
    }
    if (x != 0) return false;
    for (k = 0; k < n; k++) {
      it = num.find(ans[i][k]);
      if (it == num.end()) break;
      if (it->second == 0) break;
      it->second--;
    }
    if (k == n && judge()) {
      return true;
    }
    for (k--; k >= 0; k--) num[ans[i][k]]++;
    return false;
  } else if (j == n - 1) {
    x = t;
    for (k = 0; k < n - 1; k++) x -= ans[i][k];
    it = num.find(x);
    if (it == num.end()) return false;
    if (it->second == 0) return false;
    it->second--;
    ans[i + 1][j] = ans[i][j] -= x;
    ans[i][j] = x;
    if (gao(i + 1, 0)) return true;
    ans[i][j] += ans[i + 1][j];
    it->second++;
    return false;
  } else {
    for (it = num.begin(); it != num.end(); it++) {
      if (it->second > 0) {
        it->second--;
        ans[i + 1][j] = ans[i][j] - it->first;
        ans[i][j] = it->first;
        if (gao(i, j + 1)) return true;
        ans[i][j] += ans[i + 1][j];
        it->second++;
      }
    }
    return false;
  }
}
int main() {
  scanf("%d", &n);
  int i, j, m;
  m = n * n;
  num.clear();
  t = 0;
  while (m--) {
    scanf("%d", &i);
    t += i;
    if (num.find(i) != num.end())
      num[i]++;
    else
      num[i] = 1;
  }
  t /= n;
  for (i = 0; i < n; i++) ans[0][i] = t;
  gao(0, 0);
  printf("%d\n", t);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n - 1; j++) printf("%d ", ans[i][j]);
    printf("%d\n", ans[i][j]);
  }
}
