#include <bits/stdc++.h>
using namespace std;
int n, i, a[22], j, x[22][2], k = 0, s[11], b[5][5], s0 = 0;
int rec(int x0, int y0) {
  if (!((x0 == n - 1) && (y0 == n))) {
    if (y0 == n) {
      y0 = x0;
      x0++;
    }
    if (x0 == n) {
      y0++;
      x0 = y0;
    }
    for (int i = 0; i < k; i++) {
      if (x[i][1]) {
        int xx = x[i][0];
        b[x0][y0] = xx;
        x[i][1]--;
        s[x0] += xx;
        s[y0 + 5] += xx;
        if (x0 == y0) s[4] += xx;
        if (x0 + y0 + 1 == n) s[9] += xx;
        bool t = true;
        if (y0 == n - 1)
          if (s0 != s[x0]) t = false;
        if (x0 == n - 1) {
          if (s0 != s[y0 + 5]) t = false;
        }
        if (t)
          if (x0 <= y0) {
            if (rec(x0, y0 + 1)) return 1;
          } else if (rec(x0 + 1, y0))
            return 1;
        x[i][1]++;
        s[x0] -= xx;
        s[y0 + 5] -= xx;
        if (x0 == y0) s[4] -= xx;
        if (x0 + y0 == n - 1) s[9] -= xx;
      }
    }
  } else {
    if (s0 != s[4]) return 0;
    if (s0 != s[9]) return 0;
    cout << s0 << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) cout << b[i][j] << " ";
      cout << endl;
    }
    return 1;
  }
  return 0;
}
int main() {
  cin >> n;
  for (i = 0; i < n * n; i++) {
    cin >> a[i];
    s0 += a[i];
    bool t = true;
    for (j = 0; j < k; j++)
      if (a[i] == x[j][0]) {
        t = false;
        x[j][1]++;
        break;
      }
    if (t) {
      x[k][0] = a[i];
      x[k][1] = 1;
      k++;
    }
  }
  s0 /= n;
  rec(0, 0);
}
