#include <bits/stdc++.h>
using namespace std;
const int MaxN = 505;
long long N, A[MaxN][MaxN], sum, FJ, ksum, Ans;
int main() {
  scanf("%I64d", &N);
  if (N == 1) {
    printf("1");
    return 0;
  }
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j) scanf("%I64d", &A[i][j]);
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= N; ++j)
      if (A[i][j] == 0) {
        FJ = j;
        break;
      }
  for (int j = 1; j <= N; ++j)
    if (j != FJ) {
      for (int i = 1; i <= N; ++i) sum += A[i][j];
      break;
    }
  for (int j = 1; j <= N; ++j)
    if (j == FJ) {
      for (int i = 1; i <= N; ++i) ksum += A[i][j];
      break;
    }
  if (ksum >= sum)
    puts("-1");
  else {
    Ans = sum - ksum;
    for (int i = 1; i <= N; ++i)
      for (int j = 1; j <= N; ++j)
        if (!A[i][j]) A[i][j] = sum - ksum;
    for (int i = 1; i <= N; ++i) {
      ksum = 0;
      for (int j = 1; j <= N; ++j) ksum += A[i][j];
      if (ksum != sum) {
        puts("-1");
        return 0;
      }
    }
    for (int j = 1; j <= N; ++j) {
      ksum = 0;
      for (int i = 1; i <= N; ++i) ksum += A[i][j];
      if (ksum != sum) {
        puts("-1");
        return 0;
      }
    }
    ksum = 0;
    for (int i = 1, j = 1; i <= N; ++i, ++j) ksum += A[i][j];
    if (ksum != sum) {
      puts("-1");
      return 0;
    }
    ksum = 0;
    for (int i = 1, j = N; i <= N; ++i, --j) ksum += A[i][j];
    if (ksum != sum) {
      puts("-1");
      return 0;
    }
    printf("%I64d", Ans);
  }
  return 0;
}
