#include <bits/stdc++.h>
using namespace std;
int a[22], s1[3], s2[3], s3, s4, b[22], ss = 0;
int n, nn, c[16], sc[16];
int main() {
  cin >> n;
  nn = n * n;
  for (int i = 0; i < nn; i++) {
    cin >> a[i];
    ss += a[i];
  }
  int s = ss / 4;
  if (n <= 3) {
    sort(a, a + nn);
    do {
      memset(s1, 0, sizeof(s1));
      memset(s2, 0, sizeof(s2));
      s3 = s4 = 0;
      for (int i = 0; i < nn; i++) {
        s1[i / n] += a[i];
        s2[i % n] += a[i];
      }
      for (int i = 0; i < nn; i += n + 1) s3 += a[i];
      for (int i = nn - n, j = 0; j < n; i -= n - 1, j++) s4 += a[i];
      bool good = s3 == s4;
      for (int i = 1; i < n; i++)
        if (s1[i] != s1[0]) good = false;
      for (int i = 1; i < n; i++)
        if (s2[i] != s2[0]) good = false;
      good &= s3 == s1[0] && s3 == s2[0];
      if (good) {
        cout << s3 << endl;
        for (int i = 0; i < nn; i++) {
          if (i % n == n - 1) {
            cout << a[i] << endl;
          } else
            cout << a[i] << " ";
        }
        return 0;
      }
    } while (next_permutation(a, a + nn));
  } else {
    int cn = 0;
    sort(a, a + nn);
    for (int i = 0; i < nn; i++)
      if (i == 0 || a[i] != a[i - 1]) {
        b[cn] = a[i];
        c[cn++] = 1;
      } else
        c[cn - 1]++;
    for (int a11 = 0; a11 < cn; a11++)
      if (c[a11]) {
        c[a11]--;
        for (int a12 = 0; a12 < cn; a12++)
          if (c[a12]) {
            c[a12]--;
            for (int a13 = 0; a13 < cn; a13++)
              if (c[a13]) {
                c[a13]--;
                int b14 = s - b[a11] - b[a12] - b[a13];
                int j0 = 0;
                for (; j0 < cn; j0++)
                  if (b[j0] == b14) break;
                if (j0 == cn || c[j0] == 0) {
                  c[a13]++;
                  continue;
                }
                c[j0]--;
                for (int a21 = 0; a21 < cn; a21++)
                  if (c[a21]) {
                    c[a21]--;
                    for (int a22 = 0; a22 < cn; a22++)
                      if (c[a22]) {
                        c[a22]--;
                        for (int a23 = 0; a23 < cn; a23++)
                          if (c[a23]) {
                            c[a23]--;
                            int b24 = s - b[a21] - b[a23] - b[a22];
                            int j1 = 0;
                            for (; j1 < cn; j1++)
                              if (b[j1] == b24) break;
                            if (j1 == cn || c[j1] == 0) {
                              c[a23]++;
                              continue;
                            }
                            c[j1]--;
                            for (int a32 = 0; a32 < cn; a32++)
                              if (c[a32]) {
                                c[a32]--;
                                int b42 = s - b[a12] - b[a22] - b[a32];
                                int j2 = 0;
                                for (; j2 < cn; j2++)
                                  if (b[j2] == b42) break;
                                if (j2 == cn || c[j2] == 0) {
                                  c[a32]++;
                                  continue;
                                }
                                c[j2]--;
                                for (int a33 = 0; a33 < cn; a33++)
                                  if (c[a33]) {
                                    c[a33]--;
                                    int b43 = s - b[a13] - b[a23] - b[a33];
                                    int b44 = s - b[a11] - b[a22] - b[a33];
                                    int b41 = s - b42 - b43 - b44;
                                    if (b41 != s - b14 - b[a23] - b[a32]) {
                                      c[a33]++;
                                      continue;
                                    }
                                    int b31 = s - b[a11] - b[a21] - b41;
                                    int b34 = s - b[a32] - b31 - b[a33];
                                    memcpy(sc, c, sizeof(c));
                                    int j3;
                                    for (j3 = 0; j3 < cn; j3++)
                                      if (b[j3] == b43 && c[j3]) {
                                        c[j3]--;
                                        break;
                                      }
                                    if (j3 < cn) {
                                      for (j3 = 0; j3 < cn; j3++)
                                        if (b[j3] == b44 && c[j3]) {
                                          c[j3]--;
                                          break;
                                        }
                                      if (j3 < cn) {
                                        for (j3 = 0; j3 < cn; j3++)
                                          if (b[j3] == b41 && c[j3]) {
                                            c[j3]--;
                                            break;
                                          }
                                        if (j3 < cn) {
                                          for (j3 = 0; j3 < cn; j3++)
                                            if (b[j3] == b31 && c[j3]) {
                                              c[j3]--;
                                              break;
                                            }
                                          if (j3 < cn) {
                                            for (j3 = 0; j3 < cn; j3++)
                                              if (b[j3] == b34 && c[j3]) {
                                                c[j3]--;
                                                break;
                                              }
                                            if (j3 < cn) {
                                              cout << s << endl;
                                              cout << b[a11] << " " << b[a12]
                                                   << " " << b[a13] << " "
                                                   << b14 << endl;
                                              cout << b[a21] << " " << b[a22]
                                                   << " " << b[a23] << " "
                                                   << b24 << endl;
                                              cout << b31 << " " << b[a32]
                                                   << " " << b[a33] << " "
                                                   << b34 << endl;
                                              cout << b41 << " " << b42 << " "
                                                   << b43 << " " << b44 << endl;
                                              return 0;
                                            }
                                          }
                                        }
                                      }
                                    }
                                    memcpy(c, sc, sizeof(c));
                                    c[a33]++;
                                  }
                                c[j2]++;
                                c[a32]++;
                              }
                            c[j1]++;
                            c[a23]++;
                          }
                        c[a22]++;
                      }
                    c[a21]++;
                  }
                c[j0]++;
                c[a13]++;
              }
            c[a12]++;
          }
        c[a11]++;
      }
  }
  return 0;
}
