Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03165 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 17 09:02:00 2019
DPF3
@author: maezawa
"""

s = input()
t = input()

ns = len(s)
nt = len(t)

dp = [[0 for _ in range(nt+1)] for _ in range(ns+1)]

for si in range(ns):
    for ti in range(nt):
        if s[si] == t[ti]:
            dp[si+1][ti+1] = max(dp[si][ti]+1, dp[si+1][ti], dp[si][ti+1])
        else:
            dp[si+1][ti+1] = max(dp[si+1][ti], dp[si][ti+1])

ans = ''
si = ns
ti = nt
while si > 0 and ti > 0:
    if dp[si][ti] == dp[si-1][ti]: 
        si -= 1
    elif dp[si][ti] == dp[si][ti-1]:
        ti -= 1
    else:
        ans = s[si-1] + ans
        si -= 1
        ti -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools as itr

s = input()
t = input()

ls = len(s)
lt = len(t)

dp = [['']*(lt+1) for _ in range(ls+1)]

for i, j in itr.product(range(1, ls+1), range(1, lt+1)):
    if s[i-1] == t[j-1]:
        if len(dp[i][j-1]) > len(dp[i-1][j]):
            dp[i][j] = dp[i][j-1]+s[i-1]
        else:
            dp[i][j] = dp[i-1][j]+s[i-1]
    else:
        if len(dp[i-1][j]) > len(dp[i][j-1]):
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = dp[i][j-1]
    print((i,j), dp[i][j])

print(dp[-1][-1])
Problem p03166 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 19 16:05:26 2019
DP_G
@author: maezawa
"""
import sys
sys.setrecursionlimit(10**5)

n, m = list(map(int, input().split()))
v = [-1]*(n+1)
adj = [[] for _ in range(n+1)]
for _ in range(m):
    i, j = list(map(int, input().split()))
    adj[i].append(j)
    
def dfs(vi):
    if v[vi] != -1:
        return v[vi]
    res = 0
    for nb in adj[vi]:
        res0 = dfs(nb) +1
        if res < res0:
            res = res0
    v[vi] = res
    return res

ans = 0
for node in range(1, n+1):
    current = dfs(node)
    if current > ans:
        ans = current
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 17 11:58:20 2019
DP_G
@author: maezawa
"""
memo = [-1] * (10**5+100)

def rec(nx):
    if memo[nx] > -1:
        return memo[nx]
    depth = 0
    for edge in edges[nx]:
        nrec = rec(edge) + 1
        if nrec > depth:
            depth = nrec
    memo[nx] = depth
    return depth

n, m = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for i in range(m):
    x, y = list(map(int, input().split()))
    edges[x-1].append(y-1)
    
maxdepth = 0
for node in range(n):
    depth = rec(node)
    if maxdepth < depth:
        maxdepth = depth
        
print(maxdepth)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 17 11:58:20 2019
DP_G
@author: maezawa
"""
memo = [-1] * (10**5+1)

def rec(nx):
    if memo[nx] > -1:
        return memo[nx]
    depth = 0
    for edge in edges[nx]:
        nrec = rec(edge) + 1
        if nrec > depth:
            depth = nrec
    memo[nx] = depth
    return depth

n, m = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for i in range(m):
    x, y = list(map(int, input().split()))
    edges[x-1].append(y-1)
    
maxdepth = 0
for node in range(n):
    depth = rec(node)
    if maxdepth < depth:
        maxdepth = depth
        
print(maxdepth)

Buggy submission (verdict: Runtime Error):
 # -*- coding: utf-8 -*-
"""
Created on Sat Jan 19 16:05:26 2019
DP_G
@author: maezawa
"""

n, m = list(map(int, input().split()))
v = [-1]*(n+1)
adj = [[] for _ in range(n+1)]
for _ in range(m):
    i, j = list(map(int, input().split()))
    adj[i].append(j)
    
def dfs(vi):
    if v[vi] != -1:
        return v[vi]
    res = 0
    for nb in adj[vi]:
        res0 = dfs(nb) +1
        if res < res0:
            res = res0
    v[vi] = res
    return res

ans = 0
for node in range(1, n+1):
    current = dfs(node)
    if current > ans:
        ans = current
print(ans)
Problem p03193 (python)

Fixed submission:
n,h,w = list(map(int, input().split()))
cnt = 0
for i in range(n):
    a, b = list(map(int, input().split()))
    if a>=h and b>=w:
        cnt += 1
        
print(cnt)

Buggy submission (verdict: Runtime Error):
 n,h,w = list(map(int, input().split()))
cnt = 0
for i in range(n):
    a, b = list(map(int, input().split()))
    if a>=h and b>=w:
        cnt += 1
        
print(cnt)
Problem p03240 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Oct  6 17:56:47 2018
ABC112C
@author: maezawa
"""
import itertools as itr
n = int(input())
xyh = []
for i in range(n):
    xyhi = list(map(int, input().split()))
    xyh.append(xyhi)
xyh.sort(key=lambda x:x[2], reverse=True)
#print(xyh)

for cx, cy in itr.product(range(101),range(101)):
    hres = abs(xyh[0][0]-cx)+abs(xyh[0][1]-cy)+xyh[0][2]
    ok = 0
    for i in range(1,n):
        if xyh[i][2] > 0:
            htemp = abs(xyh[i][0]-cx)+abs(xyh[i][1]-cy)+xyh[i][2]
            #print(cx, cy, i, hh)
            if  htemp != hres:
                ok = -1
                break    
        else:
            if abs(xyh[i][0]-cx)+abs(xyh[i][1]-cy) < hres:
                ok = -1
                break
    if ok == 0:
        print(cx, cy, hres)
        break

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat Oct  6 17:56:47 2018
ABC112C
@author: maezawa
"""
import itertools as itr
n = int(input())
x = []
y = []
h = []
for i in range(n):
    xi, yi, hi = list(map(int, input().split()))
    x.append(xi)
    y.append(yi)
    h.append(hi)
    
ans = 1    
for i in range(n):
    if h[i] > 0:
        break
    cx = sum(x)//len(x)
    cy = sum(y)//len(y)
    h = 1
    print(cx, cy, h)
    ans = 0


for cx, cy in itr.product(range(101),range(101)):
    hh = set([])  
    for i in range(n):
        if h[i] > 0:
            hh.add(abs(x[i]-cx)+abs(y[i]-cy)+h[i])
            #print(cx, cy, i, hh)
            if  len(hh) > 1:
                break
        elif abs(x[i]-cx)+abs(y[i]-cy) < 1:
            break
    else:
        if len(hh) == 1:
            if ans ==1:
                print(cx, cy, hh.pop())
                break
Problem p03244 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 29 16:33:51 2018
ABC111C
@author: maezawa
"""

import collections

n = int(input())
v = list(map(int, input().split()))

v0 = [v[i] for i in range(0,n,2)]
v1 = [v[i] for i in range(1,n,2)]

v0cnt = collections.Counter(v0)
v1cnt = collections.Counter(v1)

v0most = v0cnt.most_common()[0]
v1most = v1cnt.most_common()[0]
if len(v0cnt) > 1:
    v0next = v0cnt.most_common()[1]
if len(v1cnt) > 1:
    v1next = v1cnt.most_common()[1]
if v0most[0] != v1most[0]:
    ans = n - v0most[1] -v1most[1]
else:
    if v0most[1] == v1most[1]:
        if v0most[1] == n//2:
            ans = n//2
        else:
            if v0next[1] > v1next[1]:
                ans = n - v1most[1] - v0next[1]
            else:
                ans = n - v0most[1] - v1next[1]            
    elif v0most[1] > v1most[1]:
        ans = n - v0most[1] - v1next[1]
    else:
        ans = n - v1most[1] - v0next[1]

print(ans)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
v = list(map(int, input().split()))

v0 = [v[i] for i in range(0,n,2)]
v1 = [v[i] for i in range(1,n,2)]

v0cnt = collections.Counter(v0)
v1cnt = collections.Counter(v1)

v0most = v0cnt.most_common()[0]
v1most = v1cnt.most_common()[0]
v0next = v0cnt.most_common()[1]
v1next = v1cnt.most_common()[1]
if v0most[0] != v1most[0]:
    ans = n - v0most[1] -v1most[1]
else:
    if v0most[1] == v1most[1]:
        if v0most[1] == n//2:
            ans = n//2
        else:
            if v0next[1] > v1next[1]:
                ans = n - v1most[1] - v0next[1]
            else:
                ans = n - v0most[1] - v1next[1]            
    elif v0most[1] > v1most[1]:
        ans = n - v0most[1] - v1next[1]
    else:
        ans = n - v1most[1] - v0next[1]

print(ans)
Problem p03262 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n, x0 = list(map(int, input().split()))
x = list(map(int, input().split()))

xx0 = [abs(xi-x0) for xi in x ]

y = xx0[0]
for yi in xx0:
    y = gcd(y, yi)
    
print(y)

Buggy submission (verdict: Runtime Error):
import math

n, x0 = list(map(int, input().split()))
x = list(map(int, input().split()))

xx0 = [abs(xi-x0) for xi in x ]

y = xx0[0]
for yi in xx0:
    y = math.gcd(y, yi)
    
print(y)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  8 18:34:07 2018
ABC109C
@author: maezawa
"""
import math
n, x0 = list(map(int, input().split()))
x = list(map(int, input().split()))

xx0 = [abs(xi-x0) for xi in x ]

y = xx0[0]
for yi in xx0:
    y = math.gcd(y, yi)
    
print(y)
Problem p03296 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

cnt = 0
prev = 0
for i in range(n):
    if prev == a[i]:
        cnt += 1
        prev = 0
    else:
        prev = a[i]

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

cnt = 0
pre = 0
for i in range(n):
    if prev == a[i]:
        cnt += 1
        prev = 0
    else:
        prev = a[i]

print(cnt)
Problem p03337 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat May 26 21:00:01 2018

@author: maezawa
"""

a, b = list(map(int, input().split()))

ans = max(a*b, a-b, a+b)
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat May 26 22:01:36 2018

@author: maezawa
"""

n = int(input())
a = list(map(int, input().split()))

cnt = 0
l=0
r=0

sum_a = a[0]
xor_a = a[0]

while True:
    if sum_a == xor_a:
        cnt += 1
        if r<n-1:
            r += 1        
            sum_a += a[r]
            xor_a ^= a[r]
            continue
    l += 1
    r -= 1
    if l == n:
        break
    sum_a -= a[l-1]+a[r+1]
    xor_a ^= a[l-1]^a[r+1]
    #xor_a ^= a[r+1]
    
print(cnt)
Problem p03352 (python)

Fixed submission:
n = int(input())
array = []
for i in range(1,33):
  for j in range(2,10):
    a = i**j
    if a <= n:
      array.append(a)
array.sort(reverse=True)
print(array[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
array = []
for i in range(2,33):
  for j in range(10):
    a = i**j
    if a <= n:
      array.append(a)
array.sort(reversed=True)
print(array[0])

Buggy submission (verdict: Runtime Error):

n = int(input())
array = []
for i in range(2,33):
  if j in range(10):
    a = i**j
    if a <= n:
      array.append(a)
array.sort(reversed=True)
print(array[0])
Problem p03371 (python)

Fixed submission:
a, b, c, x, y = list(map(int, input().split()))

min_money=2*5000*10**5
for nc in range(0,2*10**5+1,2):
    if nc > 2*x and nc > 2*y:
        break
    if nc > 2*x:
        money = (y-nc//2)*b + nc*c
    elif nc > 2*y:
        money = (x-nc//2)*a + nc*c
    else:
        money = (x-nc//2)*a + (y-nc//2)*b + nc*c
    if min_money > money:
        min_money = money
            
print(min_money)

Buggy submission (verdict: Runtime Error):
a, b, c, x, y = list(map(int, input().split()))

if a<c and b<c:
    ans = a*x + b*y
else:
    min_money=2*5000*10**5
    for nc in range(0,2*10**5+1,2):
        if nc > 2*x and nc > 2*y:
            break
        if nc > 2*x:
            money = (y-nc//2)*b + nc*c
        elif nc > 2*y:
            money = (x-nc//2)*a + nc*c
        else:
            money = (x-nc//2)*a + (y-nc//2)*b + nc*c
        if min_money > money:
            min_money = money
            
print(min_money)

Buggy submission (verdict: Runtime Error):
a, b, c, x, y = list(map(int, input().split()))

if a<c and b<c:
    ans = a*x + b*y
else:
    min_money=2*5000*10**5
    for nc in range(0,2*10**5+1,2):
        if nc > 2*x and nc > 2*y:
            break
        if nc > 2*x:
            money = (y-nc//2)*b + nc*c
        elif nc > 2*y:
            money = (x-nc//2)*a + nc*c
        else:
            money = (x-nc//2)*a + (y-nc//2)*b + nc*c
        if min_money > money:
            min_money = money
            nc0=nc

print(min_money)

Buggy submission (verdict: Runtime Error):
a, b, c, x, y = list(map(int, input().split()))

if a<c and b<c:
    ans = a*x + b*y
else:
    min_money=5000*10**5
    for nc in range(0,2*max(x,y)+1,2):
        if nc > 2*x and nc > 2*y:
            break
        if nc > 2*x:
            money = (y-nc//2)*b + nc*c
        elif nc > 2*y:
            money = (x-nc//2)*a + nc*c
        else:
            money = (x-nc//2)*a + (y-nc//2)*b + nc*c
        if min_money > money:
            min_money = money
            nc0=nc

print(min_money)
Problem p03377 (python)

Fixed submission:
a, b, x = list(map(int, input().split()))

if a>x:
    print('NO')
elif a+b<x:
    print('NO')
else:
    print('YES')

Buggy submission (verdict: Runtime Error):

n = int(input())
x = list(map(int, input().split()))

sortedx = x[:]
sortedx.sort()

for i in range(n):
    #ix = sortedx.index(x[i])
    #print(sortedx)
    #print(ix)
    if x[i] <= sortedx[n//2-1]:
        print(sortedx[n//2])
    else:
        print(sortedx[n//2-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))

sortedx = x[:]
sortedx.sort()

for i in range(n):
    #ix = sortedx.index(x[i])
    #print(sortedx)
    #print(ix)
    if x[i] <= sortedx[n//2-1]:
        print(sortedx[n//2-1])
    else:
        print(sortedx[n//2-2])
Problem p03379 (python)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))

sortedx = x[:]
sortedx.sort()

for i in range(n):
    #ix = sortedx.index(x[i])
    #print(sortedx)
    #print(ix)
    if x[i] <= sortedx[n//2-1]:
        print(sortedx[n//2])
    else:
        print(sortedx[n//2-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))

sx = sorted(x)
xm = sx[n//2]
xp = sx[n//2+1]

for i in range(n):
  if x[i] <= xm:
    b = xp
  else:
    b = xm
  print(b)
Problem p03434 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = sum([a[i] for i in range(0,n,2)])
bob = sum([a[i] for i in range(1,n,2)])
print(alice-bob)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = sum([a[i] for i in a if i%2 == 0])
bob = sum([a[i] for i in a if i%2 == 1])
print(alice-bob)
Problem p03448 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
ma = x // 500
mb = x // 100
mc = x // 50
na = min([a, ma])
nb = min([b, mb])
nc = min([c, mc])
for i500 in range(na+1):
  for i100 in range(nb+1):
      current = x-500*i500-100*i100
      if current >= 0 and current <= 50*nc:
          cnt += 1
          #print(i500,i100,cnt)
print(cnt)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
ma = x // a
mb = x // b
mc = x // c
for i500 in range(ma+1):
  for i100 in range(mb+1):
    for i50 in range(mc+a):
      if 500*i500 + 100*i100 + 50*i50 == x:
        cnt += 1
print(cnt)
Problem p03478 (python)

Fixed submission:
def sumorder(k, a, b):
  arr = list(str(k))
  s = sum(list(map(int,arr)))
  #print(arr, s)
  if a<=s and s<=b:
    return True
  else:
    return False
  
n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n+1):
  if sumorder(i, a, b):
    ans += i
    
print(ans)

Buggy submission (verdict: Runtime Error):
def sumorder(k, a, b):
  a = list(str(k))
  s = sum(a)
  if a<=s and s<=b:
    return True
  else:
    return False
  
n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n+1):
  if sumorder(i, a, b):
    ans += i
    
print(ans)
Problem p03486 (python)

Fixed submission:
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
if s < t:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
s.sort()
t.sort(reverse=True)
if s < t:
  print('Yes')
else:
  print('No')
Problem p03503 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 17:22:42 2018
ABC080
@author: maezawa
"""
import itertools as itr

n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
    
#print(f)
#print(p)
profit = -10**10
for oph in itr.product([0,1], repeat=10):
    if oph == (0,0,0,0,0,0,0,0,0,0):
        continue
    c = [0]*n
    for i in range(n):
        c[i] = sum([f[i][j]*oph[j] for j in range(10)])
    pcurrent = sum([p[i][c[i]] for i in range(n)])
    if pcurrent > profit:
        profit = pcurrent
        #print(oph)

print(profit)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 17:22:42 2018
ABC080
@author: maezawa
"""
import itertools as itr

n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
    
#print(f)
#print(p)
profit = -10**8
for oph in itr.product([0,1], repeat=10):
    if oph == (0,0,0,0,0,0,0,0,0,0):
        continue
    c = [0]*n
    for i in range(n):
        c[i] = sum([f[i][j] for j in range(10) if oph[j]==1])
    pcurrent = sum([p[i][c[i]] for i in range(n+1)])
    if pcurrent > profit:
        profit = pcurrent
        #print(oph)

print(profit)
Problem p03545 (python)

Fixed submission:
a, b, c, d = list(input())
ops = ['+', '-']
fin = False
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            s = a+op1+b+op2+c+op3+d
            res = eval(s)
            if res == 7:
                print(s+'=7')
                fin = True
                break
        if fin == True:
            break
    if fin == True:
        break

Buggy submission (verdict: Runtime Error):
a, b, c, d = list(map(int, input().split()))
ops = ['+', '-']
for op1 in ops:
  for op2 in ops:
    for op3 in ops:
      s = str(a)+op1+str(b)+op2+str(c)+op3+str(d)
      res = eval(s)
      if res == 7:
        print(s+'=7')
        break
Problem p03624 (python)

Fixed submission:
s = input()
sset = set(s)
ans = 'None'
abc = 'abcdefghijklmnopqrstuvwxyz'
for c in abc:
  if c not in sset:
    ans = c
    break
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
sset = set(s)
ans = 'None'
for c in (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z):
  if c not in sset:
    ans = c
    break
print(ans)
Problem p03625 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 30 10:49:33 2018
ABC071C
@author: maezawa
"""
import collections
n = int(input())
a = list(map(int,input().split()))
acount = collections.Counter(a)
auniq = list(acount.keys())
auniq.sort(reverse=True)
edge1 = 0
ans = 0
for edge in auniq:
    if acount[edge] >= 4:
        if edge1 == 0:
            ans = edge*edge
            break
        else:
            ans = edge1*edge
            break
    if acount[edge] >= 2:
        if edge1 == 0:
            edge1 = edge
        else:
            ans = edge1*edge
            break
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 30 10:49:33 2018
ABC071C
@author: maezawa
"""
import collections
n = int(input())
a = list(map(int,input().split()))
acount = collections.Counter(a)
auniq = acount.keys()
auniq.sort(reverse=True)
edge1 = 0
ans = 0
for edge in auniq:
    if acount[edge] >= 4:
        if edge1 == 0:
            ans = edge*edge
            break
        else:
            ans = edge1*edge
            break
    if acount[edge] >= 2:
        if edge1 == 0:
            edge1 = edge
        else:
            ans = edge1*edge
            break
print(ans)
Problem p03671 (python)

Fixed submission:
a = list(map(int, input().split()))
a.sort()
print(sum(a[:-1]))

Buggy submission (verdict: Runtime Error):
a = list(map(int, input()))
a.sort()
print(sum(a[:-1]))
Problem p03679 (python)

Fixed submission:
x, a, b = list(map(int, input().split()))
if -a+b <= 0:
  print('delicious')
elif -a+b <= x:
  print('safe')
else:
  print('dangerous')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 20 21:40:30 2018
ABC065D
@author: maezawa
i=0...n (0-origin)
"""
import heapq

n = int(input())
a = []
b = []
for i in range(n): # i is a name of the city (0-origin)
    xy = list(map(int, input().split()))
    a.append([i,xy[0]])
    b.append([i,xy[1]])

a.sort(key=lambda x: x[1])
b.sort(key=lambda x: x[1])
#print(a) 
#print(b)

# making adj list
adj = [[] for _ in range(n)]
for i, [j, x] in enumerate(a[:-1]):
    adj[j].append([a[i+1][1]-x, a[i+1][0]])
    adj[a[i+1][0]].append([a[i+1][1]-x, j])
for i, [j, y] in enumerate(b[:-1]):
    adj[j].append([b[i+1][1]-y, b[i+1][0]])
    adj[b[i+1][0]].append([b[i+1][1]-y, j])

#print(adj)
    
# Prim's algorithm
d = [10**10]*n
visited = [False]*n
h = []
s = 0
heapq.heappush(h, [0, s])
cnt = 0
while h:
    cost, node = heapq.heappop(h)
    #if visited[node] != True and cost < d[node]:
    if visited[node] != True:        
        d[node] = cost
        visited[node] = True
        cnt += 1
        if cnt == n:
            break
        for edge in adj[node]:
            if visited[edge[1]] == True:
                continue
            heapq.heappush(h, edge)
            
#print(d)
print(sum(d))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 20 21:40:30 2018
ABC065D
@author: maezawa
i=0...n (0-origin)
"""
import heapq

n = int(input())
a = []
b = []
for i in range(n): # i is a name of the city (0-origin)
    xy = list(map(int, input().split()))
    a.append([i,xy[0]])
    b.append([i,xy[1]])

a.sort(key=lambda x: x[1])
b.sort(key=lambda x: x[1])
#print(a) 
#print(b)

# making adj list
adj = [[] for _ in range(n)]
for i, [j, x] in enumerate(a[:-1]):
    adj[j].append([a[i+1][1]-x, a[i+1][0]])
    adj[a[i+1][0]].append([a[i+1][1]-x, j])
for i, [j, y] in enumerate(b[:-1]):
    adj[j].append([b[i+1][1]-y, b[i+1][0]])
    adj[b[i+1][0]].append([b[i+1][1]-y, j])

#print(adj)
    
# Prim's algorithm
d = [10**10]*n
visited = [False]*n
h = []
s = 0
heapq.heappush(h, [0, s])
cnt = 0
while h:
    cost, node = heapq.heappop(h)
    #if visited[node] != True and cost < d[node]:
    if visited[node] != True:        
        d[node] = cost
        visited[node] = True
        cnt += 1
        if cnt == n:
            break
        for edge in adj[node]:
            if visited[edge[1]] == True:
                continue
            heapq.heappush(h, edge)
            
#print(d)
print(sum(d))
Problem p03680 (python)

Fixed submission:
n = int(input())
a = [0]
for _ in range(n):
  a.append(int(input()))
visited = [False]*(n+1)
visited[1] = True
cnt = 0
but = 1
while True:
  nextb = a[but]
  if visited[nextb]:
    cnt = -1
    break
  elif nextb == 2:
    cnt += 1
    break
  else:
    but = nextb
    cnt += 1
    visited[but] = True
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [0]
for _ in range(n+1):
  a.append(int(input()))
visited = [False]*(n+1)
visited[1] = True
cnt = 0
but = 1
while True:
  nextb = a[but]
  if visited[nextb]:
    cnt = -1
    break
  elif nextb == 2:
    cnt += 1
    break
  else:
    but = nextb
    cnt += 1
    visited[but] = True
print(cnt)
Problem p03738 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  8 15:34:42 2018

@author: maezawa
"""

a = int(input())
b = int(input())
if a > b:
    print('GREATER')
elif a == b:
    print('EQUAL')
else:
    print('LESS')

Buggy submission (verdict: Runtime Error):
a, b = list(map(int, input().split()))
if a > b:
  print('GREATER')
else:
  print('LESS')