#include <bits/stdc++.h>
using namespace std;
const int N = 5;
bool tt, v[N * N];
int n, m, sum, s1, s2, a[N * N];
int ans[N][N], sx[N], sy[N];
int num1, num2, now1, now2;
void write() {
  printf("%d\n", sum);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) printf("%d ", ans[i][j]);
    printf("\n");
  }
}
inline bool cmp(int x, int y) { return x > y; }
void dfs(int x, int y) {
  if (x == n + 1) {
    write();
    tt = true;
    return;
  }
  for (int i = 1; i <= m; ++i)
    if (!v[i]) {
      ans[x][y] = a[i];
      sx[x] += a[i];
      sy[y] += a[i];
      if (x == y) s1 += a[i];
      if (x + y == n + 1) s2 += a[i];
      v[i] = true;
      now1 = 0;
      now2 = 0;
      num1 = 0;
      num2 = 0;
      for (int j = 1; j <= m; ++j) {
        if (!v[j]) {
          if (num1 < n - y) now1 += a[j], ++num1;
          if (num2 < n - x) now2 += a[j], ++num2;
        }
        if (num1 == n - y && num2 == n - x) break;
      }
      if (sx[x] + now1 < sum) {
        sx[x] -= a[i];
        sy[y] -= a[i];
        if (x == y) s1 -= a[i];
        if (x + y == n + 1) s2 -= a[i];
        v[i] = false;
        continue;
      }
      if (sy[y] + now2 < sum) {
        sx[x] -= a[i];
        sy[y] -= a[i];
        if (x == y) s1 -= a[i];
        if (x + y == n + 1) s2 -= a[i];
        v[i] = false;
        continue;
      }
      if (x == y)
        if (s1 + now1 < sum) {
          sx[x] -= a[i];
          sy[y] -= a[i];
          if (x == y) s1 -= a[i];
          if (x + y == n + 1) s2 -= a[i];
          v[i] = false;
          continue;
        }
      if (x + y == n + 1)
        if (s2 + now2 < sum) {
          sx[x] -= a[i];
          sy[y] -= a[i];
          if (x == y) s1 -= a[i];
          if (x + y == n + 1) s2 -= a[i];
          v[i] = false;
          continue;
        }
      now1 = 0;
      now2 = 0;
      num1 = 0;
      num2 = 0;
      for (int j = m; j; --j) {
        if (!v[j]) {
          if (num1 < n - y) now1 += a[j], ++num1;
          if (num2 < n - x) now2 += a[j], ++num2;
        }
        if (num1 == n - y && num2 == n - x) break;
      }
      if (sx[x] + now1 > sum) {
        sx[x] -= a[i];
        sy[y] -= a[i];
        if (x == y) s1 -= a[i];
        if (x + y == n + 1) s2 -= a[i];
        v[i] = false;
        continue;
      }
      if (sy[y] + now2 > sum) {
        sx[x] -= a[i];
        sy[y] -= a[i];
        if (x == y) s1 -= a[i];
        if (x + y == n + 1) s2 -= a[i];
        v[i] = false;
        continue;
      }
      if (x == y)
        if (s1 + now1 > sum) {
          sx[x] -= a[i];
          sy[y] -= a[i];
          if (x == y) s1 -= a[i];
          if (x + y == n + 1) s2 -= a[i];
          v[i] = false;
          continue;
        }
      if (x + y == n + 1)
        if (s2 + now2 > sum) {
          sx[x] -= a[i];
          sy[y] -= a[i];
          if (x == y) s1 -= a[i];
          if (x + y == n + 1) s2 -= a[i];
          v[i] = false;
          continue;
        }
      if (y == n)
        dfs(x + 1, 1);
      else
        dfs(x, y + 1);
      if (tt) return;
      sx[x] -= a[i];
      sy[y] -= a[i];
      if (x == y) s1 -= a[i];
      if (x + y == n + 1) s2 -= a[i];
      v[i] = false;
    }
}
int main() {
  scanf("%d", &n);
  m = n * n;
  for (int i = 1; i <= m; ++i) scanf("%d", a + i), sum += a[i];
  sum = sum / n;
  tt = false;
  sort(a + 1, a + m + 1, cmp);
  dfs(1, 1);
}
