import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val d = Array.ofDim[Int](N, N)
    for {
      i <- 0 until N
      j <- 0 until N
    } d(i)(j) = sc.nextInt()

    def calc: Option[Long] = {
      var ok = true
      var sum: Long = 0
      for {
        i <- 0 until N - 1
        j <- i + 1 until N
      } {
        var duplicate = false
        (0 until N) foreach { k =>
          if (k != i && k != j) {
            if (d(i)(k) + d(k)(j) == d(i)(j)) {
              duplicate = true
            } else {
              ok &= d(i)(k) + d(k)(j) > d(i)(j)
            }
          }
        }
        if (!duplicate) sum += d(i)(j)
      }

      if (ok) Some(sum) else None
    }

    val ans = (calc getOrElse -1).toString

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }
}
