#include <bits/stdc++.h>
using namespace std;
int ma[10][10];
int a[20], n, N;
int orderx[20], ordery[20], cnt[20], rec[20], pos[20];
long long RS[10], CS[10], DS, DDS;
bool used[20];
long long S;
bool dfs(int dep) {
  if (dep == N) {
    return DS == S;
  }
  int x = orderx[dep], y = ordery[dep];
  for (int i = 0; i < N; ++i)
    if (!used[i] && cnt[rec[i]] == pos[i]) {
      cnt[rec[i]]++;
      used[i] = true;
      RS[x] += a[i];
      CS[y] += a[i];
      if (x == y) DS += a[i];
      if (x + y == n - 1) DDS += a[i];
      bool flag = true;
      if (y == n - 1 && RS[x] != S) flag = false;
      if (x == n - 1 && CS[y] != S) flag = false;
      if (x == n - 1 && y == 0 && DDS != S) flag = false;
      ma[x][y] = a[i];
      if (flag) {
        if (dfs(dep + 1)) return true;
      }
      cnt[rec[i]]--;
      used[i] = false;
      RS[x] -= a[i];
      CS[y] -= a[i];
      if (x == y) DS -= a[i];
      if (x + y == n - 1) DDS -= a[i];
    }
  return false;
}
int main() {
  cin >> n;
  N = n * n;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  sort(a, a + N);
  for (int i = 0; i < N; ++i) {
    int j = i + 1;
    while (j < N && a[j] == a[i]) j++;
    for (int k = i; k < j; ++k) {
      rec[k] = i;
      pos[k] = k - i;
    }
    i = j - 1;
  }
  int t = 0;
  for (int i = 0; i <= n + n - 2; ++i) {
    for (int x = 0; x < n; ++x) {
      int y = i - x;
      if (y >= 0 && y < n) {
        orderx[t] = x;
        ordery[t] = y;
        t++;
      }
    }
  }
  S = 0;
  for (int i = 0; i < N; ++i) {
    S += a[i];
  }
  S /= n;
  cout << S << endl;
  DS = DDS = 0;
  dfs(0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n - 1; ++j) {
      cout << ma[i][j] << " ";
    }
    cout << ma[i][n - 1] << endl;
  }
}
