#include <bits/stdc++.h>
using namespace std;
int n;
long long int grid[505][505];
long long int l[505], r[505];
long long int dia1, dia2;
int ei = -1, ej = -1;
int sum;
int sum1;
int main() {
  scanf("%d", &n);
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%I64d", &grid[i][j]);
      if (grid[i][j] == 0) {
        ei = i;
        ej = j;
        continue;
      }
      if (i == j) dia1 += grid[i][j];
      if (i == n - j - 1) dia2 += grid[i][j];
      l[i] += grid[i][j];
      r[j] += grid[i][j];
    }
  }
  if (n == 1) {
    printf("1\n");
    return 0;
  }
  long long int sum = l[ei];
  int x;
  for (int i = 0; i < n; i++)
    if (i != ei) {
      x = i;
      break;
    }
  long long int sum1 = l[x];
  if (sum >= sum1) {
    printf("-1\n");
    return 0;
  }
  grid[ei][ej] = sum1 - sum;
  l[ei] += sum1 - sum;
  r[ej] += sum1 - sum;
  sum = sum1;
  if (ei == ej) dia1 += grid[ei][ej];
  if (ei == n - 1 - ej) dia2 += grid[ei][ej];
  if (dia1 != sum1 || dia2 != sum1) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (l[i] != sum1) {
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (r[i] != sum1) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%I64d\n", grid[ei][ej]);
  return 0;
}
