#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  if (N == 1) {
    printf("1\n");
    return 0;
  }
  vector<vector<long long> > sq(N, vector<long long>(N));
  for (auto &x : sq)
    for (long long &y : x) scanf("%lld", &y);
  int zi = -1, zj = -1;
  for (int i = 0; i < N; i++)
    if (zi == -1)
      for (int j = 0; j < N; j++)
        if (sq[i][j] == 0) {
          zi = i;
          zj = j;
          break;
        }
  int R = (zi == 0) ? 1 : 0;
  long long sum = accumulate(sq[R].begin(), sq[R].end(), 0ll);
  long long sum2 = accumulate(sq[zi].begin(), sq[zi].end(), 0ll);
  if (sum2 >= sum) {
    printf("-1\n");
    return 0;
  }
  sq[zi][zj] = sum - sum2;
  for (int i = 0; i < N; i++)
    if (accumulate(sq[i].begin(), sq[i].end(), 0ll) != sum) {
      printf("-1\n");
      return 0;
    }
  for (int j = 0; j < N; j++) {
    long long s = 0;
    for (int i = 0; i < N; i++) s += sq[i][j];
    if (s != sum) {
      printf("-1\n");
      return 0;
    }
  }
  long long s = 0;
  for (int i = 0; i < N; i++) s += sq[i][i];
  if (s != sum) {
    printf("-1\n");
    return 0;
  }
  s = 0;
  for (int i = 0; i < N; i++) s += sq[i][N - i - 1];
  if (s != sum) {
    printf("-1\n");
    return 0;
  }
  printf("%lld\n", sq[zi][zj]);
  return 0;
}
