#include <bits/stdc++.h>
long long int GCD(long long int n1, long long int n2) {
  while (n2 != 0) {
    unsigned r = n1 % n2;
    n1 = n2;
    n2 = r;
  }
  return n1;
}
int NOK(int n1, int n2) { return n1 * n2 / GCD(n1, n2); }
long long int C(long long int n, long long int k) {
  if (n < k) return 0;
  if (n == k) return 1;
  long long int divider = 1;
  long long int ans = 1;
  long long int i = n - k + 1;
  while (i < n + 1) {
    if (divider <= k && ans % divider == 0) {
      ans /= divider;
      ++divider;
    } else {
      ans *= i;
      ++i;
    }
  }
  while (divider <= k) {
    ans /= divider;
    ++divider;
  }
  return ans;
}
struct tree {
  int a, x;
};
bool sort1(tree a, tree b) { return a.x < b.x; }
bool sort2(tree a, tree b) { return a.x > b.x; }
bool sortByFirst(std::pair<int, int> a, std::pair<int, int> b) {
  return a.first < b.first;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  int ti, tj;
  auto q = new long long int*[n];
  for (int i = 0; i < n; ++i) q[i] = new long long int[n];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      std::cin >> q[i][j];
      if (q[i][j] == 0) {
        ti = i;
        tj = j;
      }
    }
  int exj = (tj == 0 ? tj + 1 : tj - 1);
  long long int exSum = 0;
  for (int i = 0; i < n; ++i) exSum += q[i][exj];
  long long int sum = exSum;
  for (int i = 0; i < n; ++i) sum -= q[i][tj];
  if (sum <= 0) {
    std::cout << -1;
    return 0;
  } else {
    q[ti][tj] = sum;
  }
  for (int i = 0; i < n; ++i) {
    long long int csum = 0;
    for (int j = 0; j < n; ++j) {
      csum += q[i][j];
    }
    if (csum != exSum) {
      std::cout << -1;
      return 0;
    }
  }
  for (int j = 0; j < n; ++j) {
    long long int csum = 0;
    for (int i = 0; i < n; ++i) {
      csum += q[i][j];
    }
    if (csum != exSum) {
      std::cout << -1;
      return 0;
    }
  }
  long long int dSum1 = 0, dSum2 = 0;
  for (int i = 0; i < n; ++i) {
    dSum1 += q[i][i];
    dSum2 += q[i][n - 1 - i];
  }
  if (dSum1 != exSum || dSum2 != exSum) {
    std::cout << -1;
    return 0;
  }
  std::cout << q[ti][tj];
  return 0;
}
