#include <bits/stdc++.h>
using namespace std;
bool f(int a[], int n, int &s) {
  int t;
  s = 0;
  for (int k = 0; k < n; ++k) s += a[k * n + k];
  for (int i = 0; i < n; ++i) {
    t = 0;
    for (int j = 0; j < n; ++j) t += a[i * n + j];
    if (t != s) return false;
  }
  for (int j = 0; j < n; ++j) {
    t = 0;
    for (int i = 0; i < n; ++i) t += a[i * n + j];
    if (t != s) return false;
  }
  t = 0;
  for (int k = 0; k < n; ++k) t += a[k * n + (n - k - 1)];
  if (t != s) return false;
  return true;
}
int main() {
  int n;
  int a[9];
  int s;
  cin >> n;
  for (int i = 0; i < n * n; ++i) cin >> a[i];
  while (true) {
    if (f(a, n, s)) {
      cout << s << "\n";
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) cout << a[n * i + j] << " ";
        cout << "\n";
      }
      break;
    }
    next_permutation(a, a + n * n);
  }
}
