#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int sum, tot, rec[5], n, N, val[20], cnt[20], mat[5][5], a[20];
bool g[20][20];
void init(int dep) {
  if (dep == n) {
    if (tot == sum)
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) g[rec[i]][rec[j]] = 1;
    return;
  }
  for (int i = !dep ? 0 : rec[dep - 1]; i < N; ++i)
    if (cnt[i]) {
      rec[dep] = i;
      --cnt[i];
      tot += val[i];
      init(dep + 1);
      tot -= val[i];
      ++cnt[i];
    }
}
bool dfs(int dep) {
  if (!dep) {
    for (int i = 0; i < N; ++i)
      if (cnt[i]) {
        int v = sum - val[i] - val[mat[1][1]] - val[mat[2][2]];
        if (mp.find(v) == mp.end()) continue;
        int j = mp[v];
        --cnt[i], --cnt[j];
        if (cnt[i] >= 0 && cnt[j] >= 0) {
          mat[0][0] = i, mat[3][3] = j;
          if (dfs(dep + 1)) return 1;
        }
        ++cnt[i], ++cnt[j];
      }
  } else if (dep == 1) {
    for (int i = 0; i < N; ++i)
      if (cnt[i] && g[i][mat[0][0]]) {
        int v = sum - val[i] - val[mat[1][1]] - val[mat[1][2]];
        if (mp.find(v) == mp.end()) continue;
        int j = mp[v];
        --cnt[i], --cnt[j];
        if (cnt[j] >= 0 && g[j][mat[3][3]]) {
          mat[1][0] = i, mat[1][3] = j;
          if (dfs(dep + 1)) return 1;
        }
        ++cnt[i], ++cnt[j];
      }
  } else if (dep == 2) {
    for (int i = 0; i < N; ++i)
      if (cnt[i]) {
        int u = sum - val[i] - val[mat[0][0]] - val[mat[1][0]],
            v = sum - val[i] - val[mat[2][1]] - val[mat[2][2]],
            w = sum - u - val[mat[2][1]] - val[mat[1][2]];
        if (v + w + val[mat[1][3]] + val[mat[3][3]] != sum ||
            mp.find(u) == mp.end() || mp.find(v) == mp.end() ||
            mp.find(w) == mp.end())
          continue;
        int j = mp[u], k = mp[v], l = mp[w];
        --cnt[i], --cnt[j], --cnt[k], --cnt[l];
        if (cnt[j] >= 0 && cnt[k] >= 0 && cnt[l] >= 0) {
          mat[2][0] = i, mat[3][0] = j, mat[2][3] = k, mat[0][3] = l;
          if (dfs(dep + 1)) return 1;
        }
        ++cnt[i], ++cnt[j], ++cnt[k], ++cnt[l];
      }
  } else {
    for (int i = 0; i < N; ++i)
      if (cnt[i]) {
        int u = sum - val[i] - val[mat[0][0]] - val[mat[0][3]],
            v = sum - val[i] - val[mat[1][1]] - val[mat[2][1]],
            w = sum - v - val[mat[3][0]] - val[mat[3][3]];
        if (u + w + val[mat[1][2]] + val[mat[2][2]] != sum ||
            mp.find(u) == mp.end() || mp.find(v) == mp.end() ||
            mp.find(w) == mp.end())
          continue;
        int j = mp[u], k = mp[v], l = mp[w];
        --cnt[i], --cnt[j], --cnt[k], --cnt[l];
        if (cnt[j] >= 0 && cnt[k] >= 0 && cnt[l] >= 0) {
          mat[0][1] = i, mat[0][2] = j, mat[3][1] = k, mat[3][2] = l;
          for (int r = 0; r < n; ++r)
            for (int c = 0; c < n; ++c)
              printf("%d%c", val[mat[r][c]], c + 1 == n ? '\n' : ' ');
          return 1;
        }
        ++cnt[i], ++cnt[j], ++cnt[k], ++cnt[l];
      }
  }
  return 0;
}
bool small(int x, int y) {
  if (x == n - 1 && y == n - 1) {
    int s1 = 0, s2 = 0;
    for (int i = 0; i < n - 1; ++i)
      s1 += val[mat[i][n - 1]], s2 += val[mat[n - 1][i]];
    if (s1 != s2 || mp.find(sum - s1) == mp.end() || !cnt[mp[sum - s1]])
      return 0;
    mat[x][y] = mp[sum - s1];
    s1 = s2 = 0;
    for (int i = 0; i < n; ++i)
      s1 += val[mat[i][i]], s2 += val[mat[i][n - 1 - i]];
    if (s1 == sum && s2 == sum) {
      for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
          printf("%d%c", val[mat[i][j]], j + 1 == n ? '\n' : ' ');
      return 1;
    }
  } else if (y == n - 1) {
    int v = sum;
    for (int i = 0; i < n - 1; ++i) v -= val[mat[x][i]];
    if (mp.find(v) == mp.end()) return 0;
    int i = mp[v];
    if (cnt[i]) {
      mat[x][y] = i;
      --cnt[i];
      if (small(x + 1, 0)) return 1;
      ++cnt[i];
    }
  } else if (x == n - 1) {
    int v = sum;
    for (int i = 0; i < n - 1; ++i) v -= val[mat[i][y]];
    if (mp.find(v) == mp.end()) return 0;
    int i = mp[v];
    if (cnt[i]) {
      mat[x][y] = i;
      --cnt[i];
      if (small(x, y + 1)) return 1;
      ++cnt[i];
    }
  } else {
    for (int i = 0; i < N; ++i)
      if (cnt[i]) {
        mat[x][y] = i;
        --cnt[i];
        if (small(x, y + 1)) return 1;
        ++cnt[i];
      }
  }
  return 0;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    mp.clear();
    memset(g, 0, sizeof(g));
    sum = tot = 0;
    for (int i = 0; i < n * n; ++i) {
      scanf("%d", &a[i]);
      sum += a[i];
    }
    sum /= n;
    printf("%d\n", sum);
    sort(a, a + n * n);
    for (int i = 0, j = 0; i < n * n; i = j) {
      for (; j < n * n && a[j] == a[i]; ++j)
        ;
      mp[a[i]] = N, val[N] = a[i], cnt[N++] = j - i;
    }
    if (n < 4) {
      small(0, 0);
      continue;
    }
    init(0);
    bool found = 0;
    for (int i = 0; !found && i < N; ++i)
      if (cnt[i]) {
        --cnt[i];
        mat[1][1] = i;
        for (int j = i; !found && j < N; ++j)
          if (cnt[j] && g[i][j]) {
            --cnt[j];
            mat[2][2] = j;
            for (int k = i; !found && k < N; ++k)
              if (cnt[k] && g[i][k] && g[j][k]) {
                --cnt[k];
                mat[1][2] = k;
                for (int l = i; !found && l < N; ++l)
                  if (cnt[l] && g[k][l] && g[i][l] && g[j][l]) {
                    --cnt[l];
                    mat[2][1] = l;
                    if (dfs(0)) found = 1;
                    ++cnt[l];
                  }
                ++cnt[k];
              }
            ++cnt[j];
          }
        ++cnt[i];
      }
  }
  return 0;
}
