#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
  return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
  return a * a;
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;
const int P = 2003;
const int N = 30 + 3;
int n;
int a[N];
bool can[(1 << 16) + 3][P];
int bit[30];
int f[N][N];
int sumc[5], sumr[5], sumd1, sumd2, curSum;
int nn;
int sums[(1 << 16) + 3];
int minv[(1 << 16) + 3];
int maxv[(1 << 16) + 3];
inline bool check(int x, int y, int mask) {
  int revMask = mask ^ (bit[nn] - 1);
  if (sumr[x] + maxv[revMask] * (n - 1 - y) < curSum) return false;
  if (sumr[x] + minv[revMask] * (n - 1 - y) > curSum) return false;
  if (sumc[y] + maxv[revMask] * (n - 1 - x) < curSum) return false;
  if (sumc[y] + minv[revMask] * (n - 1 - x) > curSum) return false;
  int remC = curSum - sumc[y];
  if (abs(remC) > P) remC %= P;
  if (remC < 0) remC += P;
  if (!can[revMask][remC]) return false;
  int remR = curSum - sumr[y];
  if (abs(remR) > P) remR %= P;
  if (remR < 0) remR += P;
  if (!can[revMask][remR]) return false;
  if (x == y) {
    int remD1 = curSum - sumd1;
    if (abs(remD1) > P) remD1 %= P;
    if (remD1 < 0) remD1 += P;
    if (!can[revMask][remD1]) return false;
  }
  if (x == n - 1 - y) {
    int remD2 = curSum - sumd2;
    if (abs(remD2) > P) remD2 %= P;
    if (remD2 < 0) remD2 += P;
    if (!can[revMask][remD2]) return false;
  }
  return true;
}
void go(int x, int y, int mask) {
  if (y == n) return go(x + 1, 0, mask);
  if (x == n) {
    cout << curSum << endl;
    for (int i = 0; i < int(n); i++) {
      for (int j = 0; j < int(n); j++) cout << f[i][j] << ' ';
      cout << endl;
    }
    exit(0);
  }
  for (int i = 0; i < int(nn); i++) {
    if (mask & bit[i]) continue;
    int cura = a[i];
    if (x > 0 && y == n - 1 && cura != curSum - sumr[x]) continue;
    if (x == n - 1 &&
        (cura != curSum - sumc[y] || (y == 0 && cura != curSum - sumd2) ||
         (y == n - 1 && cura != curSum - sumd1)))
      continue;
    if (x == 0) {
      curSum += cura;
      sumr[x] += cura;
      sumc[y] += cura;
      if (x == y) sumd1 += cura;
      if (x == n - 1 - y) sumd2 += cura;
      f[x][y] = cura;
      go(x, y + 1, mask ^ bit[i]);
      curSum -= cura;
      sumr[x] -= cura;
      sumc[y] -= cura;
      if (x == y) sumd1 -= cura;
      if (x == n - 1 - y) sumd2 -= cura;
    } else {
      int nmask = mask ^ bit[i];
      sumr[x] += cura;
      sumc[y] += cura;
      if (x == y) sumd1 += cura;
      if (x == n - 1 - y) sumd2 += cura;
      f[x][y] = cura;
      if (check(x, y, nmask)) go(x, y + 1, nmask);
      sumr[x] -= cura;
      sumc[y] -= cura;
      if (x == y) sumd1 -= cura;
      if (x == n - 1 - y) sumd2 -= cura;
    }
  }
}
int main() {
  for (int i = 0; i < int(30); i++) bit[i] = (1 << i);
  cin >> n;
  nn = n * n;
  for (int i = 0; i < int(n * n); i++) cin >> a[i];
  if (n == 1) {
    cout << a[0] << endl;
    cout << a[0] << endl;
    return 0;
  }
  for (int mask = 0; mask < int(bit[n * n]); mask++) {
    int minvv = INF, maxvv = -INF;
    int sum = 0;
    for (int i = 0; i < int(n * n); i++)
      if (mask & bit[i])
        sum += a[i], minvv = min(minvv, a[i]), maxvv = max(maxvv, a[i]);
    sum %= P;
    sum += P;
    sum %= P;
    sums[mask] = sum;
    minv[mask] = minvv;
    maxv[mask] = maxvv;
  }
  for (int mask = 0; mask < int(bit[n * n]); mask++)
    for (int nmask = mask;; nmask = ((nmask - 1) & mask)) {
      can[mask][sums[nmask]] = true;
      if (nmask == 0) break;
    }
  go(0, 0, 0);
  throw;
  return 0;
}
