#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecI = vector<int>;
using vec2I = vector<vecI>;
using vec3I = vector<vec2I>;
ll mod{(ll)1e9 + 7};
double pi = 2 * acos(0.0);
void solve() {
  int n;
  cin >> n;
  vec2I vec(n, vecI(n));
  for (auto &ve : vec) {
    for (auto &v : ve) cin >> v;
  }
  if (n == 1) {
    cout << 1;
    return;
  }
  map<ll, int> mp;
  for (int i{}; i < n; i++) {
    ll sum{};
    for (int j{}; j < n; j++) {
      sum += vec[i][j];
    }
    mp[sum]++;
  }
  for (int i{}; i < n; i++) {
    ll sum{};
    for (int j{}; j < n; j++) {
      sum += vec[j][i];
    }
    mp[sum]++;
  }
  if ((int)mp.size() == 2) {
    vector<pair<ll, int>> ans;
    for (auto it{mp.begin()}; it != mp.end(); it++) {
      ans.push_back(*it);
    }
    if (ans[0].first > ans[1].first) {
      if (ans[1].second == 2) {
        ll sum1{}, sum2{};
        for (int i{}; i < n; i++) {
          if (vec[i][i] == 0)
            sum1 += ans[0].first - ans[1].first;
          else
            sum1 += vec[i][i];
          if (vec[i][n - i - 1] == 0)
            sum2 += ans[0].first - ans[1].first;
          else
            sum2 += vec[i][n - i - 1];
        }
        if (sum1 == sum2 && sum1 == ans[0].first)
          cout << ans[0].first - ans[1].first;
        else
          cout << -1;
      } else
        cout << -1;
    } else {
      if (ans[0].second == 2) {
        ll sum1{}, sum2{};
        for (int i{}; i < n; i++) {
          if (vec[i][i] == 0)
            sum1 += ans[1].first - ans[0].first;
          else
            sum1 += vec[i][i];
          if (vec[i][n - i - 1] == 0)
            sum2 += ans[1].first - ans[0].first;
          else
            sum2 += vec[i][n - i - 1];
        }
        if (sum1 == sum2 && sum1 == ans[1].first)
          cout << ans[1].first - ans[0].first;
        else
          cout << -1;
      } else
        cout << -1;
    }
  } else
    cout << -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
