n = gets.to_i
graph = n.times.map{ gets.split.map(&:to_i) }
bridge = []

n.times do |i|
  0.upto(i-1) do |j|
    cost = graph[i][j]
    next if cost == -1
    bridge << [cost, i, j]
  end
end

uft = Array.new(n, -1)
uft[bridge[0][1]] = bridge[0][1]
total = 0

bridge.sort!.each do |cost, i, j|
  if uft[i] == -1 and uft[j] == -1
    total += cost
    uft[j] = i
  end
end

puts total