Buggy python submission (verdict: Runtime Error):
n = input()
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
m = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
k = [-1 for i in range(n)]
 
d[0] = 0
 
while 1:
    cost = INFTY
for i in range(n):
    if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i

if cost == INFTY:
    break
    
color[u] = 2
 
for v in range(n):
    if color[v] != 2 and m[u][v] != INFTY and m[u][v] < d[v]:
        d[v] = m[u][v]
        k[v] = u
        color[v] = 1
sum = 0
for i in range(n):
    if p[i] != -1:
        sum += m[i][k[i]]
return sum
 
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
    if G[j] != -1:
        m[i][j] = G[j]

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()

Buggy python submission (verdict: Runtime Error):
n = input()
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
m = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
k = [-1 for i in range(n)]

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
    if G[j] != -1:
        m[i][j] = G[j]

d[0] = 0
 
while 1:
    cost = INFTY
for i in range(n):
    if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i

if cost == INFTY:
    break
    
color[u] = 2
 
for v in range(n):
    if color[v] != 2 and m[u][v] != INFTY and m[u][v] < d[v]:
        d[v] = m[u][v]
        k[v] = u
        color[v] = 1
sum = 0
for i in range(n):
    if p[i] != -1:
        sum += m[i][k[i]]
print sum

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()

Buggy python submission (verdict: Runtime Error):
n = input()
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
m = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
k = [-1 for i in range(n)]

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
        if G[j] != -1:
            m[i][j] = G[j]

d[0] = 0
 
while 1:
    cost = INFTY
for i in range(n):
    if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i

if cost == INFTY:
    break
    
color[u] = 2
 
for v in range(n):
    if color[v] != 2 and m[u][v] != INFTY and m[u][v] < d[v]:
        d[v] = m[u][v]
        k[v] = u
        color[v] = 1
sum = 0
for i in range(n):
    if p[i] != -1:
        sum += m[i][k[i]]
print sum

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()

Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
m = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
k = [-1 for i in range(n)]

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
        if G[j] != -1:
            m[i][j] = G[j]

d[0] = 0
 
while 1:
    cost = INFTY
for i in range(n):
    if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i

if cost == INFTY:
    break
    
color[u] = 2
 
for v in range(n):
    if color[v] != 2 and m[u][v] != INFTY and m[u][v] < d[v]:
        d[v] = m[u][v]
        k[v] = u
        color[v] = 1
sum = 0
for i in range(n):
    if p[i] != -1:
        sum += m[i][k[i]]
print sum

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()

Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
m = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
k = [-1 for i in range(n)]

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
        if G[j] != -1:
            m[i][j] = G[j]

d[0] = 0
 
while 1:
    cost = INFTY
    for i in range(n):
        if color[i] != 2 and d[i] < cost:
            cost = d[i]
            u = i

    if cost == INFTY:
        break
    
    color[u] = 2
 
    for v in range(n):
        if color[v] != 2 and m[u][v] != INFTY and m[u][v] < d[v]:
            d[v] = m[u][v]
            k[v] = u
            color[v] = 1

sum = 0
for i in range(n):
    if p[i] != -1:
        sum += m[i][k[i]]
print sum

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()

Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
m = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
k = [-1 for i in range(n)]

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
        if G[j] != -1:
            m[i][j] = G[j]

d[0] = 0
 
while 1:
    cost = INFTY
    for i in range(n):
        if color[i] != 2 and d[i] < cost:
            cost = d[i]
            u = i

    if cost == INFTY:
        break
    
    color[u] = 2
 
    for v in range(n):
        if color[v] != 2 and m[u][v] != INFTY and m[u][v] < d[v]:
            d[v] = m[u][v]
            k[v] = u
            color[v] = 1

sum = 0
for i in range(n):
    if p[i] != -1:
        sum += m[i][k[i]]
print sum

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()

Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
 
INFTY = 99999999
 
color = [0 for i in range(n)]
m = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
k = [-1 for i in range(n)]

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
        if G[j] != -1:
            m[i][j] = G[j]

d[0] = 0

while 1:
    cost = INFTY
    for i in range(n):
        if color[i] != 2 and d[i] < cost:
            cost = d[i]
            u = i

    if cost == INFTY:
        break

    color[u] = 2

    for v in range(n):
        if color[v] != 2 and m[u][v] != INFTY and m[u][v] < d[v]:
            d[v] = m[u][v]
            k[v] = u
            color[v] = 1

sum = 0
for i in range(n):
    if p[i] != -1:
        sum += m[i][k[i]]
print sum

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()

Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
 
INFTY = 99999999
 
color = [0 for i in range(n)]
m = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
k = [-1 for i in range(n)]

for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
        if G[j] != -1:
            m[i][j] = G[j]

d[0] = 0

while 1:
    cost = INFTY
    for i in range(n):
        if color[i] != 2 and d[i] < cost:
            cost = d[i]
            u = i

    if cost == INFTY:
        break

    color[u] = 2

    for v in range(n):
        if color[v] != 2 and m[u][v] != INFTY and m[u][v] < d[v]:
            d[v] = m[u][v]
            k[v] = u
            color[v] = 1

sum = 0
for i in range(n):
    if p[i] != -1:
        sum += m[i][k[i]]
print sum

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()

Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
    d[0] = 0
 
    while 1:
        cost = INFTY
        for i in range(n):
            if color[i] != 2 and d[i] < cost:
                cost = d[i]
                u = i
 
      if cost == INFTY:
          break
     
      color[u] = 2
 
      for v in range(n):
          if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
              d[v] = M[u][v]
              p[v] = u
              color[v] = 1
 
    sum = 0
    for i in range(n):
        if p[i] != -1:
            sum += M[i][p[i]]
    return sum
 
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(n):
       if G[j] != -1:
         M[i][j] = G[j]
 
print MST()

Fixed submission:
n = int(raw_input())
 
INFTY = float('inf')
 
color = [0 for i in range(n)]
M = [[INFTY for i in range(n)] for j in range(n)]
d = [INFTY for i in range(n)]
p = [-1 for i in range(n)]
 
def MST():
  d[0] = 0
 
  while True:
    cost = INFTY
    for i in range(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i
 
    if cost == INFTY:
      break
     
    color[u] = 2
 
    for v in range(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1
 
  sum = 0
  for i in range(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum
 
for i in range(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]
 
print MST()