#include <bits/stdc++.h>
using namespace std;
int n;
int a[20], flag[20];
int b[5][5], ans[5][5], cnt;
void solve(int x, int y) {
  if (x == n) {
    int sum = 0;
    for (int i = 0; i < n; i++) sum += b[0][i];
    for (int i = 1; i < n; i++) {
      int cur = 0;
      for (int j = 0; j < n; j++) cur += b[i][j];
      if (sum != cur) return;
    }
    for (int i = 0; i < n; i++) {
      int cur = 0;
      for (int j = 0; j < n; j++) cur += b[j][i];
      if (sum != cur) return;
    }
    int cur = 0;
    for (int i = 0; i < n; i++) cur += b[i][i];
    if (cur != sum) return;
    cur = 0;
    for (int i = 0; i < n; i++) cur += b[i][n - i - 1];
    if (cur != sum) return;
    cnt = sum;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) ans[i][j] = b[i][j];
  }
  for (int i = 0; i < n * n; i++)
    if (!flag[i]) {
      b[x][y] = a[i];
      flag[i] = 1;
      solve(x + (y + 1) / n, (y + 1) % n);
      flag[i] = 0;
    }
}
int main() {
  cin >> n;
  for (int i = 0; i < n * n; i++) cin >> a[i];
  solve(0, 0);
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    cout << ans[i][0];
    for (int j = 1; j < n; j++) cout << " " << ans[i][j];
    cout << endl;
  }
  return 0;
}
