integer N
integer(16), allocatable::A(:,:)
integer(16) ans
logical direct
read*,N
allocate(A(N,N))
do i=1,N
  read*,A(i,:)
end do

ans=0
do i=1,N
  do j=i+1,N
    direct=.true.
    do k=1,N
      if(i==k.or.j==k)cycle
      if(A(i,j)>A(i,k)+A(k,j))then
        print"(i0)",-1
        stop
      else if(A(i,j)==A(i,k)+A(k,j))then
        direct=.false.
      endif
    end do
    if(direct)ans=ans+A(i,j)
  end do
end do

print"(I0)",ans

end