#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  vector<vector<long long>> v;
  v.resize(n, vector<long long>(n));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) cin >> v[i][j];
  long long c = -1, r = -1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      if (v[i][j] == 0) {
        c = j, r = i;
        break;
      }
    }
  long long MAX = -1;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    sum = 0;
    for (int j = 0; j < n; ++j) {
      sum += v[i][j];
    }
    MAX = max(MAX, sum);
  }
  for (int j = 0; j < n; ++j) {
    sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += v[i][j];
    }
    MAX = max(MAX, sum);
  }
  sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += v[i][i];
  }
  MAX = max(MAX, sum);
  sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += v[i][n - 1 - i];
  }
  MAX = max(MAX, sum);
  sum = 0;
  for (int i = 0; i < n; ++i) sum += v[i][c];
  long long val = MAX - sum;
  if (val <= 0) {
    cout << -1 << endl;
    return 0;
  }
  v[r][c] = val;
  long long last_sum = val + sum;
  for (int i = 0; i < n; ++i) {
    sum = 0;
    for (int j = 0; j < n; ++j) {
      sum += v[i][j];
    }
    if (sum != last_sum) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int j = 0; j < n; ++j) {
    sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += v[i][j];
    }
    if (sum != last_sum) {
      cout << -1 << endl;
      return 0;
    }
  }
  sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += v[i][i];
  }
  if (sum != last_sum) {
    cout << -1 << endl;
    return 0;
  }
  sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += v[i][n - 1 - i];
  }
  if (sum != last_sum) {
    cout << -1 << endl;
    return 0;
  }
  cout << val << endl;
  return 0;
}
