#include <bits/stdc++.h>
using namespace std;
int v[20];
long long int S;
int n;
bool viz[20];
int A[20][20];
map<int, int> mp;
bool solution_found;
void add_element(int element, int no_added) {
  mp[element]--;
  int j_index = 1, i_index = 1;
  while (no_added >= (n - 1)) {
    i_index++;
    no_added -= (n - 1);
  }
  j_index = 1 + no_added;
  A[i_index][j_index] = element;
  A[0][j_index] += element;
  A[i_index][0] += element;
}
void remove_element(int element, int no_added) {
  mp[element]++;
  int j_index = 1, i_index = 1;
  while (no_added >= (n - 1)) {
    i_index++;
    no_added -= (n - 1);
  }
  j_index = 1 + no_added;
  if (j_index > 1)
    j_index--;
  else {
    i_index--;
    j_index = n - 1;
  }
  A[i_index][j_index] = 0;
  A[0][j_index] -= element;
  A[i_index][0] -= element;
}
void reset_round(int updates) {
  while (updates > n - 1) {
    int j_index = updates - (n - 1);
    A[0][j_index] -= A[n][j_index];
    A[n][0] -= A[n][j_index];
    mp[A[n][j_index]]++;
    A[n][j_index] = 0;
    updates--;
  }
  while (updates > 0) {
    A[updates][0] -= A[updates][n];
    A[0][n] -= A[updates][n];
    mp[A[updates][n]]++;
    A[updates][n] = 0;
    updates--;
  }
}
long long int second_diag_sum() {
  long long int s = 0;
  for (int i = 1; i <= n; i++) {
    s += A[i][n - i + 1];
  }
  return s;
}
long long int main_diag_sum() {
  long long int s = 0;
  for (int i = 1; i <= n; i++) {
    s += A[i][i];
  }
  return s;
}
void bkt(int no_added) {
  if (!solution_found) {
    if (no_added == (n - 1) * (n - 1)) {
      int updates = 0;
      bool stop = false;
      for (int i = 1; i <= n - 1 && (!stop); i++) {
        long long int candidate = S - A[i][0];
        if (mp[candidate] > 0) {
          updates++;
          A[i][n] = candidate;
          mp[candidate]--;
          A[0][n] += candidate;
          A[i][0] += candidate;
        } else {
          stop = true;
        }
      }
      for (int j = 1; j <= n && (!stop); j++) {
        long long int candidate = S - A[0][j];
        if (mp[candidate] > 0) {
          updates++;
          A[n][j] = candidate;
          mp[candidate]--;
          A[n][0] += candidate;
          A[0][j] += candidate;
        } else {
          stop = true;
        }
      }
      if (stop)
        reset_round(updates);
      else if (main_diag_sum() != S) {
        stop = true;
        reset_round(updates);
      } else if (second_diag_sum() != S) {
        stop = true;
        reset_round(updates);
      }
      if (!stop) {
        for (int i = 1; i <= n; i++) {
          for (int j = 1; j <= n; j++) {
            cout << A[i][j] << " ";
          }
          cout << '\n';
        }
        solution_found = true;
      }
    } else {
      for (int i = 1; i <= n * n; i++) {
        if (!viz[i]) {
          viz[i] = true;
          add_element(v[i], no_added);
          no_added++;
          bkt(no_added);
          remove_element(v[i], no_added);
          no_added--;
          viz[i] = false;
        }
      }
    }
  }
}
int main() {
  ifstream f("input.in");
  cin >> n;
  S = 0;
  for (int i = 1; i <= n * n; i++) {
    cin >> v[i];
    S += v[i];
    mp[v[i]]++;
  }
  S /= n;
  cout << S << '\n';
  bkt(0);
  f.close();
  return 0;
}
