#include <bits/stdc++.h>
using namespace std;
const int maxm = 20;
int A[maxm];
int sum = 0;
bool good(int n) {
  if (n == 3) {
    return A[0] + A[1] + A[2] == sum && A[3] + A[4] + A[5] == sum &&
           A[0] + A[3] + A[6] == sum && A[1] + A[4] + A[7] == sum &&
           A[0] + A[4] + A[8] == sum && A[2] + A[4] + A[6] == sum;
  } else if (n == 1) {
    return 1;
  } else if (n == 2) {
    return A[0] + A[1] == sum && A[0] + A[3] == sum && A[1] + A[2] == sum;
  }
}
int main() {
  int n;
  cin >> n;
  int m = n * n;
  for (int i = 0; i < m; ++i) {
    cin >> A[i];
    sum += A[i];
  }
  sort(A, A + m);
  sum /= n;
  do {
    if (good(n)) {
      cout << sum << '\n';
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          cout << A[i * n + j] << ' ';
        }
        cout << '\n';
      }
      return 0;
    }
  } while (next_permutation(A, A + m));
  return 0;
}
