#include <bits/stdc++.h>
using namespace std;
int n, sum, a[4][4], in[16];
int t[8], C, r[4], s[8], f[8], m[5];
bool check() {
  for (int i = 0; i < n; ++i) {
    int p = 0, q = 0;
    for (int j = 0; j < n; ++j) {
      p += a[i][j];
      q += a[j][i];
    }
    if (p != sum || q != sum) return false;
  }
  int p = 0, q = 0;
  for (int i = 0; i < n; ++i) {
    p += a[i][i];
    q += a[i][n - i - 1];
  }
  if (p != sum || q != sum) return false;
  return true;
}
void print() {
  if (check()) {
    cout << sum << endl;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) cout << a[i][j] << (j != n - 1 ? " " : "");
      cout << endl;
    }
  } else
    cout << -1 << endl;
}
bool zero(int mask, int plc) { return ((mask >> plc) & 1) == 0; }
void find_ans(int key, int &mask) {
  for (int i = 0; i < 16; ++i)
    if (zero(mask, i) && in[i] == key) {
      mask |= (1 << i);
      return;
    }
  mask = (1 << 17) - 1;
}
int main() {
  cin >> n;
  for (int i = 0; i < n * n; ++i) {
    cin >> in[i];
    sum += in[i];
  }
  if (n == 1)
    cout << in[0] << endl << in[0] << endl;
  else {
    if (sum % n != 0)
      cout << -1 << endl;
    else if (n != 4) {
      sum /= n;
      int id[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
      do {
        for (int i = 0; i < n; ++i)
          for (int j = 0; j < n; ++j) a[i][j] = in[id[i * n + j]];
        if (check()) break;
      } while (next_permutation(id, id + n * n));
      print();
    } else {
      sum /= n;
      bool E = false;
      for (int i = 0; i < 16 && !E; ++i)
        for (int j = i + 1; j < 16 && !E; ++j)
          for (int k = 0; k < 16 && !E; ++k)
            for (int l = k + 1; l < 16 && !E; ++l)
              if (k != i && k != j && l != i && l != j) {
                s[0] = in[i], s[1] = in[j], s[2] = in[k], s[3] = in[l];
                m[0] = (1 << i) + (1 << j) + (1 << k) + (1 << l);
                bool ans = false;
                for (int i0 = 0; i0 < 16 && !ans; ++i0)
                  if (zero(m[0], i0)) {
                    s[4] = in[i0];
                    m[1] = m[0] + (1 << i0);
                    find_ans(f[0] = sum - s[0] - s[4] - s[1], m[1]);
                    for (int i1 = 0; i1 < 16 && !ans; ++i1)
                      if (zero(m[1], i1)) {
                        s[5] = in[i1];
                        m[2] = m[1] + (1 << i1);
                        find_ans(f[1] = sum - s[5] - s[2] - s[3], m[2]);
                        for (int i2 = 0; i2 < 16 && !ans; ++i2)
                          if (zero(m[2], i2)) {
                            s[6] = in[i2];
                            m[3] = m[2] + (1 << i2);
                            find_ans(f[2] = sum - s[4] - s[6] - f[1], m[3]);
                            find_ans(f[3] = sum - s[1] - s[3] - f[2], m[3]);
                            find_ans(f[4] = sum - s[5] - f[0] - f[3], m[3]);
                            if (f[4] != sum - s[0] - s[6] - s[2]) continue;
                            for (int i3 = 0; i3 < 16 && !ans; ++i3)
                              if (zero(m[3], i3)) {
                                s[7] = in[i3];
                                m[4] = m[3] + (1 << i3);
                                find_ans(f[5] = sum - s[4] - s[5] - s[7], m[4]);
                                find_ans(f[6] = sum - s[1] - s[2] - f[5], m[4]);
                                find_ans(f[7] = sum - f[0] - f[1] - f[6], m[4]);
                                if (f[7] != sum - s[0] - s[3] - s[7]) continue;
                                if (m[4] == (1 << 17) - 1) continue;
                                ans = true;
                                a[0][0] = s[0], a[0][1] = s[6], a[0][2] = f[4],
                                a[0][3] = s[2];
                                a[1][0] = s[7], a[1][1] = s[4], a[1][2] = s[5],
                                a[1][3] = f[5];
                                a[2][0] = f[7], a[2][1] = f[1], a[2][2] = f[0],
                                a[2][3] = f[6];
                                a[3][0] = s[3], a[3][1] = f[2], a[3][2] = f[3],
                                a[3][3] = s[1];
                              }
                          }
                      }
                  }
                if (ans == true) E = true;
              }
      print();
    }
  }
  return 0;
}
