#include <bits/stdc++.h>
using namespace std;
int arr[50], n;
int ma[5][5];
void check() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      ma[i][j] = arr[i * n + j];
    }
  }
  set<int> sum;
  for (int i = 0; i < n; ++i) {
    int s = 0;
    if (sum.size() > 1) return;
    for (int j = 0; j < n; ++j) {
      s += ma[i][j];
    }
    sum.insert(s);
  }
  for (int j = 0; j < n; ++j) {
    int s = 0;
    if (sum.size() > 1) return;
    for (int i = 0; i < n; ++i) {
      s += ma[i][j];
    }
    sum.insert(s);
  }
  int s = 0, s2 = 0;
  for (int i = 0; i < n; ++i) {
    s += ma[i][i];
    s2 += ma[n - i - 1][i];
  }
  sum.insert(s);
  sum.insert(s2);
  if (sum.size() > 1) return;
  cout << s << '\n';
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << ma[i][j];
      if (j + 1 < n) cout << ' ';
    }
    cout << '\n';
  }
  exit(0);
}
int main() {
  cin >> n;
  for (int i = 0; i < n * n; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + n * n);
  int x = 0;
  do {
    ++x;
    check();
  } while (next_permutation(arr, arr + n * n));
  return 0;
}
