#include <bits/stdc++.h>
using namespace std;
void mytimer(string task) {}
void ext(int c) {}
int val[20];
int cnt[20];
int n;
int S;
int res[4][4];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  vector<int> src(n * n);
  for (int i = 0; i < (n * n); ++i) {
    cin >> src[i];
    S += src[i];
    val[i] = src[i];
  }
  S /= n;
  sort(src.begin(), src.end());
  if (n <= 3) {
    do {
      int ss1 = 0, ss2 = 0;
      bool ok = true;
      for (int i = 0; i < (n); ++i) {
        int s1 = 0, s2 = 0;
        for (int j = 0; j < (n); ++j) {
          s1 += src[i * n + j];
          s2 += src[j * n + i];
        }
        ss1 += src[i * n + i];
        ss2 += src[i * n + (n - 1 - i)];
        if (s1 != S || s2 != S) {
          ok = false;
          break;
        }
      }
      if (ss1 != S || ss2 != S) ok = false;
      if (ok) {
        for (int i = 0; i < (n); ++i)
          for (int j = 0; j < (n); ++j) res[i][j] = src[i * n + j];
        break;
      }
    } while (next_permutation(src.begin(), src.end()));
  } else {
    sort(val, val + n * n);
  }
  cout << S << endl;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (n); ++j) cout << res[i][j] << ' ';
    cout << endl;
  }
  return 0;
}
