#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> a;
bool found;
int b[5][5], sum, cols[5];
void backTrack(int x, int y, int sumRow, int sumDia1, int sumDia2) {
  if (x == n) {
    if (sumDia1 != sum || sumDia2 != sum) return;
    for (int i = 0; i < n; i++)
      if (cols[i] != sum) return;
    found = true;
    return;
  }
  for (typeof(a.begin()) it = a.begin(); it != a.end(); it++)
    if (it->second > 0) {
      it->second--;
      sumRow += it->first;
      if (x == y) sumDia1 += it->first;
      if (x + y == n - 1) sumDia2 += it->first;
      cols[y] += it->first;
      int xx = x, yy = y + 1;
      if (yy == n) yy = 0, xx++;
      b[x][y] = it->first;
      if (yy == 0) {
        if (sumRow == sum) backTrack(xx, yy, 0, sumDia1, sumDia2);
      } else
        backTrack(xx, yy, sumRow, sumDia1, sumDia2);
      it->second++;
      sumRow -= it->first;
      if (x == y) sumDia1 -= it->first;
      if (x + y == n - 1) sumDia2 -= it->first;
      cols[y] -= it->first;
      if (found) return;
    }
}
int main() {
  sum = 0;
  scanf("%d", &n);
  for (int i = 0, val; i < n * n; i++) {
    scanf("%d", &val);
    a[val]++;
    sum += val;
  }
  sum /= n;
  found = false;
  memset(cols, 0, sizeof(cols));
  backTrack(0, 0, 0, 0, 0);
  printf("%d\n", sum);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j) putchar(' ');
      printf("%d", b[i][j]);
    }
    putchar('\n');
  }
  return 0;
}
