#include <bits/stdc++.h>
int a[4 * 4], d[4][4], n, s;
bool b[4 * 4];
void solve1() { printf("%d\n%d\n", a[0], a[0]); }
void solve2() {
  d[0][0] = a[3];
  for (int i = 0; i < (3); i++)
    for (int j = 0; j < (3); j++)
      for (int k = 0; k < (3); k++) {
        if (i != j && i != k && j != k) {
          d[0][1] = a[i];
          d[1][0] = a[j];
          d[1][1] = a[k];
          if (d[0][0] + d[1][1] == s && d[0][1] + d[1][0] == s &&
              d[0][0] + d[0][1] == s && d[1][0] + d[1][1] == s &&
              d[0][0] + d[1][0] == s && d[0][1] + d[1][1] == s)
            break;
        }
      }
  printf("%d\n%d %d\n%d %d\n", s, d[0][0], d[0][1], d[1][0], d[1][1]);
}
inline bool check3() {
  int ok = 0;
  for (int i = 0; i < (9); i++)
    if (!b[i] && s - d[0][0] - d[1][0] == a[i]) {
      b[i] = 1;
      d[2][0] = a[i];
      ok = 1;
      break;
    }
  if (!ok) return 0;
  ok = 0;
  for (int i = 0; i < (9); i++)
    if (!b[i] && s - d[0][0] - d[0][1] == a[i]) {
      b[i] = 1;
      d[0][2] = a[i];
      ok = 1;
      break;
    }
  if (!ok) return 0;
  ok = 0;
  for (int i = 0; i < (9); i++)
    if (!b[i] && s - d[0][2] - d[2][0] == a[i]) {
      b[i] = 1;
      d[1][1] = a[i];
      ok = 1;
      break;
    }
  if (!ok) return 0;
  ok = 0;
  for (int i = 0; i < (9); i++)
    if (!b[i] && s - d[0][0] - d[1][1] == a[i]) {
      b[i] = 1;
      d[2][2] = a[i];
      ok = 1;
      break;
    }
  if (!ok) return 0;
  ok = 0;
  for (int i = 0; i < (9); i++)
    if (!b[i] && s - d[0][2] - d[2][2] == a[i] &&
        s - d[1][0] - d[1][1] == a[i]) {
      b[i] = 1;
      d[1][2] = a[i];
      ok = 1;
      break;
    }
  if (!ok) return 0;
  ok = 1;
  for (int i = 0; i < (9); i++)
    if (!b[i] && s - d[0][1] - d[1][1] == a[i] &&
        s - d[2][0] - d[2][2] == a[i]) {
      d[2][1] = a[i];
      return 1;
    }
  return 0;
}
void solve3() {
  for (int i = 0; i < (9); i++)
    for (int j = 0; j < (9); j++)
      for (int k = 0; k < (9); k++)
        if (i != j && i != k && j != k) {
          d[1][0] = a[i];
          d[0][0] = a[j];
          d[0][1] = a[k];
          b[i] = b[j] = b[k] = 1;
          if (check3()) goto lb;
          for (int i = 0; i < (3); i++)
            for (int j = 0; j < (3); j++) d[i][j] = 0;
          for (int i = 0; i < (9); i++) b[i] = 0;
        }
lb:
  printf("%d\n", s);
  for (int i = 0; i < (3); i++) {
    for (int j = 0; j < (3); j++) printf("%d ", d[i][j]);
    puts("");
  }
}
void solve4() {}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n * n); i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  s /= n;
  if (n == 1) solve1();
  if (n == 2) solve2();
  if (n == 3) solve3();
  if (n == 4) solve4();
  return 0;
}
