#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
  return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long INF64 = 1e18;
const long long INF32 = 1e9;
const long long MOD = 1e9 + 7;
const long double PI = acos(-1.0L);
const long double EPS = static_cast<long double>(1e-9);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  {
    long long n;
    cin >> n;
    if (n == 1) {
      cout << 1 << endl;
      return 0;
    }
    long long x0, y0, a[n][n];
    vector<long long> r(n, 0), c(n, 0);
    for (long long i = (0); i < (n); i++)
      for (long long j = (0); j < (n); j++) {
        cin >> a[i][j];
        if (a[i][j] == 0) x0 = i, y0 = j;
        r[i] += a[i][j], c[j] += a[i][j];
      }
    for (long long i = (0); i < (n); i++)
      if (i != x0) {
        a[x0][y0] = r[i] - r[x0], r[x0] += a[x0][y0], c[y0] += a[x0][y0];
        break;
      }
    for (long long i = (1); i < (n); i++)
      if (r[i] != r[0]) {
        cout << -1 << endl;
        return 0;
      }
    for (long long j = (1); j < (n); j++)
      if (c[j] != c[0]) {
        cout << -1 << endl;
        return 0;
      }
    long long d = 0;
    for (long long i = (0); i < (n); i++) d += a[i][i];
    if (d != r[0]) {
      cout << -1 << endl;
      return 0;
    }
    d = 0;
    for (long long i = (0); i < (n); i++) d += a[i][n - i - 1];
    if (d != r[0]) {
      cout << -1 << endl;
      return 0;
    }
    cout << (a[x0][y0] > 0 ? a[x0][y0] : -1) << endl;
  }
  return 0;
}
