#include <bits/stdc++.h>
using namespace std;
int max = 0;
int n = 0;
int media = 0;
int board[4][4];
bool isRowsOk() {
  bool ok = true;
  int somCol[n];
  for (int i = 0; i < n; i++) {
    int sum = 0;
    somCol[i] = 0;
    for (int k = 0; k < n; k++) {
      somCol[i] += board[i][k];
    }
  }
  for (int i = 0; i < n; i++) {
    if (somCol[i] != media) {
      ok = false;
    }
  }
  return ok;
}
bool isColsOk() {
  bool ok = true;
  int somCol[n];
  for (int i = 0; i < n; i++) {
    int sum = 0;
    somCol[i] = 0;
    for (int k = 0; k < n; k++) {
      somCol[i] += board[k][i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (somCol[i] != media) {
      ok = false;
    }
  }
  return ok;
}
bool isDiagOk() {
  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) {
      if (i == k) {
        sum += board[i][k];
      }
    }
  }
  if (sum != media) {
    return false;
  } else {
    return true;
  }
}
bool isSecOk() {
  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) {
      if (i == n - 1 - k) {
        sum += board[i][k];
      }
    }
  }
  if (sum != media) {
    return false;
  } else {
    return true;
  }
}
bool isOk() {
  if (isRowsOk() && isColsOk() && isDiagOk() && isSecOk()) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin >> n;
  int arr[n * n];
  for (int i = 0; i < n * n; i++) {
    cin >> arr[i];
    media += arr[i];
  }
  media = media / (n);
  sort(arr, arr + (n * n));
  int arr2[9] = {2, 7, 6, 9, 5, 1, 4, 3, 8};
  do {
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < n; k++) {
        board[i][k] = arr[i * n + k];
      }
    }
    if (isOk()) {
      break;
    }
  } while (next_permutation(arr, arr + (n * n)));
  cout << media << "\n";
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < n; k++) {
      cout << board[i][k] << " ";
    }
    cout << "\n";
  }
  return 0;
}
