#include <bits/stdc++.h>
using namespace std;
int n, n2;
int a[16];
int s = 0;
bool check() {
  int t = 0;
  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;
    t = 0;
    for (int j = 0; j < n; j++) t += a[j * n + i];
    if (t != s) return false;
  }
  t = 0;
  for (int i = 0; i < n; i++) t += a[i * n + i];
  if (t != s) return false;
  t = 0;
  for (int i = 0; i < n; i++) t += a[i * n + (n - i - 1)];
  if (t != s) return false;
  return true;
}
void solve_small() {
  do {
    if (check()) {
      cout << s << endl;
      for (int i = 0; i < n2; i++) cout << a[i] << endl;
      break;
    }
  } while (next_permutation(a, a + n2));
}
int b[4][4];
bool used[16];
void solve(int i, int j) {
  if (i == 4) {
    if (b[0][0] + b[1][1] + b[2][2] + b[3][3] != s) return;
    cout << s << endl;
    for (int k = 0; k < 4; k++) {
      for (int l = 0; l < 4; l++) cout << b[k][l] << " ";
      cout << endl;
    }
    exit(0);
  }
  if (i == 3 && j == 1) {
    if (b[0][3] + b[1][2] + b[2][1] + b[3][0] != s) return;
  }
  if (i == 3 && j > 0) {
    if (b[0][j - 1] + b[1][j - 1] + b[2][j - 1] + b[3][j - 1] != s) return;
  }
  if (j == 4) {
    if (b[i][0] + b[i][1] + b[i][2] + b[i][3] != s) return;
    solve(i + 1, 0);
    return;
  }
  int prev = (1 << 30);
  for (int k = 0; k < 16; k++)
    if (!used[k] && a[k] != prev) {
      prev = a[k];
      used[k] = true;
      b[i][j] = a[k];
      solve(i, j + 1);
      used[k] = false;
    }
}
int main() {
  cin >> n;
  n2 = n * n;
  for (int i = 0; i < n2; i++) {
    cin >> a[i];
    s += a[i];
  }
  s /= n;
  sort(a, a + n2);
  if (n <= 3)
    solve_small();
  else
    solve(0, 0);
}
