#include <bits/stdc++.h>
int matrix[16];
bool hassolution;
int DP[1 << 16][25];
int n;
bool find(int vet[16]) {
  int sum = 0;
  for (int i = 0; i < n * n; i += (n + 1)) sum += vet[i];
  int newsum = 0;
  for (int i = 0; i < n * n; i++) {
    newsum += vet[i];
    if ((i + 1) % n == 0) {
      if (newsum != sum) return false;
      newsum = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int news = 0;
    int j = i;
    while (j < n * n) {
      news += vet[j];
      j += n;
    }
    if (news != sum) return false;
  }
  int ksum = 0;
  for (int i = n - 1; i < (n - 1) * n + 1; i += (n - 1)) ksum += vet[i];
  if (ksum != sum) return false;
  printf("%d\n", sum);
  for (int i = 0; i < n * n; i++) {
    printf("%d ", vet[i]);
    if ((i + 1) % n == 0) printf("\n");
  }
  return true;
}
int ct = 0;
void solve(int mask, int mask2, int vet[16], int pos) {
  int sum = 0;
  if (mask == ((1 << (n * n)) - 1) && mask == mask2) {
    if (find(vet)) {
      hassolution = true;
      return;
    }
  }
  for (int j = 0; j < n * n && !hassolution; j++) {
    if (!(mask2 & (1 << j))) {
      vet[pos] = matrix[j];
      solve(mask | (1 << pos), mask2 | (1 << j), vet, pos + 1);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * n; i++) scanf("%d", &matrix[i]);
  if (n == 1) {
    printf("%d\n%d\n", matrix[0], matrix[0]);
    return 0;
  }
  int vet[16];
  memset(DP, -1, sizeof(DP));
  solve(0, 0, vet, 0);
  return 0;
}
