#include <bits/stdc++.h>
using namespace std;
struct s {
  long long x, y;
};
bool cmp(s a, s b) { return a.x < b.x; }
long long gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long mod(long a, long b) { return (a % b + b) % b; }
int main() {
  int n;
  cin >> n;
  int myj, myk;
  vector<long long> sumr;
  vector<long long> sumc(n, 0);
  vector<long long> sumd(3, 0);
  int num;
  for (int k = 0; k < n; k++) {
    unsigned long long r = 0;
    for (int j = 0; j < n; j++) {
      cin >> num;
      r += num;
      r = r % 1000000000000000000;
      if (num == 0) {
        myj = k;
        myk = j;
      }
      if (k == j) {
        sumd[0] += num;
        sumd[0] = sumd[0] % 1000000000000000000;
      }
      if (j + k == n - 1) {
        sumd[1] += num;
        sumd[1] = sumd[1] % 1000000000000000000;
      }
      sumc[j] += num;
      sumc[j] = sumc[j] % 1000000000000000000;
    }
    sumr.push_back(r);
  }
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  int idx = 0;
  ;
  if (myj == 0) idx++;
  long long hnzodo = abs((sumr[idx] - sumr[myj]));
  sumr[myj] += hnzodo;
  sumc[myk] += hnzodo;
  if (myj == myk) sumd[0] += hnzodo;
  if (myj + myk == n - 1) sumd[1] += hnzodo;
  bool ck = 0;
  for (int i = 0; i < (int)(n); ++i) {
    if (sumr[0] != sumc[i]) ck = 1;
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (sumr[0] != sumr[i]) ck = 1;
  }
  for (int i = 0; i < (int)(2); ++i) {
    if (sumr[0] != sumd[i]) ck = 1;
  }
  if (ck || hnzodo == 0 || hnzodo < 0)
    cout << -1 << endl;
  else
    cout << hnzodo << endl;
  return 0;
}
