#include <bits/stdc++.h>
using namespace std;
int a[10];
int mp[3][3];
int res;
bool check(int n) {
  int s = 0;
  for (int i = 0; i < n; i++) {
    s += mp[0][i];
  }
  int t = 0;
  for (int i = 0; i < n; i++) {
    t = 0;
    for (int j = 0; j < n; j++) t += mp[i][j];
    if (t != s) return false;
  }
  for (int j = 0; j < n; j++) {
    t = 0;
    for (int i = 0; i < n; i++) t += mp[i][j];
    if (t != s) return false;
  }
  t = 0;
  for (int i = 0; i < n; i++) t += mp[i][i];
  if (t != s) return false;
  t = 0;
  for (int i = 0; i < n; i++) t += mp[i][n - i - 1];
  if (t != s) return false;
  res = s;
  return true;
}
int main() {
  int n;
  while (cin >> n) {
    int m = n * n;
    for (int i = 0; i < m; i++) cin >> a[i];
    sort(a, a + m);
    do {
      for (int i = 0; i < m; i++) {
        int x = i / n;
        int y = i % n;
        mp[x][y] = a[i];
      }
      if (check(n)) {
        break;
      }
    } while (next_permutation(a, a + m));
    printf("%d\n", res);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j == n - 1)
          printf("%d\n", mp[i][j]);
        else
          printf("%d ", mp[i][j]);
      }
    }
  }
  return 0;
}
