#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) >= 1) {
    vector<int> as(n * n);
    int s = 0;
    for (int i = 0; i < n * n; i++) {
      scanf("%d", &as[i]);
      s += as[i];
    }
    assert((s % n) == 0);
    s /= n;
    sort(as.begin(), as.end());
    do {
      bool g = true;
      for (int y = 0; y < n; y++) {
        int cs = 0;
        for (int x = 0; x < n; x++) cs += as[y * n + x];
        g = g && cs == s;
      }
      for (int x = 0; x < n; x++) {
        int cs = 0;
        for (int y = 0; y < n; y++) cs += as[y * n + x];
        g = g && cs == s;
      }
      int cs1 = 0, cs2 = 0;
      for (int x = 0; x < n; x++) {
        cs1 += as[x * n + x];
        cs2 += as[(n - 1 - x) * n + x];
      }
      g = g && cs1 == s && cs2 == s;
      if (g) {
        printf("%d\n", s);
        for (int y = 0; y < n; y++)
          for (int x = 0; x < n; x++)
            printf("%d%c", as[y * n + x], "\n "[x + 1 < n]);
        goto end;
      }
    } while (next_permutation(as.begin(), as.end()));
    assert(false);
  end:;
  }
  return 0;
}
