#include <bits/stdc++.h>
using namespace std;
template <class T>
int popcount(T n);
template <>
int popcount(unsigned int n) {
  return n ? __builtin_popcount(n) : 0;
}
template <>
int popcount(int n) {
  return n ? __builtin_popcount(n) : 0;
}
template <>
int popcount(unsigned long long n) {
  return n ? __builtin_popcountll(n) : 0;
}
template <>
int popcount(long long n) {
  return n ? __builtin_popcountll(n) : 0;
}
template <class T>
void max_swap(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void min_swap(T& a, const T& b) {
  a = min(a, b);
}
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool valid_pos(int x, int y, int w, int h) {
  return 0 <= x && x < w && 0 <= y && y < h;
}
template <class T>
void print(T a, int n, int br = 1, const string& deli = ", ") {
  cout << "{ ";
  for (int i = 0; i < n; ++i) {
    cout << a[i];
    if (i + 1 != n) cout << deli;
  }
  cout << " }";
  while (br--) cout << endl;
}
template <class T>
void print(const vector<T>& v, int br = 1, const string& deli = ", ") {
  print(v, v.size(), br, deli);
}
int n, a[33];
int x[] = {0};
int y[] = {0, 1, 2, 3, 0, 2, 1, 3, 0, 3, 1, 2};
int z[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 3, 6,
           1, 4, 7, 2, 5, 8, 0, 4, 8, 2, 4, 6};
int* w[] = {x, y, z};
int cs(int k) {
  int res = 0;
  for (int i = 0; i < n; ++i) res += a[w[n - 1][k * n + i]];
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n * n; ++i) cin >> a[i];
  int s;
  sort(a, a + n * n);
  do {
    bool ok = true;
    s = cs(0);
    for (int i = 1; i < 2 * n + 2 && ok; ++i)
      if (s != cs(i)) ok = false;
    if (ok) break;
  } while (next_permutation(a, a + n * n));
  cout << s << endl;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      printf("%d%c", a[i * n + j], j + 1 == n ? '\n' : ' ');
}
