import java.io.PrintWriter

data class Edge(val a: Int, val i: Int, val j: Int)

fun main(args: Array<String>) = with(PrintWriter(System.out)) {
    val n = readLine()!!.toInt()
    val uf = IntArray(n)
    val a = mutableListOf<Edge>()
    for (i in 0 until n) {
        uf[i] = i
        readLine()!!.trim().split(' ').forEachIndexed { j, s ->
            if (j > i-1)
                return@forEachIndexed
            val a_ij = s.toInt()
            if (a_ij != -1)
                a.add(Edge(a_ij, i, j))
        }
    }
    a.sortBy { it.a }

    fun find(_n: Int): Int {
        if (_n == uf[_n]) {
            return _n
        } else {
            uf[_n] = find(uf[_n])
            return uf[_n]
        }
    }

    fun isSame(_i: Int, _j: Int): Boolean {
        return find(_i) == find(_j)
    }

    fun join(_i: Int, _j: Int) {
        uf[find(_i)] = find(_j)
    }

    var sum = 0
    a.forEach{ a_ij ->
        if (!isSame(a_ij.i, a_ij.j)) {
            sum += a_ij.a
            join(a_ij.i, a_ij.j)
        }
    }
    println(sum)
    flush()
}

