#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int(i) = 0; (i) < (((int)(t.size()))); ++(i)) s << t[i] << " ";
  return s;
}
int a[26], co[32], ile[32], kinds, s, w[4][4];
const int xx[16] = {0, 0, 0, 0, 1, 2, 3, 1, 3, 2, 3, 3, 1, 2, 1, 2};
const int yy[16] = {0, 1, 2, 3, 1, 2, 3, 2, 2, 1, 1, 0, 0, 0, 3, 3};
typedef bool (*checkFunction)(void);
bool checkNothing() { return 1; }
bool check3() { return s == w[0][0] + w[0][1] + w[0][2] + w[0][3]; }
bool check6() { return s == w[0][0] + w[1][1] + w[2][2] + w[3][3]; }
bool check8() { return s == w[0][2] + w[1][2] + w[2][2] + w[3][2]; }
bool check10() { return s == w[0][1] + w[1][1] + w[2][1] + w[3][1]; }
bool check11() {
  return (s == w[3][0] + w[3][1] + w[3][2] + w[3][3]) &&
         (s == w[0][3] + w[1][2] + w[2][1] + w[3][0]);
}
bool check13() { return s == w[0][0] + w[1][0] + w[2][0] + w[3][0]; }
bool check14() { return s == w[1][0] + w[1][1] + w[1][2] + w[1][3]; }
bool check15() {
  return (s == w[2][0] + w[2][1] + w[2][2] + w[2][3]) &&
         (s == w[0][3] + w[1][3] + w[2][3] + w[3][3]);
}
checkFunction performCheck[16] = {
    checkNothing, checkNothing, checkNothing, checkNothing,
    checkNothing, checkNothing, checkNothing, checkNothing,
    checkNothing, checkNothing, checkNothing, checkNothing,
    checkNothing, checkNothing, checkNothing, checkNothing};
void backtrack(int ktory) {
  if (ktory == 16) {
    for (int(i) = 0; (i) < (4); ++(i)) {
      printf("%d %d %d %d\n", w[i][0], w[i][1], w[i][2], w[i][3]);
    }
    exit(0);
  }
  int x = xx[ktory], y = yy[ktory];
  for (int(kind) = 0; (kind) < (kinds); ++(kind))
    if (ile[kind]) {
      w[x][y] = co[kind];
      --ile[kind];
      bool res = performCheck[ktory]();
      if (res) {
        backtrack(ktory + 1);
      }
      ++ile[kind];
    }
}
int main() {
  performCheck[3] = &check3;
  performCheck[6] = &check6;
  performCheck[8] = &check8;
  performCheck[10] = &check10;
  performCheck[11] = &check11;
  performCheck[13] = &check13;
  performCheck[14] = &check14;
  performCheck[15] = &check15;
  int(n);
  scanf("%d", &(n));
  int nn = n * n;
  s = 0;
  for (int(i) = 0; (i) < (nn); ++(i)) {
    scanf("%d", a + i);
    s += a[i];
  }
  sort(a, a + nn);
  s /= n;
  pisz(s);
  if (n == 1) {
    pisz(s);
  } else if (n == 2) {
    do {
      if (s == a[0] + a[1] && s == a[2] + a[3] && s == a[0] + a[2] &&
          s == a[1] + a[3] && s == a[0] + a[3] && s == a[1] + a[2]) {
        printf("%d %d\n%d %d\n", a[0], a[1], a[2], a[3]);
        return 0;
      }
    } while (next_permutation(a, a + 4));
  } else if (n == 3) {
    do {
      if (s == a[0] + a[1] + a[2] && s == a[3] + a[4] + a[5] &&
          s == a[6] + a[7] + a[8] && s == a[0] + a[3] + a[6] &&
          s == a[1] + a[4] + a[7] && s == a[2] + a[5] + a[8] &&
          s == a[0] + a[4] + a[8] && s == a[2] + a[4] + a[6]) {
        printf("%d %d %d\n%d %d %d\n%d %d %d\n", a[0], a[1], a[2], a[3], a[4],
               a[5], a[6], a[7], a[8]);
        return 0;
      }
    } while (next_permutation(a, a + 9));
  } else {
    kinds = 0;
    for (int(i) = 0; (i) < (nn); ++(i)) {
      if (i != 0 && a[i] == a[i - 1]) {
        ++ile[kinds - 1];
      } else {
        co[kinds] = a[i];
        ile[kinds] = 1;
        kinds++;
      }
    }
    backtrack(0);
  }
}
