#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MAXn = 100;
int a[MAXn];
int t[MAXn][MAXn];
int n;
bool check() {
  long long s = 0;
  for (int i = 0, __e = n; i < __e; i++) s += t[0][i];
  for (int i = 0, __e = n; i < __e; i++) {
    long long x = 0;
    for (int j = 0, __e = n; j < __e; j++) x += t[i][j];
    if (x != s) return false;
  }
  for (int i = 0, __e = n; i < __e; i++) {
    long long x = 0;
    for (int j = 0, __e = n; j < __e; j++) x += t[j][i];
    if (x != s) return false;
  }
  long long x = 0;
  for (int i = 0, __e = n; i < __e; i++) x += t[i][i];
  if (x != s) return false;
  x = 0;
  for (int i = 0, __e = n; i < __e; i++) x += t[i][n - 1 - i];
  if (x != s) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int m = n * n;
  for (int i = 0, __e = m; i < __e; i++) cin >> a[i];
  sort(a, a + m);
  do {
    int c = 0;
    for (int i = 0, __e = n; i < __e; i++)
      for (int j = 0, __e = n; j < __e; j++) t[i][j] = a[c++];
    if (check()) {
      long long sum = 0;
      for (int i = 0, __e = n; i < __e; i++) sum += t[0][i];
      cout << sum << endl;
      for (int i = 0, __e = n; i < __e; i++) {
        for (int j = 0, __e = n; j < __e; j++) cout << t[i][j] << " ";
        cout << endl;
      }
      return 0;
    }
  } while (next_permutation(a, a + m));
  return 0;
}
