#include <bits/stdc++.h>
using namespace std;
int N, k;
int dizi[100], A[100][100];
bool use[100];
void read() {
  int i, j;
  scanf("%d", &N);
  for (i = 1; i <= N * N; i++) scanf("%d", dizi + i);
}
bool control() {
  long long i, j, t = 0, t2;
  for (i = 1; i <= N; i++) t += A[1][i];
  for (i = 2; i <= N; i++) {
    t2 = 0;
    for (j = 1; j <= N; j++) t2 += A[i][j];
    if (t != t2) return 0;
  }
  for (i = 1; i <= N; i++) {
    t2 = 0;
    for (j = 1; j <= N; j++) t2 += A[j][i];
    if (t != t2) return 0;
  }
  t2 = 0;
  for (i = 1; i <= N; i++) t2 += A[i][i];
  if (t2 != t) return 0;
  t2 = 0;
  for (i = 1; i <= N; i++) t2 += A[i][N - i + 1];
  if (t2 == t) {
    cout << t << endl;
    for (i = 1; i <= N; i++, printf("\n"))
      for (j = 1; j <= N; j++) printf("%d ", A[i][j]);
    exit(0);
  }
}
void print() {
  int i, j;
  for (i = 1; i <= N; i++, printf("\n"))
    for (j = 1; j <= N; j++) printf("%d ", A[i][j]);
}
void solve(int x, int y) {
  if (y == N + 1) {
    solve(x + 1, 1);
    return;
  }
  if (x == N + 1) {
    control();
    return;
  }
  int i;
  for (i = 1; i <= N * N; i++)
    if (!use[i]) {
      A[x][y] = dizi[i];
      use[i] = true;
      solve(x, y + 1);
      use[i] = false;
    }
}
int main() {
  read();
  solve(1, 1);
  return 0;
}
