#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int f[20];
int G[20], H[20];
bool z[20];
int A, B;
int main() {
  int n;
  cin >> n;
  int N = n * n;
  for (int i = 1; i <= N; ++i) cin >> f[i];
  sort(f + 1, f + N + 1);
  int s = 0;
  for (int i = 1; i <= N; ++i) s += f[i];
  s /= n;
  cout << s << endl;
  if (n == 4) {
    memset(z, true, sizeof(z));
    for (int i1 = 1; i1 <= N; ++i1)
      for (int i2 = 1; i2 <= N; ++i2)
        if (i2 != i1)
          for (int i3 = 1; i3 <= N; ++i3)
            if (i1 != i3 && i2 != i3) {
              int j;
              for (j = 1; j <= N; ++j)
                if (j != i1 && j != i2 && j != i3 && z[j] &&
                    f[j] == s - f[i1] - f[i2] - f[i3])
                  break;
              if (j == N + 1) continue;
              z[i1] = false;
              z[i2] = false;
              z[i3] = false;
              z[j] = false;
              A = f[j];
              for (int j1 = 1; j1 <= N; ++j1)
                if (z[j1])
                  for (int j2 = 1; j2 <= N; ++j2)
                    if (z[j2] && j2 != j1)
                      for (int j3 = 1; j3 <= N; ++j3)
                        if (z[j3] && j3 != j2 && j3 != j1) {
                          int j;
                          for (j = 1; j <= N; ++j)
                            if (j != j1 && j != j2 && j != j3 && z[j] &&
                                f[j] == s - f[j1] - f[j2] - f[j3])
                              break;
                          if (j == N + 1) continue;
                          z[j1] = false;
                          z[j2] = false;
                          z[j3] = false;
                          z[j] = false;
                          B = f[j];
                          for (int c = 1; c <= N; ++c)
                            if (z[c]) {
                              int v1 = -1, v2 = -1;
                              for (int v = 1; v <= N; ++v)
                                if (z[v])
                                  if (v != c && v1 == -1 &&
                                      f[v] == s - f[i2] - f[j2] - f[c])
                                    v1 = v;
                                  else if (v != c &&
                                           f[v] == s - A - f[j3] - f[c])
                                    v2 = v;
                              if (v1 == -1 || v2 == -1) continue;
                              int vv = -1;
                              for (int v = 1; v <= N; ++v)
                                if (v != v1 && v != v2 && v != c && z[v] &&
                                    f[v] == s - f[i1] - f[j1] - f[v2])
                                  vv = v;
                              if (vv == -1) continue;
                              z[c] = false;
                              z[v1] = false;
                              z[v2] = false;
                              z[vv] = false;
                              int gg = 0;
                              for (int v = 1; v <= N; ++v)
                                if (z[v]) G[++gg] = f[v];
                              int x = s - f[vv] - f[c], y = s - f[v1] - f[v2],
                                  zz = s - f[i3] - f[j3], t = s - A - B,
                                  p = s - f[i1] - f[j2];
                              int d = (p + y - zz);
                              if (d % 2 == 0) {
                                d >>= 1;
                                int a = p - d, b = x - a, c = zz - a;
                                int hh = 0;
                                H[++hh] = a;
                                H[++hh] = b;
                                H[++hh] = c;
                                H[++hh] = d;
                                sort(H + 1, H + hh + 1);
                                if (H[1] == G[1] && H[2] == G[2] &&
                                    H[3] == G[3] && H[4] == G[4]) {
                                  cout << f[i1] << " " << f[i2] << " " << f[i3]
                                       << " " << A << "\n"
                                       << f[j1] << " " << f[j2] << " " << f[j3]
                                       << " " << B << "\n"
                                       << f[vv] << " " << f[c] << " " << a
                                       << " " << b << "\n"
                                       << f[v2] << " " << f[v1] << " " << c
                                       << " " << d << "\n";
                                  return 0;
                                }
                              }
                              z[vv] = true;
                              z[v1] = z[v2] = true;
                              z[c] = true;
                            }
                          z[j] = true;
                          z[j1] = true;
                          z[j2] = true;
                          z[j3] = true;
                        }
              z[j] = true;
              z[i1] = true;
              z[i2] = true;
              z[i3] = true;
            }
    return 0;
  }
  if (n == 1) {
    cout << f[1] << endl;
    return 0;
  }
  if (n == 3) {
    memset(z, true, sizeof(z));
    for (int i1 = 1; i1 <= N; ++i1)
      for (int i2 = 1; i2 <= N; ++i2)
        if (i2 != i1)
          for (int i3 = 1; i3 <= N; ++i3)
            if (i3 != i2 && i3 != i1)
              for (int i4 = 1; i4 <= N; ++i4)
                if (i4 != i3 && i4 != i2 && i4 != i1) {
                  z[i1] = false;
                  z[i2] = false;
                  z[i3] = false;
                  z[i4] = false;
                  int gg = 0;
                  for (int i = 1; i <= N; ++i)
                    if (z[i]) {
                      G[++gg] = f[i];
                    }
                  int a, b, c, d;
                  int hh = 0;
                  H[++hh] = s - f[i1] - f[i2];
                  a = H[hh];
                  H[++hh] = s - f[i3] - f[i4];
                  b = H[hh];
                  H[++hh] = s - f[i1] - f[i4];
                  H[++hh] = s - f[i2] - f[i4];
                  c = H[hh];
                  H[++hh] = s - f[i1] - f[i3];
                  d = H[hh];
                  sort(H + 1, H + hh + 1);
                  sort(G + 1, G + gg + 1);
                  bool ok = true;
                  for (int i = 1; i <= gg; ++i)
                    if (G[i] != H[i]) ok = false;
                  if (ok && d + f[i4] + a == s && d + c == a + b &&
                      d + c == f[i1] + f[i4]) {
                    cout << f[i1] << " " << f[i2] << " " << s - f[i1] - f[i2]
                         << endl;
                    cout << f[i3] << " " << f[i4] << " " << s - f[i3] - f[i4]
                         << endl;
                    cout << s - f[i1] - f[i3] << " " << s - f[i2] - f[i4] << " "
                         << s - (s - f[i1] - f[i2]) - (s - f[i3] - f[i4])
                         << endl;
                    return 0;
                  }
                  z[i1] = true;
                  z[i2] = true;
                  z[i3] = true;
                  z[i4] = true;
                }
  }
  if (n == 2) {
    for (int i1 = 1; i1 <= N; ++i1)
      for (int i2 = 1; i2 <= N; ++i2)
        if (i2 != i1)
          for (int i3 = 1; i3 <= N; ++i3)
            if (i3 != i2 && i3 != i1)
              for (int i4 = 1; i4 <= N; ++i4)
                if (i4 != i3 && i4 != i2 && i4 != i1) {
                  if (f[i1] + f[i2] == s && f[i1] + f[i3] == s &&
                      f[i1] + f[i4] == s && f[i3] + f[i4] == s &&
                      f[i2] + f[i4] == s) {
                    cout << f[i1] << " " << f[i2] << endl;
                    cout << f[i3] << " " << f[i4] << endl;
                    return 0;
                  }
                }
  }
  return 0;
}
