#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int a[300][300];
int main() {
  int n;
  cin >> n;
  rep(i,n)rep(j,n) cin >> a[i][j];
  ll ans = 0;
  rep(i,n)rep(j,n){
    if(i>=j)continue;
    int d = 2*1e9;
    rep(k,n){
      if(i==k||j==k) continue;
      if(a[i][j]>a[i][k]+a[k][j]){
        cout << -1 << endl;
        return 0;
      }
      d = min(d,a[i][k]+a[k][j]);
    }
    if(d>a[i][j]) ans += a[i][j];
  }
  cout << ans << endl;
}