#include <bits/stdc++.h>
using namespace std;
int n, t;
int a[20];
int used[20];
int b[5][5];
bool ok;
void go(int x, int y, int n) {
  if (x > n) {
    bool good = true;
    int s = 0;
    for (int i = (1); (i) <= (n); ++(i)) s += b[1][i];
    for (int i = (2); (i) <= (n); ++(i)) {
      int sum = 0;
      for (int j = (1); (j) <= (n); ++(j)) sum += b[i][j];
      if (sum != s) {
        good = false;
        break;
      }
    }
    for (int j = (1); (j) <= (n); ++(j)) {
      int sum = 0;
      for (int i = (1); (i) <= (n); ++(i)) sum += b[i][j];
      if (sum != s) {
        good = false;
        break;
      }
    }
    int sum = 0;
    for (int i = (1); (i) <= (n); ++(i)) sum += b[i][i];
    if (sum != s) good = false;
    sum = 0;
    for (int i = (1); (i) <= (n); ++(i)) sum += b[i][n - i + 1];
    if (sum != s) good = false;
    if (!good) return;
    cout << s << endl;
    for (int i = (1); (i) <= (n); ++(i)) {
      for (int j = (1); (j) <= (n); ++(j)) cout << b[i][j] << " ";
      cout << endl;
    }
    ok = true;
    return;
  }
  if (ok) return;
  int xx = x;
  int yy = y;
  yy++;
  if (yy > n) {
    xx++;
    yy = 1;
  }
  for (int i = 1; i <= t; ++i)
    if (used[i] == 0) {
      used[i] = 1;
      b[x][y] = a[i];
      go(xx, yy, n);
      used[i] = 0;
    }
}
int main() {
  cin >> n;
  t = n * n;
  for (int i = 1; i <= t; ++i) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << a[1] << endl;
    cout << a[1] << endl;
    return 0;
  }
  go(1, 1, n);
  return 0;
}
