#include <bits/stdc++.h>
using namespace std;
int a[10][10];
int b[100];
int n, s;
map<int, int> mp;
void solve();
int main(void) {
  cin >> n;
  for (int i = 0; i < (n * n); ++i) cin >> b[i];
  if (n <= 3) {
    int s = accumulate(b, b + n * n, 0) / n;
    sort(b, b + n * n);
    do {
      bool tag = true;
      int cc = 0;
      for (int i = 0; i < (n); ++i)
        for (int j = 0; j < (n); ++j) a[i][j] = b[cc++];
      for (int i = 0; i < (n); ++i) {
        int c = 0;
        for (int j = 0; j < (n); ++j) c += a[i][j];
        if (c != s) tag = false;
      }
      for (int j = 0; j < (n); ++j) {
        int c = 0;
        for (int i = 0; i < (n); ++i) c += a[i][j];
        if (c != s) tag = false;
      }
      int c = 0;
      for (int i = 0; i < (n); ++i) c += a[i][i];
      if (c != s) tag = false;
      c = 0;
      for (int i = 0; i < (n); ++i) c += a[i][n - 1 - i];
      if (c != s) tag = false;
      if (tag) {
        cout << s << endl;
        for (int i = 0; i < (n); ++i) {
          for (int j = 0; j < (n); ++j) cout << a[i][j] << ' ';
          cout << endl;
        }
        return 0;
      }
    } while (next_permutation(b, b + n * n));
  } else
    solve();
}
void dfs(int x, int y) {
  if (y == 0 && x) {
    if (accumulate(a[x - 1], a[x - 1] + 4, 0) != s) return;
  }
  if (x == 4) {
    for (int j = 0; j < (4); ++j) {
      int c = 0;
      for (int i = 0; i < (4); ++i) c += a[i][j];
      if (c != s) return;
    }
    int c = 0;
    for (int i = 0; i < (4); ++i) c += a[i][i];
    if (c != s) return;
    c = 0;
    for (int i = 0; i < (4); ++i) c += a[i][3 - i];
    if (c != s) return;
    for (int i = 0; i < (4); ++i) {
      for (int j = 0; j < (4); ++j) cout << a[i][j] << ' ';
      cout << endl;
    }
    exit(0);
  }
  int nx = x, ny = y + 1;
  if (ny >= 4) ny = 0, ++nx;
  for (auto it = (mp).begin(); it != (mp).end(); ++it)
    if (it->second > 0) {
      --it->second;
      a[x][y] = it->first;
      dfs(nx, ny);
      ++it->second;
    }
}
void solve() {
  s = accumulate(b, b + n * n, 0) / n;
  cout << s << endl;
  for (int i = 0; i < (16); ++i) ++mp[b[i]];
  dfs(0, 0);
}
