#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4 + 1;
int n, m, sum, vec[MAXN * MAXN];
int d[MAXN][MAXN], sec[MAXN * MAXN], sc[MAXN * MAXN];
int mark[MAXN * MAXN];
bool fl;
vector<int> gec, fr;
map<int, int> cnt;
void gen(int ind) {
  if (ind == m) {
    int c = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++, c++) d[i][j] = sec[c];
    if (n == 1) fl = 1;
    if (fl) return;
    if ((d[0][0] + d[0][1] + d[0][2]) * n == sum &&
        (d[1][0] + d[1][1] + d[1][2]) * n == sum)
      if ((d[0][0] + d[1][0] + d[2][0]) * n == sum &&
          (d[0][1] + d[1][1] + d[2][1]) * n == sum)
        if ((d[0][0] + d[1][1] + d[2][2]) * n == sum) {
          int z = 0;
          for (int i = n - 1; i >= 0; i--) z += d[i][(n - 1) - i];
          if (z * n == sum) fl = 1;
        }
    return;
  }
  for (int i = 0; i < m; i++) {
    if (mark[i]) continue;
    mark[i] = 1;
    sec[ind] = vec[i];
    gen(ind + 1);
    mark[i] = 0;
    if (fl) return;
  }
}
void gg(int ind) {
  if (ind == 4 && (sec[0] + sec[1] + sec[2] + sec[3]) * 4 != sum) return;
  if (ind == 8 && (sec[4] + sec[5] + sec[6] + sec[7]) * 4 != sum) return;
  if (ind == 12 && (sec[8] + sec[9] + sec[10] + sec[11]) * 4 != sum) return;
  if (ind == 16) {
    int c = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++, c++) d[i][j] = sec[c];
    bool fail = 0;
    for (int i = 0; i < n; i++) {
      int z = 0;
      for (int j = 0; j < n; j++) z += d[i][j];
      if (z * 4 != sum) fail = 1;
    }
    if (fail) return;
    for (int j = 0; j < n; j++) {
      int z = 0;
      for (int i = 0; i < n; i++) z += d[i][j];
      if (z * 4 != sum) fail = 1;
    }
    if (fail) return;
    if ((d[0][0] + d[1][1] + d[2][2] + d[3][3]) * 4 != sum) return;
    if ((d[3][0] + d[2][1] + d[1][2] + d[0][3]) * 4 != sum) return;
    fl = 1;
    return;
  }
  for (int i = 0; i < m; i++)
    if (mark[i] != sc[i]) {
      mark[i]++;
      sec[ind] = vec[i];
      gg(ind + 1);
      mark[i]--;
      if (fl) return;
    }
}
int main() {
  cin >> n;
  m = n * n;
  for (int i = 0; i < m; i++) cin >> vec[i], sum += vec[i];
  if (n < 4) {
    gen(0);
    assert(fl);
    cout << d[0][0] + d[0][1] + d[0][2] << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) cout << d[i][j] << " ";
      cout << endl;
    }
    return 0;
  }
  for (int i = 0; i < m; i++) cnt[vec[i]]++;
  sort(vec, vec + m);
  m = unique(vec, vec + m) - vec;
  for (int i = 0; i < m; i++) sc[i] = cnt[vec[i]];
  gg(0);
  cout << d[0][0] + d[0][1] + d[0][2] + d[0][3] << endl;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) cout << d[i][j] << " ";
    cout << endl;
  }
  return 0;
}
