#include <bits/stdc++.h>
using namespace std;
template <typename T>
T POW(T b, T p) {
  T r = 1;
  while (p) {
    if (p & 1) r = (r * b);
    b = (b * b);
    p >>= 1;
  }
  return r;
}
template <typename T>
T BigMod(T b, T p, T m) {
  T r = 1;
  while (p) {
    if (p & 1) r = (r * b) % m;
    b = (b * b) % m;
    p >>= 1;
  }
  return r;
}
long long mat[501][501];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) cin >> mat[i][j];
  if (n == 1) {
    puts("1\n");
    return 0;
  }
  int row = -1, col = -1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (mat[i][j] == 0) row = i, col = j;
  set<long long> s, ss;
  for (int i = 0; i < n; ++i) {
    long long sum = 0;
    for (int j = 0; j < n; ++j) {
      sum += mat[i][j];
    }
    if (i != row)
      s.insert(sum);
    else
      ss.insert(sum);
  }
  for (int i = 0; i < n; ++i) {
    long long sum = 0;
    for (int j = 0; j < n; ++j) {
      sum += mat[j][i];
    }
    if (i != col)
      s.insert(sum);
    else
      ss.insert(sum);
  }
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += mat[i][i];
  }
  if (row != col)
    s.insert(sum);
  else
    ss.insert(sum);
  sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += mat[i][n - 1 - i];
  }
  if (row != (n - 1 - col))
    s.insert(sum);
  else
    ss.insert(sum);
  if (s.size() != 1) {
    puts("-1\n");
    return 0;
  } else if (ss.size() > 1) {
    puts("-1\n");
    return 0;
  } else if (ss.size()) {
    long long res = *s.begin() - *ss.begin();
    printf("%lld\n", res > 0 ? res : -1);
  } else
    puts("1\n");
}
