#include <bits/stdc++.h>
using namespace std;
int n, k, need;
int a[20], b[20], cnt[20];
int val[20][20];
vector<int> lst[66000];
inline bool find(int sum, int mask) {
  int pos = lower_bound(b, b + k, sum) - b;
  if (pos >= 0 && pos < k && b[pos] == sum && cnt[pos] > 0) {
    return true;
  }
  return false;
}
inline bool check(int x, int mask) {
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += val[x][i];
  }
  if (sum != need) {
    return false;
  }
  if (x == n - 2) {
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
      sum += val[i][i];
    }
    if (!find(need - sum, mask)) {
      return false;
    }
    sum = 0;
    for (int i = 0; i < n - 1; i++) {
      sum += val[i][n - i - 1];
    }
    if (!find(need - sum, mask)) {
      return false;
    }
    for (int i = 0; i < n; i++) {
      sum = 0;
      for (int j = 0; j < n - 1; j++) {
        sum += val[j][i];
      }
      if (!find(need - sum, mask)) {
        return false;
      }
    }
  }
  return true;
}
void gen(int x, int y, int mask) {
  if (x >= n) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += val[i][i];
    }
    if (sum != need) {
      return;
    }
    sum = 0;
    for (int i = 0; i < n; i++) {
      sum += val[i][n - i - 1];
    }
    if (sum != need) {
      return;
    }
    printf("%d\n", need);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j > 0) {
          printf(" ");
        }
        printf("%d", val[i][j]);
      }
      printf("\n");
    }
    exit(0);
  }
  if (y == n - 1) {
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
      sum += val[x][i];
    }
    sum = need - sum;
    if (x == n - 1) {
      int ssum = 0;
      for (int i = 0; i < n - 1; i++) {
        ssum += val[i][i];
      }
      if (need - ssum != sum) {
        return;
      }
    }
    int pos = lower_bound(b, b + k, sum) - b;
    if (pos >= 0 && pos < k && b[pos] == sum && cnt[pos] > 0) {
      cnt[pos]--;
      if (cnt[pos] == 0) {
        mask ^= (1 << pos);
      }
      val[x][y] = sum;
      gen(x + 1, 0, mask);
      if (cnt[pos] == 0) {
        mask |= (1 << pos);
      }
      cnt[pos]++;
    }
    return;
  }
  if (x == n - 1) {
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
      sum += val[i][y];
    }
    sum = need - sum;
    if (y == 0) {
      int ssum = 0;
      for (int i = 0; i < n - 1; i++) {
        ssum += val[i][n - i - 1];
      }
      if (need - ssum != sum) {
        return;
      }
    }
    int pos = lower_bound(b, b + k, sum) - b;
    if (pos >= 0 && pos < k && b[pos] == sum && cnt[pos] > 0) {
      cnt[pos]--;
      if (cnt[pos] == 0) {
        mask ^= (1 << pos);
      }
      val[x][y] = sum;
      gen(x, y + 1, mask);
      if (cnt[pos] == 0) {
        mask |= (1 << pos);
      }
      cnt[pos]++;
    }
    return;
  }
  for (int i = 0; i < (int)lst[mask].size(); i++) {
    val[x][y] = b[lst[mask][i]];
    cnt[lst[mask][i]]--;
    int nmask = mask;
    if (cnt[lst[mask][i]] == 0) {
      nmask ^= (1 << lst[mask][i]);
    }
    gen(x, y + 1, nmask);
    cnt[lst[mask][i]]++;
  }
}
int main() {
  scanf("%d", &n);
  need = 0;
  for (int i = 0; i < n * n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
    need += a[i];
  }
  need /= n;
  sort(b, b + n * n);
  k = unique(b, b + n * n) - b;
  for (int i = 0; i < n * n; i++) {
    for (int j = 0; j < k; j++) {
      if (b[j] == a[i]) {
        cnt[j]++;
        break;
      }
    }
  }
  int all = (1 << k);
  for (int i = 0; i < all; i++) {
    for (int j = 0; j < k; j++) {
      if ((i & (1 << j)) != 0) {
        lst[i].push_back(j);
      }
    }
    random_shuffle(lst[i].begin(), lst[i].end());
  }
  gen(0, 0, all - 1);
  return 0;
}
