#include <bits/stdc++.h>
using namespace std;
int b[10];
int a[3][3];
int used[10];
int n;
void check() {
  int sum1 = 0, sum = 0;
  for (int i = 0; i < n; i++) sum1 += a[i][i];
  for (int i = 0; i < n; i++) sum += a[n - 1 - i][i];
  if (sum != sum1) return;
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = 0; j < n; j++) sum += a[i][j];
    if (sum != sum1) return;
    sum = 0;
    for (int j = 0; j < n; j++) sum += a[j][i];
    if (sum != sum1) return;
  }
  cout << sum << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cout << a[i][j] << " ";
    cout << endl;
  }
  exit(0);
}
void get(int num) {
  if (num == n * n) check();
  for (int i = 0; i < n * n; i++)
    if (!used[i]) {
      a[num / n][num % n] = b[i];
      used[i] = 1;
      get(num + 1);
      used[i] = 0;
    }
}
int main(void) {
  cin >> n;
  for (int i = 0; i < n * n; i++) cin >> b[i];
  get(0);
  return 0;
}
