#include <bits/stdc++.h>
using namespace std;
int n, S[4][4], ans, N, B[9];
bool got_it;
vector<int> A;
bool TestRow(int i) {
  int sum = 0;
  for (int j = 0; j < n; ++j) sum += S[i][j];
  return sum == ans;
}
bool TestCol(int j) {
  int sum = 0;
  for (int i = 0; i < n; ++i) sum += S[i][j];
  return sum == ans;
}
bool TestDiag() {
  int sum = 0;
  for (int i = 0; i < n; ++i) sum += S[i][n - 1 - i];
  return sum == ans;
}
bool TestMainDiag() {
  int sum = 0;
  for (int i = 0; i < n; ++i) sum += S[i][i];
  return sum == ans;
}
void rec(int x, int y) {
  if (x > 0) {
    if (x == n) {
      if (TestMainDiag() && TestRow(n - 1) && TestCol(n - 1)) got_it = true;
      return;
    } else if (x == n - 1) {
      if (y > 0)
        if (!TestCol(y - 1) || (y == 1 && !TestDiag())) return;
    }
    if (y == 0) {
      if (!TestRow(x - 1)) return;
    }
  }
  for (size_t i = 0; i < A.size(); ++i) {
    if (B[i] > 0) {
      S[x][y] = A[i];
      --B[i];
      if (y + 1 == n)
        rec(x + 1, 0);
      else
        rec(x, y + 1);
      if (got_it) return;
      ++B[i];
    }
  }
}
int main() {
  cin >> n;
  N = n * n;
  int a;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    ans += a;
    bool f = false;
    for (size_t j = 0; j < A.size(); ++j)
      if (A[j] == a) {
        B[j]++;
        f = true;
        break;
      }
    if (!f) {
      A.push_back(a);
      B[A.size() - 1]++;
    }
  }
  ans /= n;
  rec(0, 0);
  cout << ans << endl;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cout << S[i][j] << " ";
    cout << endl;
  }
  return 0;
}
