open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let Read3Int () = ReadNextInt (), ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module ARC083 =
    let private Mod = 1000000007L

    let private RestoringRoadNetwork () =
        let n = ReadNextInt ()
        let m = Array.init n (fun _ -> ReadListOf int64 n |> Seq.toArray)
        let g x y = m.[x].[y]
        let mutable fail = false
        let mutable total = m |> Seq.map Seq.sum |> Seq.sum
        total <- total / 2L
        //printfn "total = %d" total
        for i in [0..n-1] do
            for j in [i+1..n-1] do
                let mutable minD = System.Int64.MaxValue
                for k in [0..n-1] do
                    if i <> k && j <> k then
                        minD <- min minD (g i k + g k j)
                let c = g i j
                if minD < c then fail <- true
                elif minD = c then total <- total - c
        if fail then -1L else total
        |> printfn "%d"

    let Entry = RestoringRoadNetwork

ARC083.Entry ()