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

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
mod = 10**9+7

def main():
  
  n,k = map(int,input().split())
  sl = [0]*(n+1)
  tree = [[] for i in range(n+1)]
  
  for i in range(n-1):
    a,b = map(int,input().split())
    tree[a] += (b,)
    tree[b] += (a,)

  def dfs(x,depth,k):
    sl[x] = 1
    child = 0
    ans = 1
    for i in tree[x]:
      if sl[i] == 0:
        ans *= dfs(i,depth+1,k)
        child += 1
    if depth == 0:
      for x in range(k-1, k-1-child, -1):
        ans = ans * x % mod   
    else:    
      for x in range(k-2, k-2-child, -1):
        ans = ans * x % mod
    ans %= mod
    return ans

  print(dfs(1,0,k)*k%mod)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
n,k = map(int,input().split())
sl = [0]*n
dl = [0]*n
tree = [[] for i in range(n)]
mod = 10**9+7

for i in range(n-1):
  a,b = map(int,input().split())
  tree[a-1] += [b-1]
  tree[b-1] += [a-1]

def perm(n, r):
    return math.factorial(n) // math.factorial(n - r)

def dfs(x,depth,k):
  sl[x] = 1
  dl[depth] += 1
  child = 0
  ans = 1
  for i in tree[x]:
    if sl[i] == 0:
      ans *= dfs(i,depth+1,k)
      ans %= mod
      child += 1
  if depth == 0:
    ans *= perm(k-1,child)
    ans %= mod
  else:
    ans *= perm(k-2,child)
    ans %= mod
  return ans

print(dfs(0,0,k)*k%mod)
Problem p03014 (python)

Fixed submission:
import numpy as np
h,w = map(int,input().split())
ar = np.array([list(input()) for _ in range(h)]) == '.'
#print(ar)
l = np.zeros((h,w),dtype=int)
r = np.zeros((h,w),dtype=int)
u = np.zeros((h,w),dtype=int)
d = np.zeros((h,w),dtype=int)

for i in range(h):
  u[i] = (u[i-1]+1)*ar[i]
  #print(u)
  d[-i-1] = (d[-i]+1)*ar[-i-1]
  #print(d)
  
for j in range(w):
  l[:,j] = (l[:,j-1]+1)*ar[:,j]
  #print(l)
  r[:,-j-1] = (r[:,-j]+1)*ar[:,-j-1]
  #print(r)
print(np.max(u+d+l+r)-3)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
h,w = map(int,input().split())
l=['#'*(w+2)]+['#'+input().strip()+'#' for i in range(h)]+['#'*(w+2)]
dp = np.zeros((h+2,w+2,2),dtype=int)
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x,y,0] = dfsw(x,y+1,cnt)
    return dp[x,y,0]
  else:
    dp[x,y,0] = cnt
    return dp[x,y,0]

def dfsh(x,y,cnt):
  if l[x+1][y] == '.':
    cnt += 1
    dp[x,y,1] = dfsh(x+1,y,cnt)
    return dp[x,y,1]
  else:
    dp[x,y,1] = cnt
    return dp[x,y,1]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      if dp[i,j,0] == 0:
        dfsw(i,j,1)
      if dp[i,j,1] == 0:
        dfsh(i,j,1)
      ans = max(ans, sum(dp[i,j]) - 1)
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
l=['#'*(w+2)]+['#'+input()+'#' for i in range(h)]+['#'*(w+2)]
dp = [[[0]*2 for i in range(w+2)] for i in range(h+2)]
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x][y][0] = dfsw(x,y+1,cnt)
    return dp[x][y][0]
  else:
    dp[x][y][0] = cnt
    return dp[x][y][0]

def dfsh(x,y,cnt):
  if l[x+1][y] == '.':
    cnt += 1
    dp[x][y][1] = dfsh(x+1,y,cnt)
    return dp[x][y][1]
  else:
    dp[x][y][1] = cnt
    return dp[x][y][1]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][0] == 0:
      dfsw(i,j,1)
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][1] == 0:
      dfsh(i,j,1)
    
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans, sum(dp[i][j]) - 1)
print(ans)
Problem p03050 (python)

Fixed submission:
import math
n = int(input())
ans = 0

if n > 2:
  ans += n-1

for i in range(2,math.ceil(n**0.5)+1):
  if n % i == 0:
    j = n // i
    if n % (i-1) == n // (i-1):
      ans += i-1
    if i != j > 1 and n % (j-1) == n // (j-1) :
      ans += j-1
  
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ans = 0

if n > 2:
  ans += n-1

for i in range(2,math.ceil(n**0.5)+1):

  if n % i == 0:
    j = n // i
    if n % (i-1) == n // (i-1):
      ans += i-1
    if n % (j-1) == n // (j-1) and i != j:
      ans += j-1
  
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ans = 0

if n > 2:
  ans += n-1

for i in range(2,math.ceil(n**0.5)+1):

  if n % i == 0:
    j = n // i
    if n % (i-1) == n // (i-1):
      ans += n-1
    if n % (j-1) == n // (j-1) and i != j:
      ans += j-1
  
print(ans)
Problem p03076 (python)

Fixed submission:
li = [int(input()) for i in range(5)]
al = []
ans = 0
for i in li:
  if i % 10 != 0:
    al.append(i % 10) 
  ans += i // 10
ans *= 10
if len(al) > 0:
  ans += min(al) + (len(al) - 1)*10
print(ans)

Buggy submission (verdict: Runtime Error):
an = [int(input()) for i in range(5)]
total = 0

for i in range(5):
  tot = (an[i] // 10) * 10
  an[i] -= tot
  total += tot
  if an[i] == 0:
    del an[i]
if len(an) > 0:
  total += min(an) + (len(an) - 1)*10
print(total)

Buggy submission (verdict: Runtime Error):
an = [int(input()) for i in range(5)]
total = 0

for i in range(5):
  tot = (an[i] // 10) * 10
  an[i] -= tot
  total += tot
  if an[i] == 0:
    del an[i]
if an:
  total += min(an) + (len(an) - 1)*10
print(total)

Buggy submission (verdict: Runtime Error):
an = [int(input()) for i in range(5)]
total = 0

for i in range(5):
  tot = (an[i] // 10) * 10
  an[i] -= tot
  total += tot
  if an[i] == 0:
    del an[i]
    
total += min(an) + (len(an) - 1)*10
print(total)
Problem p03078 (python)

Fixed submission:
import heapq

X,Y,Z,K = (int(i) for i in input().split())
a = [-int(i) for i in input().split()]
b = [-int(i) for i in input().split()]
c = [-int(i) for i in input().split()]
q = []
S = set()
a.sort()
b.sort()
c.sort()

heapq.heappush(q,(a[0]+b[0]+c[0],0,0,0))

for i in range(K):
  p,i,j,k=heapq.heappop(q)
  print(-p)
  if i+1 < X and not((i+1,j,k) in S):
    S.add((i+1,j,k))
    heapq.heappush(q,(a[i+1]+b[j]+c[k],i+1,j,k))
  if j+1 < Y and not((i,j+1,k) in S):
    S.add((i,j+1,k))
    heapq.heappush(q,(a[i]+b[j+1]+c[k],i,j+1,k))
  if k+1 < Z and not((i,j,k+1) in S):
    S.add((i,j,k+1))
    heapq.heappush(q,(a[i]+b[j]+c[k+1],i,j,k+1))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ans = [0] * (X*Y*Z)
cnt = 0
for i in ax:
  for j in by:
    for k in cz:
      ans[cnt] = i + j + k
      cnt += 1
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ans = [0] * max(3000,X*Y*Z)
cnt = 0
for i in ax:
  for j in by:
    for k in cz:
      ans[cnt] = i + j + k
      cnt += 1
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ans = [0] * min(3000,X*Y*Z)
cnt = 0
for i in ax:
  for j in by:
    for k in cz:
      ans[cnt] = i + j + k
      cnt += 1
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ans = [0] * 3000
cnt = 0
for i in ax:
  for j in by:
    for k in cz:
      ans[cnt] = i + j + k
      cnt += 1
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X,Y,Z,K = (int(i) for i in input().split())
ax = [int(i) for i in input().split()]
by = [int(i) for i in input().split()]
cz = [int(i) for i in input().split()]
ans = [0] * (X*Y*Z)
cnt = 0
for i in ax:
  for j in by:
    for k in cz:
      ans[cnt] = i + j + k
      cnt += 1
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])
Problem p03103 (python)

Fixed submission:
N,M = (int(i) for i in input().split())
dic = {}
drink = M
money = 0
for i in range(N):
  a,b = (int(i) for i in input().split())
  if a not in dic:
    dic[a] = b
  else:
    dic[a] += b
c = sorted(dic.keys())
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)

Buggy submission (verdict: Runtime Error):
N,M = (int(i) for i in input().split())
dic = {}
drink = M
money = 0
for i in range(N):
  a,b = (int(i) for i in input().split())
  dic[a] += b
c = sorted(dic.keys())
print(c)
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)
Problem p03552 (python)

Fixed submission:
n,z,w = map(int,input().split())
a = [int(i) for i in input().split()]

if n == 1:
  print(abs(a[-1]-w))
else:
  print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))

Buggy submission (verdict: Runtime Error):
n,z,w = map(int,input().split())
a = [int(i) for i in input().split()]

print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))
Problem p03569 (python)

Fixed submission:
s = input()
lens = len(s)
l = 0
r = lens - 1
cnt = 0
while l != r:
  if s[l] == s[r]:
    l += 1
    r -= 1
    if l > r:
      break
  elif s[l] == 'x':
    cnt += 1
    l += 1
  elif s[r] == 'x':
    cnt += 1
    r -= 1
  else:
    print(-1)
    exit()
print(cnt)

Buggy submission (verdict: Runtime Error):
s = input()
lens = len(s)
l = 0
r = lens - 1
cnt = 0
while l != r:
  if s[l] == s[r]:
    l += 1
    r -= 1
  elif s[l] == 'x':
    cnt += 1
    l += 1
  elif s[r] == 'x':
    cnt += 1
    r -= 1
  else:
    print(-1)
    exit()
print(cnt)
Problem p03592 (python)

Fixed submission:
n,m,k = map(int,input().split())

for i in range(m+1):
  for j in range(n+1):
    if n*i + m*j - 2*i*j == k:
      print('Yes')
      exit()
print('No')

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

for i in range(m+1):
  if k - n*i == 0 or (k - n*i > 0 and (k - n*i) % (m - 2*i) == 0):
    print('Yes')
    exit()
  elif k - n*i < 0:
    print('No')
    exit()
print('No')

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

for i in range(m+1):
  if k - n*i < 0:
    print('No')
    exit()
  if (k - n*i) % (m - 2*i) == 0:
    print('Yes')
    exit()
Problem p03608 (python)

Fixed submission:
from scipy.sparse import*
from itertools import*
n,m,r = map(int,input().split())
R = [int(i)-1 for i in input().split()]
cost = [[0]*n for i in range(n)]
ans = 10**9
for j in range(m):
  a,b,c = map(int,input().split())
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c

Co = csgraph.floyd_warshall(csr_matrix(cost))

for v in permutations(R):
  temp = 0
  for i in range(1,r):
    temp += Co[v[i-1]][v[i]]
  ans = min(ans,temp)
print(int(ans))

Buggy submission (verdict: Runtime Error):
from scipy.sparse import*
from itertools import*
n,m,r = map(int,input().split())
R = [int(i)-1 for i in input().split()]
cost = [[0]*n for i in range(n)]
ans = 10**9
for j in range(m):
  a,b,c = map(int,input().split())
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c

Co = csgraph.shortest_path(csr_matrix(cost))

for v in permutations(R):
  temp = 0
  for i in range(1,r):
    temp += Co[v[i-1]][v[i]]
  ans = min(ans,temp)
print(int(ans))
Problem p03695 (python)

Fixed submission:
input()
an = [int(i) for i in input().split()]
score = [0]*13
ans = 0

for i in an:
  score[i//400] += 1   
for i in score[:8]:
  if i:
    ans += 1

k = sum(score[8:])

if ans == 0 and k:
  print(1,k)
else:
  print(ans,ans+k)

Buggy submission (verdict: Runtime Error):
n = int(input())
an = [int(i) for i in input().split()]
score = [0]*9
ans = 0

for i in an:
  score[i//400] += 1

for i in score[:8]:
  if i:
    ans += 1
print(ans,ans+score[8])
Problem p04030 (python)

Fixed submission:
S = list(input())
final_str = []
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str))

Buggy submission (verdict: Runtime Error):
S = list(input())
final_str = []
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str)

Buggy submission (verdict: Runtime Error):
S = list(input())
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str)
Problem p02900 (python)

Fixed submission:
import math

A, B = [int(item) for item in input().split()]

def gdc(A, B):
    if B == 0:
        return A
    else:
        return gdc(B, A % B)

def chk_pn(num):
    flag = True
    if num  <= 3:
        pass
    else:
        for i in range(2, int(math.sqrt(num)) + 1):
            if num % i == 0:
                flag = False
                break
    return flag

def mk_factor(num):
    max_divisor = int(math.sqrt(num))+1
    divisor = 2
    factor_list = [1]

    while divisor <= max_divisor:
        if num % divisor == 0:
            factor_list.append(divisor)
            num /= divisor
        else:
            divisor += 1
    if num != 1.0:
        factor_list.append(num)
    return factor_list

GDC = gdc(A, B)
#pn_factor = [i for i in mk_factor(GDC) if chk_pn(i) is True]

print(len(set(mk_factor(GDC))))

Buggy submission (verdict: Runtime Error):
from sympy import sieve

def yakusuu(a):
    t = []
    for i in range(1,a+1):
        if a%i==0:
            t.append(i)
    return t

def kouyakusuu(a,b):
    t = []
    u = 0
    d = 0
    if a>b:
        u = a
        d = b
    else:
        u = b
        d = a
    for i in range(1,d+1):
        if u%i==0 and d%i==0:
            t.append(i)
    return t

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

#t = list(map(yakusuu,kouyakusuu(a,b)))
t = kouyakusuu(a,b)
sn = 0
for i in t:
    if i in sieve:
        sn += 1

sn += 1

ans = sn*(sn-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
from sympy import sieve

def yakusuu(a):
    t = []
    for i in range(1,a+1):
        if a%i==0:
            t.append(i)
    return t

def kouyakusuu(a,b):
    t = []
    u = 0
    d = 0
    if a>b:
        u = a
        d = b
    else:
        u = b
        d = a
    for i in range(1,d+1):
        if u%i==0 and d%i==0:
            t.append(i)
    return t

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

#t = list(map(yakusuu,kouyakusuu(a,b)))
t = kouyakusuu(a,b)
sn = 0
for i in t:
    if i in sieve:
        sn += 1

sn += 1

ans = sn*(sn-1)/2
print(ans)
Problem p02924 (python)

Fixed submission:
n = int(input())

print((n*(n-1)//2))

Buggy submission (verdict: Runtime Error):
n = int(input())

print((n(n-1)//2))

Buggy submission (verdict: Runtime Error):
n = int(input())

print(sum(list(range(n))))

Buggy submission (verdict: Runtime Error):
n = int(input())

p = list(reversed(list(range(1,n+1))))

r = set(range(1,n+1))

m = []

for i in range(n):
    f = True
    a = 1
    b = 1
    while f:
        while (a*p[i]-b)<=n and f:
            if a*p[i]-b in r:
                r.remove(a*p[i]-b)
                m.append((a*p[i]-b)%p[i])
                f = False
                break
            a += 1
        b += 1

print(sum(m))
Problem p02971 (python)

Fixed submission:
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = A[:]

copy.remove(maxa)

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)

Buggy submission (verdict: Runtime Error):
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = [l for l in A if l != maxa]

maxa2 = max(copy)

for i in A:
    if i == maxa:
        print(maxa2)
    else:
        print(maxa)

Buggy submission (verdict: Runtime Error):
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = [l for l in A if l != maxa]

maxa2 = max(copy)

for i in A:
    if i == max:
        print(maxa2)
    else:
        print(maxa)

Buggy submission (verdict: Runtime Error):
n = int(input())

A = []

for i in range(n):
    a = int(input())
    A.append(a)

maxa = max(A)

copy = A[:]

while True:
    if maxa in copy:
        copy.remove(maxa)
    else:
        break

maxa2 = max(copy)

for i in A:
    if i == max:
        print(maxa2)
    else:
        print(maxa)
Problem p03434 (python)

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

ans = 0
for i in range(n):
    if i%2==0:
        ans += a[i]
    else:
        ans -= a[i]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())

print((n(n-1)//2))
Problem p03471 (python)

Fixed submission:
n,y = map(int,input().split())
yukichi = -1
higuchi = -1
noguchi = -1
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            yukichi = i
            higuchi = j
            noguchi = n-i-j

print("{} {} {}".format(yukichi,higuchi,noguchi))

Buggy submission (verdict: Runtime Error):
yukichi = -1
higuchi = -1
noguchi = -1


def check(n,y,a,b,c):

    if y/1000 == n:
        global yukichi,higuchi,noguchi
        yukichi = a
        higuchi = b
        noguchi = n

    else:
        if y>=0:
            check(n-1,y-10000,a+1,b,c)
            check(n-1,y-5000,a,b+1,c)


n,y = map(int,input().split())

check(n,y,0,0,0)

print("{} {} {}".format(yukichi,higuchi,noguchi))

Buggy submission (verdict: Runtime Error):
yukichi = -1
higuchi = -1
noguchi = -1


def check(n,y,a,b,c):
    if n==0:
        if y==0:
            global yukichi,higuchi,noguchi
            yukichi = a
            higuchi = b
            noguchi = c
            
    else:
        check(n-1,y-10000,a+1,b,c)
        check(n-1,y-5000,a,b+1,c)
        check(n-1,y-1000,a,b,c+1)


n,y = map(int,input().split())

check(n,y,0,0,0)

print("{} {} {}".format(yukichi,higuchi,noguchi))
Problem p03854 (python)

Fixed submission:
import re
s = input()
m = re.fullmatch(r"(dreamer|dream|erase|eraser)+", s)

if m:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
flag = False
def check(sen,l,s):
    if len(sen)<l:
        check(sen+"dream",l,s)
        check(sen+"dreamer",l,s)
        check(sen+"erase",l,s)
        check(sen+"eraser",l,s)
    else:
        if sen==s:
            global flag
            flag = True

s = input()

check("",len(s),s)

if flag:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
flag = False
def check(sen,l,s):
    if len(sen)<l:
        check(sen+"dream",l,s)
        check(sen+"dreamer",l,s)
        check(sen+"erase",l,s)
        check(sen+"eraser",l,s)
    else:
        if sen==s:
            global flag
            flag = True

s = input()

check("",len(s),s)

if flag:
    print("yes")
else:
    print("no")

Buggy submission (verdict: Runtime Error):
flag = False
def check(sen,l,s):
    if len(sen)<l:
        check(sen+"dream",l,s)
        check(sen+"dreamer",l,s)
        check(sen+"erase",l,s)
        check(sen+"eraser",l,s)
    else:
        if sen==s:
            global flag
            flag = True

s = input()

check("",len(s),s)

if flag:
    print("yes")
else:
    print("no")
Problem p02952 (python)

Fixed submission:
a = int(input())

if a < 10:
  print(a)
elif a < 100:
  print(9)
elif a < 1000:
  print(a - 90)
elif a < 10000:
  print(909)
elif a < 100000:
  print(a - 90 - 9000)
elif a == 100000:
  print(90909)

Buggy submission (verdict: Runtime Error):
a = int(input())

if a < 10:
  print(a)
elif a < 100:
  print(9)
elif a < 1000:
  print(a - 90)
elif a < 10000:
  print(910)
elif a < 100000:
  print(a - 90 - 9000)
elif a = 100000:
  print(90909)
Problem p02957 (python)

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

if a > b:
    c = b
    b = a
    a = c
    
if (b - a) % 2 == 1:
    print('IMPOSSIBLE')
else:
    print((b + a) // 2)

Buggy submission (verdict: Runtime Error):
N = int(input())
monster = list(map(int, input().split()))
hero = list(map(int, input().split()))

total = 0
i = -1

for i in range(N + 1):
    if i == 0:
        if monster[0] < hero[0]:
            total += monster[0]
            hero[0] -= monster[0]
            monster[0] = 0
        else:
            total += hero[0]
            monster[0] -= hero[0]
            hero[0] = 0
            
    elif i < N:
        if monster[i] < hero[i - 1]:
            total += monster[i]
            hero[i - 1] -= monster[i]
            monster[i] = 0
        else:
            total += hero[i - 1]
            monster[i] -= hero[i - 1]
            hero[i - 1] = 0
            
            if monster[i] < hero[i]:
                total += monster[i]
                hero[i] -= monster[i]
                monster[i] = 0
            else:
                total += hero[i]
                hero[i] = 0
                monster[i] -= hero[i]
    else:
        if monster[N] < hero[N - 1]:
            total += monster[N]
        else:
            total += hero[N - 1]

print(total)

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

if a > b:
    c = b
    b = a
    a = c
    
if (b - a) % 2 == 1:
    print(IMPOSSIBLE)
else:
    print((b + a) // 2)
Problem p03543 (python)

Fixed submission:
s = input()
if s[1] == s[2] and s[2] == s[3]:
  print("Yes")
else:
  if s[0] == s[1] and s[1] == s[2]:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])


n = {1:0}

while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] < c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c

ans = 0
for a in range(0, h):
  for b in range(0, w):
    if wl[a][b] != -1:
      ans += n[wl[a][b]]

print(ans)
Problem p03546 (python)

Fixed submission:
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])
 
 
n = {1:0}
 
while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] <= c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c
 
ans = 0
for a in range(0, h):
  for b in range(0, w):
    if wl[a][b] != -1:
      ans += n[wl[a][b]]
 
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])
 
 
n = {1:0}
 
while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] < c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c
 
ans = 0
for a in range(0, h):
  for b in range(0, w):
    if wl[a][b] != -1:
      ans += n[wl[a][b]]
 
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = [int(i) for i in input().split()]
k = []
wl = []
  
for i in range(0, 10):
  k.append([int(i) for i in input().split()])
for i in range(0, h):
  wl.append([int(i) for i in input().split()])


n = {1:0}

while len(n) < 10:
  c = 1000
  mn = 10
  for a in n.keys():
    a2 = int(a)
    for b in range(0, 10):
      if not b in n:
        if k[b][a2] + n[a] < c:
          c = k[b][a2] + n[a]
          mn = b
  n[mn] = c

ans = 0
for a in range(0, h):
  for b in range(0, w):
    ans += n[wl[a][b]]

print(ans)