#include <bits/stdc++.h>
int a[4 * 4];
int n, n2;
std::map<int, int> sums[4 + 1];
void gens(int p, int cnt, int sum, std::map<int, int>& s) {
  if (cnt == 0) {
    std::map<int, int>::iterator it = s.find(sum);
    if (it == s.end())
      s[sum] = 1;
    else
      ++it->second;
    return;
  }
  if (p >= n2) return;
  gens(p + 1, cnt, sum, s);
  gens(p + 1, cnt - 1, sum + a[p], s);
}
int m[4][4];
int hs[4], vs[4], ds1, ds2;
bool used[4 * 4];
int sum;
void doit(int i, int j, int v) {
  hs[i] += v;
  vs[j] += v;
  if (i == j) ds1 += v;
  if (i == n - j - 1) ds2 += v;
}
bool gen(int i, int j) {
  if (i == n) return true;
  for (int k = 0; k < n2; ++k)
    if (!used[k]) {
      int v = a[k];
      m[i][j] = v;
      doit(i, j, v);
      if (i == n - 1 && vs[j] != sum) {
        doit(i, j, -v);
        continue;
      }
      if (j == n - 1 && hs[i] != sum) {
        doit(i, j, -v);
        continue;
      }
      if (i == n - 1 && j == 0 && ds2 != sum) {
        doit(i, j, -v);
        continue;
      }
      if (i == n - 1 && j == n - 1 && ds1 != sum) {
        doit(i, j, -v);
        continue;
      }
      if (hs[i] > sum || vs[j] > sum || ds1 > sum || ds2 > sum) {
        doit(i, j, -v);
        continue;
      }
      used[k] = true;
      int i2 = i, j2 = j + 1;
      if (j2 == n) {
        ++i2;
        j2 = 0;
      }
      if (gen(i2, j2)) return true;
      used[k] = false;
      doit(i, j, -v);
    }
  return false;
}
int main() {
  scanf("%d", &n);
  n2 = n * n;
  int min = 0;
  for (int i = 0; i < n2; ++i) {
    scanf("%d", &a[i]);
    if (a[i] < min) min = a[i];
  }
  min = -min;
  for (int i = 0; i < n2; ++i) a[i] += min;
  for (int i = 1; i <= n; ++i) {
    gens(0, i, 0, sums[i]);
  }
  bool res = false;
  for (std::map<int, int>::const_iterator i = sums[n].begin();
       i != sums[n].end(); ++i) {
    sum = i->first;
    memset(hs, 0, sizeof(hs));
    memset(vs, 0, sizeof(vs));
    memset(used, 0, sizeof(used));
    ds1 = 0;
    ds2 = 0;
    if (gen(0, 0)) {
      res = true;
      break;
    }
  }
  if (!res) {
    printf("sorry. i am failed");
    return 0;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) m[i][j] -= min;
  int s = 0;
  for (int i = 0; i < n; ++i) s += m[i][0];
  printf("%d\n", s);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (j > 0) printf(" ");
      printf("%d", m[i][j]);
    }
    printf("\n");
  }
  return 0;
}
