#include <bits/stdc++.h>
using namespace std;
const long long oo = (1 << 30);
long long n, s;
vector<long long> data;
long long mat[5][5];
bool check(vector<long long> a) {
  long long r = 0, c = 0;
  for (long long i = 0; i < a.size(); i++) {
    if (i % n == 0 && i != 0) r++;
    mat[r][i % n] = a[i];
  }
  bool ok = 1;
  for (long long i = 0; i < n; i++) {
    long long sum = 0;
    for (long long j = 0; j < n; j++) sum += mat[i][j];
    if (sum != s) return false;
  }
  for (long long j = 0; j < n; j++) {
    long long sum = 0;
    for (long long i = 0; i < n; i++) sum += mat[i][j];
    if (sum != s) return false;
  }
  long long sum = 0;
  for (long long i = 0; i < n; i++) sum += mat[i][i];
  if (sum != s) return false;
  sum = 0;
  long long x = n - 1, y = 0;
  while (x >= 0 && y < n) {
    sum += mat[x][y];
    x--;
    y++;
  }
  if (sum != s) return false;
  return true;
}
int main() {
  cin >> n;
  data.assign(n * n, 0);
  long long sum = 0;
  for (long long i = 0; i < n * n; i++) cin >> data[i], sum += data[i];
  sort(data.begin(), data.end());
  s = sum / n;
  bool ok = true;
  cout << s << '\n';
  while (ok) {
    random_shuffle(data.begin(), data.end());
    if (check(data)) ok = 0;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) cout << mat[i][j] << " ";
    cout << '\n';
  }
  return 0;
}
