Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = [int(s) for s in input().split()]
a.sort()
b_c = [[int(s) for s in input().split()] for i in range(m)]
cnt = 0
for k in range(m):
    while cnt < b_c[k][0]:
        if a[cnt] <= b_c[k][1]:
            a[cnt] = b_c[k][1]
        cnt += 1
    a.sort()
print(sum(a))        
    
        

Fixed submission:
a,b =map(int,input().split())
if a >= 13:
    print(b)
elif 6<= a <= 12:
    print(int(b/2))
elif  a <= 5:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
d = []
for _ in range(m):
  b,c = map(int,input().split())
  d.extend([c]*b)
d.sort(reverse =True)
d_big = d[:n]


a += d_big
a.sort(reverse = True)
print(sum(a[:n]))
  

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [tuple(map(int,input().split())) for _ in range(m)]

bc.sort(key = lambda x: x[1],reverse = True)
i = 0
j = 0
ad = []
while i < n and j < m:
    ad.extend([bc[j][1]]*bc[j][0])
    i += bc[j][0]
    j += 1
    
if len(ad) < n:
    ad.extend([0]*(n-len(ad)))

a.sort(reverse = True)

i = 0
j = 0
k = 0
ans = 0
while k < n :
    if a[i] > ad[j]:
        ans += a[i]
        i += 1
        k += 1
    else:
        ans += ad[j]
        j += 1
        k += 1
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
d = []
b_sum = 0
for _ in range(m):
  b,c = map(int,input().split())
  d.extend([c]*b)
  b_sum += b
d.sort(reverse =True)
d_big = d[:n]


for x in range(min(b_sum,n)):
  if d_big[x] > a[x]:
    a[x] = d_big[x]
  else:
    break

print(sum(a))
  

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [tuple(map(int,input().split())) for _ in range(m)]

bc.sort(key = lambda x: x[1],reverse = True)
i = 0
j = 0
ad = []
while i < n and j < m:
    ad.extend([bc[j][1]]*bc[j][0])
    i += bc[j][0]
    j += 1
    
if len(ad) < n:
    ad.extend([0]*(n-len(ad)))

a.sort(reverse = True)

i = 0
j = 0
k = 0
ans = 0
while k < n :
    if a[i] > ad[j]:
        ans += a[i]
        i += 1
        k += 1
    else:
        ans += ad[j]
        j += 1
        k += 1
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
for _ in range(m):
  b,c = map(int,input().split())
  for i in range(b):
    if a[i] < c:
      a[i] = c
    else:
      break
  a.sort()
      
print(sum(a))
  

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [tuple(map(int,input().split())) for _ in range(m)]

bc.sort(key = lambda x: x[1],reverse = True)
i = 0
j = 0
ad = []
while i < n and j < m:
    ad.extend([bc[j][1]]*bc[j][0])
    i += bc[j][0]
    j += 1
    
if len(ad) < n:
    ad.extend([0]*(n-len(ad)))

a.sort(reverse = True)

i = 0
j = 0
k = 0
ans = 0
while k < n :
    if a[i] > ad[j]:
        ans += a[i]
        i += 1
        k += 1
    else:
        ans += ad[j]
        j += 1
        k += 1
  
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [[] for _ in range(n)]
color = [0]*n
for _ in range(n-1):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append((b,c))
  tree[b].append((a,c))
  
  
def dfs(i,before,cost):
  if cost == 1:
    color[i] = 1
  for j in tree[i]:
    if j[0] == before:
      continue
    dfs(j[0],i,(cost + j[1])%2 )
    
dfs(0,-1,0)

for i in range(n):
  print(color[i])
  



Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
tree = [[] for _ in range(n)]
color = [0]*n
for _ in range(n-1):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append((b,c))
  tree[b].append((a,c))
  
  
def dfs(i,before,cost):
  if cost == 1:
    color[i] = 1
  for j in tree[i]:
    if j[0] == before:
      continue
    dfs(j[0],i,(cost + j[1])%2 )
    
dfs(0,-1,0)

for i in range(n):
  print(color[i])

Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [[] for _ in range(n)]
color = [0]*n
for _ in range(n-1):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append((b,c))
  tree[b].append((a,c))
  
  
def dfs(i,before,cost):
  if cost%2 == 1:
    color[i] = 1
  for j in tree[i]:
    if j[0] == before:
      continue
    dfs(j[0],i,cost + j[1])
    
dfs(0,-1,0)

for i in range(n):
  print(color[i])
  



Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
tree = [[] for _ in range(n)]
color = [0]*n
for _ in range(n-1):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append((b,c))
  tree[b].append((a,c))
  
  
def dfs(i,before,cost):
  if cost == 1:
    color[i] = 1
  for j in tree[i]:
    if j[0] == before:
      continue
    dfs(j[0],i,(cost + j[1])%2 )
    
dfs(0,-1,0)

for i in range(n):
  print(color[i])
Buggy python submission (verdict: Runtime Error):
lis = []
for _ in range(5):
  lis.append(int(input()))
mod = []
for i in lis:
  mod.append(i%10)
k = min(mod) if min(mod) != 0 else sorted(set(mod))[1]
ans = 0
for i in range(5):
  if i == mod.index(k):
    ans += lis[i]
  else:
    ans += ((lis[i]+9)//10)*10
print(ans)
    

Fixed submission:
lis = []
for _ in range(5):
  lis.append(int(input()))
mod = []
for i in lis:
  mod.append(i%10)
if mod == [0,0,0,0,0]:
  print(sum(lis))
else:
  k = min(mod) if min(mod) != 0 else sorted(set(mod))[1]
  ans = 0
  for i in range(5):
    if i == mod.index(k):
      ans += lis[i]
    else:
      ans += ((lis[i]+9)//10)*10
  print(ans)
Buggy python submission (verdict: Runtime Error):
b = input()
b_dic = {"A":"T","T":"A","C":"G","G":"c"}
print(b-dic[b])

Fixed submission:
b = input()
b_dic = {"A":"T","T":"A","C":"G","G":"C"}
print(b_dic[b])
Buggy python submission (verdict: Runtime Error):
S = input()
atcg = ["A","T","C","G"]
num_lis =[]
for idx,s in enumerate(S):
  if s in atcg:
    num_lis.append(idx)

ans_lis =[]
x = 0

for i in range(len(S)):
  if i in num_lis:
    x += 1
  else:
    ans_lis.append(x)
    x = 0
    
print(max(ans_lis))
    

Fixed submission:
s = input()
cnt = [0]*(len(s))
for i in range(len(s)):
  for j in range(i,len(s)):
    if s[j] in ["A","C","G","T"]:
      cnt[i] += 1
    else:
      break

print(max(cnt))
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = list(input())
l = len(s)
for i in range(l-1):
  if s[i] == "A" and s[i+1] == "C":
    s[i]= "a"


lis = [0]*(l+1)
for i in range(l+1):
  lis[i] = s[:i].count("a")


for i in range(q):
  l,r = map(int,input().split())
  print(lis[r-1]-lis[l-1])
  
  



Fixed submission:
n,q = map(int,input().split())
s = list(input())
l = len(s)
for i in range(l-1):
  if s[i] == "A" and s[i+1] == "C":
    s[i]= "a"


lis = [0]*(l+1)
for i in range(1,l+1):
  lis[i] = lis[i-1]+(1 if s[i-1]=="a" else 0)


for i in range(q):
  l,r = map(int,input().split())
  print(lis[r-1]-lis[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = list(input())
l = len(s)
for i in range(l-1):
  if s[i] == "A" and s[i+1] == "C":
    s[i]= "a"


lis = [0]*(l+1)
for i in range(l+1):
  lis[i] = s[:i].count("a")


for i in range(q):
  l,r = map(int,input().split())
  print(lis[r-1]-lis[l-1])
  
  



Fixed submission:
n,q = map(int,input().split())
s = list(input())
l = len(s)
for i in range(l-1):
  if s[i] == "A" and s[i+1] == "C":
    s[i]= "a"


lis = [0]*(l+1)
for i in range(1,l+1):
  lis[i] = lis[i-1]+(1 if s[i-1]=="a" else 0)


for i in range(q):
  l,r = map(int,input().split())
  print(lis[r-1]-lis[l-1])
Buggy python submission (verdict: Runtime Error):
zn,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[0])
ans = 0
for i in range(n):
  while ab[i][1] > 0 and m> 0:
    m -= 1
    ab[i][1] -= 1
    ans += ab[i][0]
    
print(ans)
  

Fixed submission:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[0])
ans = 0
for i in range(n):
  while ab[i][1] > 0 and m> 0:
    m -= 1
    ab[i][1] -= 1
    ans += ab[i][0]
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
ans = 0
for i in range(a,b+1):
  ans = ans ^ i
print(ans)
  

Fixed submission:
a,b = map(int,input().split())
def xor(X):
  if X%2== 0:
    i = 0 if (X//2)%2==0 else 1
    return X ^ i
  else:
    i = 0 if ((X+1)//2)%2==0 else 1
    return i
A = xor(a-1)
B = xor(b)
print(A ^ B)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

n,m = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(m)]
class Unionfind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1]*n
        
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return 
                
        if self.parents[x] > self.parents[y]:
            x ,y = y,x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def size(self,x):
        return -self.parents[self.find(x)]
    
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x < 0]
 
ans = [n*(n-1)//2]
island = Unionfind(n)
for a,b in reversed(AB[1:]):
    island.union(a-1,b-1)
    num = [island.size(r) for r in island.roots()]
    cnt = 0
    for v,w in combinations(num,2):
      cnt += v*w
    ans.append(cnt)
        
for a in reversed(ans):
    print(a)
    
    
    

Fixed submission:
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(m)]
class Unionfind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1]*n
        
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return 
                
        if self.parents[x] > self.parents[y]:
            x ,y = y,x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def size(self,x):
        return -self.parents[self.find(x)]
      
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
ans = [n*(n-1)//2]
island = Unionfind(n)
for a,b in reversed(AB[1:]):
  if island.same(a-1,b-1):
    cnt = ans[-1]
  else:
    cnt = ans[-1]-island.size(a-1)*island.size(b-1)
    island.union(a-1,b-1)
  ans.append(cnt)
        
for a in reversed(ans):
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n,W = map(int,input().split())
table = [[0]*(W+1) for _ in range(n+1)]
for i in range(n):
  w,v = map(int,input().split())
  for k in range(W+1):
    if k < w:
      table[i+1][k] = table[i][k]
    else:
      table[i+1][k] = max(table[i][k],table[i][k-w]+v)

print(table[n][W])
  
  

Fixed submission:
n,W = map(int,input().split())
table = [[0]*(W+1) for _ in range(n+1)]
for i in range(n):
  w,v = map(int,input().split())
  for k in range(W+1):
    if k < w:
      table[i+1][k] = table[i][k]
    else:
      table[i+1][k] = max(table[i][k],table[i][k-w]+v)

print(table[n][W])
Buggy python submission (verdict: Runtime Error):
x - int(input())
if x in [3,5,7]:
  print('YES')
else:
  print('NO')

Fixed submission:
x = int(input())
if x in [3,5,7]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
import math

n,m = map(int,input().split())
m_div = []
for i in range(1,math.ceil(math.sqrt(m)+1)):
  if m%i ==0:
    m_div.extend([i,m//i])
m_div = list(set(m_div))
m_div.sort(reverse = True)
for div in m_div:
  if div >= n:
    ans = m//div
  else:
    break
print(ans)
    

Fixed submission:
n = int(input())
if n ==1:
  print("Hello World")
else:
  a = int(input())
  b = int(input())
  print(a+b)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
bit = int(bin(2**(n-1)-1),2)
ab = []
for _ in range(m):
  ab.append(list(map(int,input().split())))
ab.sort(key = lambda x:(x[0],x[1]))

ans = 0
for a_b in ab: 
  a_b_bit = int(bin(2**(a_b[1]-1)-2**(a_b[0]-1)),2)
  if bit & a_b_bit !=0:
    bit = bit & a_b_bit
  else:
    ans += 1
    bit = a_b_bit

print(ans+1)
    

Fixed submission:
n,m = map(int,input().split())
ab = []
for _ in range(m):
  ab.append(list(map(int,input().split())))
ab.sort(key = lambda x:x[1])

bridge = [1]*(n-1)
x = -1
for a_b in ab:
  if a_b[0] <= x:
    pass
  else:
    x = a_b[1]-1
    bridge[x-1]=0

print(bridge.count(0))
Buggy python submission (verdict: Runtime Error):
N, i = map(int, intput().split())
print(N-i+1)

Fixed submission:
N, i = map(int, input().split())
print(N-i+1)
Buggy python submission (verdict: Time Limit Exceeded):
N, c = map(int, input().split())
D = [[int(i) for i in input().split()] for j in range(c)]
C = [[int(i) for i in input().split()] for j in range(N)]
A = [[0 for i in range(c)] for j in range(3)]
for i in range(N):
    for j in range(N):
        for k in range(c):
            A[(i+j)%3][k] += D[C[i][j]-1][k]

ans = 1e9
for i in range(c):
    for j in range(i):
        for k in range(j):
            for l in range(3):
                ans = min(ans, A[l][i]+A[(l+1)%3][j]+A[(l+2)%3][k],
                          A[l][i]+A[(l-1)%3][j]+A[(l-2)%3][k])
print(ans)


Fixed submission:
N, c = map(int, input().split())
D = [[int(i) for i in input().split()] for j in range(c)]
C = [[int(i) for i in input().split()] for j in range(N)]
A = [[0 for i in range(c)] for j in range(3)]
for i in range(N):
    for j in range(N):
        for k in range(c):
            A[(i+j)%3][k] += D[C[i][j]-1][k]

ans = 1e9
for i in range(c):
    for j in range(i):
        for k in range(j):
            for l in range(3):
                ans = min(ans, A[l][i]+A[(l+1)%3][j]+A[(l+2)%3][k],
                          A[l][i]+A[(l-1)%3][j]+A[(l-2)%3][k])
print(ans)
Buggy python submission (verdict: Runtime Error):
input()
print(len(set([input().split()]))

Fixed submission:
input()
n = len(set(input().split()))
print("Three" if n == 3 else "Four")
Buggy python submission (verdict: Runtime Error):
s = input()
s[3] = '8'
print(s)

Fixed submission:
s = input()
print("2018"+s[4:])
Buggy python submission (verdict: Runtime Error):
W = map(int,input().split())
if sum(W[:2]) < sum(W[2:]):
  print("Right")
elif sum(W[:2]) > sum(W[2:]):
  print("Left")
else:
  print("Balanced")

Fixed submission:
W = list(map(int,input().split()))
if sum(W[:2]) < sum(W[2:]):
  print("Right")
elif sum(W[:2]) > sum(W[2:]):
  print("Left")
else:
  print("Balanced")
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
print(min(n＊a,b))


Fixed submission:
n,a,b = map(int,input().split())
print(min(n*a,b))
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(min([sum(list(map(int,input().split()))) for j in range(N)])

Fixed submission:
N = int(input())
print(min([sum(list(map(int,input().split()))) for j in range(N)]))

Buggy python submission (verdict: Runtime Error):
N = int(input())
print(min(sum(list(map(int,input().split())))))

Fixed submission:
N = int(input())
print(min([sum(list(map(int,input().split()))) for j in range(N)]))

Buggy python submission (verdict: Runtime Error):
N = int(input())
print(min(sum(*map(int,input().split()))))

Fixed submission:
N = int(input())
print(min([sum(list(map(int,input().split()))) for j in range(N)]))

Buggy python submission (verdict: Runtime Error):
N = int(input())
print(min(sum(map(int,input().split()))))

Fixed submission:
N = int(input())
print(min([sum(list(map(int,input().split()))) for j in range(N)]))
Buggy python submission (verdict: Runtime Error):
S = input()
if(len(S) >= 4 and A[:4] == "YAKI"):
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
if(len(S) >= 4 and S[:4] == "YAKI"):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
S = input()
if(A[:4] == "YAKI"):
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
if(len(S) >= 4 and S[:4] == "YAKI"):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
ws = []
vs = []

for i in range(N):
	w, v = map(int, input().split())
	ws.append(w)
	vs.append(v)

w1 = ws[0]
s = 0

for i in range(N):
	ws[i] -= w1
	s += ws[i]

dp = [[[0]*(s+1) for i in range(N+1)] for k in range(N)]
for k in range(N):
	for i in range(1,N+1):
		for j in range(s+1):
			if j >= ws[i-1]:
				dp[k][i][j] = max(dp[k-1][i-1][j-ws[i-1]]+vs[i-1], dp[k][i-1][j])
			else:
				dp[k][i][j] = max(dp[k][i][j], dp[k][i-1][j])
			if j > 0:
				dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
ans = 0
for k in range(N):
	if W < (k+1)*w1:
		break
	ans = max(ans, dp[k][N][min(W-(k+1)*w1, s)])
print(ans)
from sys import stderr
print(dp, file=stderr)

Fixed submission:
N, W = map(int, input().split())
ws = []
vs = []

for i in range(N):
	w, v = map(int, input().split())
	ws.append(w)
	vs.append(v)

w1 = ws[0]
s = 0

for i in range(N):
	ws[i] -= w1
	s += ws[i]

dp = [[[0]*(s+1) for i in range(N+1)] for k in range(N)]
for k in range(N):
	if (k+1)*w1 > W:
		break
	for i in range(1,N+1):
		for j in range(s+1):
			if j >= ws[i-1]:
				dp[k][i][j] = max(dp[k-1][i-1][j-ws[i-1]]+vs[i-1], dp[k][i-1][j])
			else:
				dp[k][i][j] = max(dp[k][i][j], dp[k][i-1][j])
			if j > 0:
				dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
ans = 0
for k in range(N):
	if W < (k+1)*w1:
		break
	ans = max(ans, dp[k][N][min(W-(k+1)*w1, s)])
print(ans)
from sys import stderr
print(dp, file=stderr)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input())
if b-a == c-b:
  print("YeS")
else:
  print("NO")

Fixed submission:
a,b,c = map(int,input().split())
if b-a == c-b:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
mod = 10**9 + 7
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
ans = 0
for i in range(n-1):
	for j in range(m-1):
		ans += abs(X[i+1] - X[i])%mod * abs(Y[j+1] - Y[j])%mod * ((i+1)%mod) * ((n-i-1)%mod) * ((j+1)%mod) * ((m-j-1)%mod)
		ans %= mod
print(ans)

Fixed submission:
n, m = map(int, input().split())
mod = 10**9 + 7
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
ans = 0
for i in range(n):
	ans += X[i]*(n-2*i-1)%mod
t = 0
for j in range(m):
	t += Y[j]*(m-2*j-1)%mod
ans *= t%mod
print(ans%mod)
Buggy python submission (verdict: Runtime Error):

N, M = map(int, input().split())
A = []
for i in range(N):
	A.append(input())
B = []
for i in range(M):
	B.append(input())
t = 0
for i in range(N):
	for j in range(N-M):
		t = 0
		for k in range(M):
			if t:
				break
			for l in range(M):
				if A[i+k][j+l] != B[k][l]:
					t = 1
					break
		else:
			if A[i+k][j+l] == B[k][l]:
				print("Yes")
				exit()
print("No")

Fixed submission:
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
f = 0
for i in range(N-M+1):
	for j in range(N-M+1):
		for k in range(M):
			if f:
				f = 0
				break
			for l in range(M):
				if A[i+k][j+l] != B[k][l]:
					f = 1
					break
			else:
				if k == l == M-1:
					print("Yes")
					exit()
print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
B = [[] for _ in range(N)]
unchecked = [i for i in range(N)]
for i in range(1,N):
	t = int(input()) - 1
	B[t].append(i)
ans = [0]*N
for i in range(N):
	if not B[i]:
		unchecked.remove(i)
while 0 in unchecked:
	for i in unchecked:
			f = 0
			C = []
			for a in B[i]:
				if a in unchecked:
					f = 1
					break
				else:
					C.append(ans[a])
			if not f:
				C.sort()
				C.reverse()
				l = len(C)
				ans[i] = max([j+C[j]+1 for j in range(l)])
				unchecked.remove(i)
print(ans[0])

Fixed submission:
N = int(input())
ans = 0
ab = []
for _ in range(N):
	ab.append([int(i) for i in input().split()])
ab.reverse()
for A,B in ab:
	ans = ans + (-A-ans) % B
print(ans)
Buggy python submission (verdict: Runtime Error):
A = [int(i) for i in input().split()]

ans = 0
ans += B[0]
if min(B[1:]) == 0:
	for b in B[1:]:
		if b%2 == 0:
			ans += 2
elif not sum([i%2 for i in B[1:]])%3:
	ans += sum(B[1:])
else:
	ans += sum(B[1:])-1
print(ans)


Fixed submission:
A = [int(i) for i in input().split()]
B = [A[1],A[0],A[3],A[4]]
ans = 0
ans += B[0]
if min(B[1:]) == 0:
	for b in B[1:]:
		ans += b//2*2
elif not sum([i%2 for i in B[1:]])%3:
	ans += sum(B[1:])
else:
	ans += sum(B[1:])-1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import hypot
def dijkstra(matrix):
    from heapq import heappush, heappop
    n = len(matrix)
    inf = 10**10
    hq = []
    ans = [inf]*n
    ans[0] = 0
    heappush(hq, (0, 0))
    while hq:
        d, p = heappop(hq)
        for i in range(n):
            if ans[p] == d and p != i and d + matrix[p][i] < ans[i]:
                ans[i] = d + matrix[p][i]
                heappush(hq, (ans[i], i))
    return ans[n-1]

x_s, y_s, x_t, y_t = map(int, input().split())
N = int(input())
xyr = [(x_s,y_s,0)]
for i in range(N):
    xyr.append(tuple(int(i) for i in input().split()))
xyr.append((x_t,y_t,0))
graph = [[0]*(N+2) for j in range(N+2)]

for i in range(N+2):
    for j in range(i,N+2):
        graph[i][j] = max(hypot((xyr[i][1]-xyr[j][1]), (xyr[i][0]-xyr[j][0])) - xyr[i][2] - xyr[j][2], 0)
        graph[j][i] = graph[i][j]

print(dijkstra(graph))

Fixed submission:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(N-1):
	if a[i] + a[i+1] > x:
		d = a[i] + a[i+1] - x
		if d <= a[i+1]:
			a[i+1] -= d
			ans += d
		else:
			a[i] -= d - a[i+1]
			a[i+1] = 0
			ans += d
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import sqrt
inf = 10**10
x_s, y_s, x_t, y_t = map(int, input().split())
N = int(input())
xyr = []
for i in range(N):
	x_i, y_i, r_i = map(int, input().split())
	xyr.append((x_i, y_i, r_i))
p = (x_s, y_s)
goal = (x_t, y_t)
ans = 0
while p != goal and xyr:
	D = inf
	for i in range(N):
		x, y, r = xyr[i]
		d = sqrt((x-p[0])**2+(y-p[1])**2) - 2*r
		if d < D:
			j = i
			D = d
	d = sqrt((goal[0]-p[0])**2+(goal[1]-p[1])**2)
	if d < D:
		ans += d
		p = goal
	else:
		x, y, r = xyr.pop(j)
		p = (x, y)
		N -= 1
		ans += D

if p != goal:
	d = sqrt((goal[0]-p[0])**2+(goal[1]-p[1])**2)
	ans += d

print(max(0, ans))
	

Fixed submission:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(N-1):
	if a[i] + a[i+1] > x:
		d = a[i] + a[i+1] - x
		if d <= a[i+1]:
			a[i+1] -= d
			ans += d
		else:
			a[i] -= d - a[i+1]
			a[i+1] = 0
			ans += d
print(ans)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
ans = 0
for i in range(h):
	a = imput()
	ans += a.count("#")
if ans == h + w - 1:
	print("Possible")
else:
	print("Impossible")

Fixed submission:
h, w = map(int, input().split())
ans = 0
for i in range(h):
	a = input()
	ans += a.count("#")
if ans == h + w - 1:
	print("Possible")
else:
	print("Impossible")