#include <bits/stdc++.h>
using namespace std;
int n;
int s;
map<int, int> MAP;
vector<int> a;
bool isOK(vector<int> &b) {
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) sum += b[i * n + j];
    if (sum != s) return false;
  }
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) sum += b[j * n + i];
    if (sum != s) return false;
  }
  int sum = 0;
  for (int i = 0; i < n; i++) sum += b[i * n + i];
  if (sum != s) return false;
  sum = 0;
  for (int i = 0; i < n; i++) sum += b[i * n + n - 1 - i];
  if (sum != s) return false;
  return true;
}
void writeTable(vector<int> &b) {
  printf("%d\n", s);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      printf("%d", b[i * n + j]);
      if (j + 1 < n)
        printf(" ");
      else
        printf("\n");
    }
}
bool canUse(int x) { return MAP[x] > 0; }
bool use(int num, int x) {
  a[num] = x;
  MAP[x]--;
}
bool unuse(int num) { MAP[a[num]]++; }
void dfs(int num) {
  int i = num;
  if (num == 16) {
    if (isOK(a)) {
      writeTable(a);
      exit(0);
    }
  }
  if (i < 13) {
    if (i % 4 < 3) {
      for (map<int, int>::iterator it = MAP.begin(); it != MAP.end(); it++)
        if (canUse(it->first)) {
          use(i, it->first);
          dfs(i + 1);
          unuse(i);
        }
    } else {
      int v = s - a[i - 1] - a[i - 2] - a[i - 3];
      if (canUse(v)) {
        use(i, v);
        dfs(i + 1);
        unuse(i);
      }
    }
  } else {
    int v = s - a[i - 4] - a[i - 8] - a[i - 12];
    if (canUse(v)) {
      use(i, v);
      dfs(i + 1);
      unuse(i);
    }
  }
}
int main() {
  vector<int> b;
  scanf("%d", &n);
  b.assign(n * n, 0);
  s = 0;
  for (int i = 0; i < n * n; i++) {
    scanf("%d", &b[i]);
    s += b[i];
  }
  s /= n;
  if (n <= 3) {
    while (true) {
      random_shuffle(b.begin(), b.end());
      if (isOK(b)) {
        writeTable(b);
        return 0;
      }
    }
  }
  for (int i = 0; i < n * n; i++) MAP[b[i]] = 0;
  for (int i = 0; i < n * n; i++) MAP[b[i]]++;
  a.assign(16, 0);
  dfs(0);
  return 0;
}
