#include <bits/stdc++.h>
using namespace std;
int sum, i, j, a[5][5], n, b[20];
int check() {
  int res = 0;
  int i, j, nowsum;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      a[i][j] = b[i * n + j];
    }
  for (i = 0; i < n; i++) {
    nowsum = 0;
    for (j = 0; j < n; j++) nowsum += a[i][j];
    res += abs(sum - nowsum);
  }
  for (j = 0; j < n; j++) {
    nowsum = 0;
    for (i = 0; i < n; i++) nowsum += a[i][j];
    res += abs(sum - nowsum);
  }
  nowsum = 0;
  for (i = 0; i < n; i++) nowsum += a[i][i];
  res += abs(nowsum - sum);
  nowsum = 0;
  for (i = 0; i < n; i++) nowsum += a[i][n - i - 1];
  res += abs(nowsum - sum);
  return res;
}
int main() {
  srand((unsigned)time(NULL));
  cin >> n;
  for (i = 0; i < n * n; i++) {
    cin >> b[i];
    sum += b[i];
  }
  sum /= n;
  int q, p, i, j;
  q = check();
  while (q) {
    random_shuffle(b, b + n * n);
    q = check();
    for (int iter = 0; iter < 1000; iter++) {
      i = (rand() * 257) % (n * n);
      j = (rand() * 37) % (n * n);
      while (j == i) {
        j = (rand() * 37) % (n * n);
      }
      if (i > j) swap(i, j);
      swap(b[i], b[j]);
      p = check();
      if (p < q) {
        q = p;
      } else {
        swap(b[i], b[j]);
      }
    }
    q = check();
  }
  cout << sum << endl;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) cout << a[i][j] << ' ';
    cout << endl;
  }
  return 0;
}
