#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<pair<int, int>, vector<pair<int, int>>,
                       greater<pair<int, int>>>
    rpqpi;
multiset<int> b;
vector<vector<int>> w(4, vector<int>(4));
long long sum = 0;
bool fill(int step) {
  bool done = false;
  if (step == 17) {
    long long a;
    long long c;
    a = w[2][0];
    a += w[2][1];
    a += w[2][2];
    a += w[2][3];
    c = w[3][0];
    c += w[3][1];
    c += w[3][2];
    c += w[3][3];
    if (a == sum && c == sum) {
      done = true;
      for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
          cout << w[i][j] << " ";
        }
        cout << '\n';
      }
    }
  } else {
    if (step == 1 || step == 2 || step == 3 || step == 5 || step == 6 ||
        step == 8 || step == 10 || step == 13) {
      int a = *b.begin();
      int c;
      b.erase(b.lower_bound(a));
      if (step == 1)
        w[0][0] = a;
      else if (step == 2)
        w[1][1] = a;
      else if (step == 3)
        w[3][3] = a;
      else if (step == 5)
        w[1][3] = a;
      else if (step == 6)
        w[1][2] = a;
      else if (step == 8)
        w[0][3] = a;
      else if (step == 10)
        w[2][1] = a;
      else if (step == 13)
        w[0][1] = a;
      done = fill(step + 1);
      while (!done && b.upper_bound(a) != b.end()) {
        c = *b.upper_bound(a);
        b.erase(b.lower_bound(c));
        b.insert(a);
        a = c;
        if (step == 1)
          w[0][0] = a;
        else if (step == 2)
          w[1][1] = a;
        else if (step == 3)
          w[3][3] = a;
        else if (step == 5)
          w[1][3] = a;
        else if (step == 6)
          w[1][2] = a;
        else if (step == 8)
          w[0][3] = a;
        else if (step == 10)
          w[2][1] = a;
        else if (step == 13)
          w[0][1] = a;
        done = fill(step + 1);
      }
      b.insert(a);
    } else if (step == 4) {
      long long q = w[0][0];
      q += w[3][3];
      q += w[1][1];
      if (b.find(sum - q) != b.end()) {
        w[2][2] = sum - q;
        b.erase(b.lower_bound(w[2][2]));
        done = fill(5);
        b.insert(w[2][2]);
      }
    } else if (step == 7) {
      long long q = w[1][1];
      q += w[1][2];
      q += w[1][3];
      if (b.find(sum - q) != b.end()) {
        w[1][0] = sum - q;
        b.erase(b.lower_bound(w[1][0]));
        done = fill(8);
        b.insert(w[1][0]);
      }
    } else if (step == 9) {
      long long q = w[0][3];
      q += w[1][3];
      q += w[3][3];
      if (b.find(sum - q) != b.end()) {
        w[2][3] = sum - q;
        b.erase(b.lower_bound(w[2][3]));
        done = fill(10);
        b.insert(w[2][3]);
      }
    } else if (step == 11) {
      long long q = w[0][3];
      q += w[1][2];
      q += w[2][1];
      if (b.find(sum - q) != b.end()) {
        w[3][0] = sum - q;
        b.erase(b.lower_bound(w[3][0]));
        done = fill(12);
        b.insert(w[3][0]);
      }
    } else if (step == 12) {
      long long q = w[0][0];
      q += w[1][0];
      q += w[3][0];
      if (b.find(sum - q) != b.end()) {
        w[2][0] = sum - q;
        b.erase(b.lower_bound(w[2][0]));
        done = fill(13);
        b.insert(w[2][0]);
      }
    } else if (step == 14) {
      long long q = w[0][0];
      q += w[0][1];
      q += w[0][3];
      if (b.find(sum - q) != b.end()) {
        w[0][2] = sum - q;
        b.erase(b.lower_bound(w[0][2]));
        done = fill(15);
        b.insert(w[0][2]);
      }
    } else if (step == 15) {
      long long q = w[0][1];
      q += w[1][1];
      q += w[2][1];
      if (b.find(sum - q) != b.end()) {
        w[3][1] = sum - q;
        b.erase(b.lower_bound(w[3][1]));
        done = fill(16);
        b.insert(w[3][1]);
      }
    } else if (step == 16) {
      long long q = w[0][2];
      q += w[1][2];
      q += w[2][2];
      if (b.find(sum - q) != b.end()) {
        w[3][2] = sum - q;
        b.erase(b.lower_bound(w[3][2]));
        done = fill(17);
        b.insert(w[3][2]);
      }
    }
  }
  return done;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  if (n == 1) {
    int a;
    cin >> a;
    cout << a << '\n';
    cout << a << '\n';
  } else if (n == 2) {
    int a;
    cin >> a;
    cout << a * 2 << '\n';
    cout << a << " " << a << '\n';
    cout << a << " " << a << '\n';
  } else if (n == 3) {
    vector<int> a(9);
    for (int i = 0; i < 9; ++i) {
      cin >> a[i];
      sum += a[i];
    }
    cout << sum / 3 << '\n';
    sort(a.begin(), a.end());
    do {
      if (a[0] + a[1] + a[2] == a[3] + a[4] + a[5] &&
          a[0] + a[1] + a[2] == a[6] + a[7] + a[8] &&
          a[0] + a[1] + a[2] == a[0] + a[3] + a[6] &&
          a[0] + a[1] + a[2] == a[1] + a[4] + a[7] &&
          a[0] + a[1] + a[2] == a[2] + a[5] + a[8] &&
          a[0] + a[1] + a[2] == a[0] + a[4] + a[8] &&
          a[0] + a[1] + a[2] == a[2] + a[4] + a[6]) {
        cout << a[0] << " " << a[1] << " " << a[2] << '\n';
        cout << a[3] << " " << a[4] << " " << a[5] << '\n';
        cout << a[6] << " " << a[7] << " " << a[8] << '\n';
        return 0;
      }
    } while ((next_permutation(a.begin(), a.end())));
  } else {
    int a;
    for (int i = 0; i < 16; ++i) {
      cin >> a;
      b.insert(a);
      sum += a;
    }
    sum /= 4;
    cout << sum << '\n';
    fill(1);
  }
  return 0;
}
