#include <bits/stdc++.h>
using namespace std;
struct IO {
} io;
IO &operator>>(IO &io, int &n) {
  scanf("%d", &n);
  return io;
}
IO &operator>>(IO &io, unsigned int &n) {
  scanf("%u", &n);
  return io;
}
IO &operator>>(IO &io, long long &n) {
  scanf("%lld", &n);
  return io;
}
IO &operator>>(IO &io, unsigned long long &n) {
  scanf("%llu", &n);
  return io;
}
IO &operator>>(IO &io, double &n) {
  scanf("%lf", &n);
  return io;
}
IO &operator>>(IO &io, long double &n) {
  scanf("%Lf", &n);
  return io;
}
IO &operator>>(IO &io, char *c) {
  scanf("%s", c);
  return io;
}
IO &operator>>(IO &io, string &s) {
  char c;
  s.clear();
  while (isspace(c = getc(stdin))) {
    if (c == -1) return io;
  }
  do {
    s.push_back(c);
  } while (!isspace(c = getc(stdin)));
  if (c != -1) ungetc(c, stdin);
  return io;
}
IO &operator<<(IO &io, const int &n) {
  printf("%d", n);
  return io;
}
IO &operator<<(IO &io, const unsigned int &n) {
  printf("%u", n);
  return io;
}
IO &operator<<(IO &io, const long long &n) {
  printf("%lld", n);
  return io;
}
IO &operator<<(IO &io, const unsigned long long &n) {
  printf("%llu", n);
  return io;
}
IO &operator<<(IO &io, const double &n) {
  printf("%lf", n);
  return io;
}
IO &operator<<(IO &io, const long double &n) {
  printf("%Lf", n);
  return io;
}
IO &operator<<(IO &io, const char c[]) {
  printf("%s", c);
  return io;
}
IO &operator<<(IO &io, const string &s) {
  for (int i = 0; i < (int)(s.size()); ++i) putc(s[i], stdout);
}
int n;
int a[9], p[9];
int s = 0;
bool hantei() {
  for (int i = 0; i < (int)(n); ++i) {
    int r = 0;
    for (int j = 0; j < (int)(n); ++j) {
      r += a[i * n + j];
    }
    if (r != s) return false;
  }
  for (int j = 0; j < (int)(n); ++j) {
    int r = 0;
    for (int i = 0; i < (int)(n); ++i) {
      r += a[i * n + j];
    }
    if (r != s) return false;
  }
  int r = 0;
  for (int i = 0; i < (int)(n); ++i) {
    r += a[i * n + i];
  }
  if (r != s) return false;
  r = 0;
  for (int i = 0; i < (int)(n); ++i) {
    r += a[i * n + n - 1 - i];
  }
  if (r != s) return false;
  for (int i = 0; i < (int)(n); ++i) {
    for (int j = 0; j < (int)(n); ++j) {
      cout << a[i * n + j];
      if (j < n - 1) cout << " ";
    }
    cout << "\n";
  }
  return true;
}
int main() {
  cin >> n;
  for (int i = 0; i < (int)(n * n); ++i) {
    cin >> a[i];
    p[i] = i;
    s += a[i];
  }
  sort(a, a + n * n);
  s /= n;
  cout << s << "\n";
  do {
    if (hantei()) {
      return 0;
    }
  } while (next_permutation(a, a + n * n));
  return 0;
}
