#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n][n];
  int b[n * n + 1];
  for (int i = 0; i < n * n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = b[i * 3 + j];
    }
  }
  sort(b, b + (n * n));
  set<int> setwa;
  int sum = 0;
  do {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        a[i][j] = b[i * n + j];
      }
    }
    int s = 0, ss;
    setwa.clear();
    for (int i = 0; i < n; i++) {
      s = 0;
      ss = 0;
      for (int j = 0; j < n; j++) {
        s += a[i][j];
        ss += a[j][i];
      }
      setwa.insert(s);
      setwa.insert(ss);
    }
    sum = s;
    s = 0;
    ss = 0;
    for (int i = 0; i < n; i++) {
      s += a[i][i];
      ss += a[i][n - 1 - i];
    }
    setwa.insert(s);
    setwa.insert(ss);
    if (setwa.size() == 1) break;
  } while (next_permutation(b, b + (n * n)));
  sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i][0];
  }
  cout << sum << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  cin >> n;
  return 0;
}
