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

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N = int(sys.stdin.readline())
h = tuple(map(int, sys.stdin.readline().split()))
cost = [None]*N

def DP(n):
    if cost[n] != None:
        return cost[n]
    
    if n==0:
        return 0
    elif(n > 1):
        cost[n] = min(DP(n-1) + abs(h[n] - h[n-1]), DP(n-2) + abs(h[n] - h[n-2]))
        return cost[n]
    else:
        cost[n] = DP(n-1) + abs(h[n] - h[n-1])
        return cost[n]


print(DP(N-1))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

N = int(sys.stdin.readline())
h = tuple(map(int, sys.stdin.readline().split()))
cost = [None]*N

def DP(n):
    if cost[n] != None:
        return cost[n]
    
    if n==0:
        return 0
    elif(n > 1):
        cost[n] = min(DP(n-1) + abs(h[n] - h[n-1]), DP(n-2) + abs(h[n] - h[n-2]))
        return cost[n]
    else:
        cost[n] = DP(n-1) + abs(h[n] - h[n-1])
        return cost[n]


print(DP(N-1))

Buggy submission (verdict: Runtime Error):
N = int(input())
h = tuple(map(int, input().split()))
cost = [None]*N

def DP(n):
    if cost[n] != None:
        return cost[n]
    
    if n==0:
        return 0
    elif(n > 1):
        cost[n] = min(DP(n-1) + abs(h[n] - h[n-1]), DP(n-2) + abs(h[n] - h[n-2]))
        return cost[n]
    else:
        cost[n] = DP(n-1) + abs(h[n] - h[n-1])
        return cost[n]


print(DP(N-1))
Problem p02818 (python)

Fixed submission:
A, B, K = map(int, input().split())


if A>=K:
    A2=A-K
    B2=B
elif A+B>=K:
    A2=0
    B2=A+B-K
else:
    A2=B2=0
print(A2, B2)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

A2=A-K
if A2<0:
    B2=B+A2
    A2=0
print(A2, B2)
Problem p02886 (python)

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

kotae=0
for i in range(n):
  for j in range(i+1,n):
    kotae=kotae+d[i]*d[j]
print(kotae)

Buggy submission (verdict: Runtime Error):
n=int(input())
d=map(int,input().split())
d=list(d)
kotae=0
for i in range(n):
  for j in range(i+1,n):
    kotae=kotae+d[i]*d[i+j]
print(kotae)

Buggy submission (verdict: Runtime Error):
n=int(input())
d=map(int,input().split())
kotae=0
for i in range(n):
  for j in range(n-i-1):
    kotae=kotae+d[i]*d[j]
print(kotae)
Problem p02971 (python)

Fixed submission:
N=int(input())
lis=[]
for i in range(N):  
  lis.append(int(input()))
lis2=sorted(lis)
ma1=lis2[-1]
ma2=lis2[-2]

for i in range(N):
  if lis[i] == ma1:
    print(ma2)
  else:
    print(ma1)

Buggy submission (verdict: Runtime Error):
N=int(input())
lis=[]
for i in range(N):
  lis.append(int(input())
lis2=sorted(lis)
ma1=lis2[-1]
ma2=lis2[-2]

for i in range(N):
  if lis[i] == ma1:
    print(ma2)
  else:
    print(ma1)
Problem p02983 (python)

Fixed submission:
L2, R2= map(int, input().split())

L=L2%2019
R=R2%2019

hasamu=R2-L2
kotae=10000
if hasamu>2017:
  kotae=0
if L>R:
  kotae=0
else:
  for i in range(L,R):
    for j in range(i+1,R+1):
      seki=i*j
      amari=seki%2019
      if amari<kotae:
        kotae=amari
print(kotae)

Buggy submission (verdict: Runtime Error):
L2, R2= map(int, input().split())

L=L2%2019
R=R2%2019

hasamu=R2-L2
kotae=10000
if hasamu>2017:
  kotae=0
if L>R:
  kotae=0
else:
  for i in range(L,R):
    for j in range(i+1,R+1):
      seki=i*j
      amari=seki%2019
        if amari<kotae:
          kotae=amari
print(kotae)

Buggy submission (verdict: Runtime Error):
L2, R2= map(int, input().split())

L=L2%2019
R=R2%2019

hasamu=R2-L2
kotae=10000
if hasamu>2017:
  kotae=0
if L>R:
  kotae=0
else:
  for i in range(L,R):
  	for j in range(i+1,R+1):
    	seki=i*j
    	amari=seki%2019
    	if amari<kotae:
     		kotae=amari
print(kotae)

Buggy submission (verdict: Runtime Error):
L, R= map(int, input())

hasamu=R-L
kotae=10000
if hasamu>2017:
  kotae=0

for i in range(L,R):
  for j in range(i+1,R+1):
    seki=i*j
    amari=seki%2019
    if amari<kotae:
      kotae=amari
print(kotae)
Problem p03086 (python)

Fixed submission:
moto=input()
count=0
countlist=[0]
for i in range(len(moto)):
  if moto[i]=="A" or moto[i]=="T" or moto[i]=="G" or moto[i]=="C":
    count=count+1
  else:
    countlist.append(count)
    count=0
countlist.append(count)
kotae=max(countlist)
print(kotae)

Buggy submission (verdict: Runtime Error):
moto=input()
count=0
countlist=[]
for i in range(len(moto)):
  if moto[i]=="A":
    count=count+1
  elif moto[i]=="T":
    count=count+1
  elif moto[i]=="G":
    count=count+1
  elif moto[i]=="C":
    count=count+1
  else:
    countlist.append(count)
    count=0
kotae=max(countlist)
print(kotae)
Problem p03337 (python)

Fixed submission:
A,B=map(int,input().split())
wa=A+B
sa=A-B
seki=A*B
kotae=max(wa,sa,seki)
print(kotae)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input())
wa=A+B
sa=A-B
seki=A*B
kotae=max(wa,sa,seki)
print(kotae)
Problem p03359 (python)

Fixed submission:
M, D=map(int,input().split())
if D>=M:
  print(M)
else:
  print(M-1)

Buggy submission (verdict: Runtime Error):
M, D=map(int,input().split())
if D>=M:
  print(M)
elif:
  print(M-1)

Buggy submission (verdict: Runtime Error):
M, D=map(int,input()>split())
if D>=M:
  print(M)
elif:
  print(M-1)
Problem p02717 (python)

Fixed submission:
x, y, z = map(int, input().split())
print(z, x, y)

Buggy submission (verdict: Runtime Error):
x, y, z = map(int(input().split()))
print(z, x, y)
Problem p02837 (python)

Fixed submission:
n = int(input())
prf = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        prf[i].append((x-1, y))

res = 0
for i in range(1<<n):
    flg = True
    cnt = 0
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            cnt += 1
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            for x,y in prf[j]:
                if y == 0 and ( i >> x & 1 ) == 1:
                    flg = False
                if y == 1 and ( i >> x & 1 ) == 0:
                    flg = False
    if flg:
        res = max(res, cnt)
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
prf = [[] for _ in range(n)]
for i in range(n):
    a.append(int(input()))
    for _ in range(a[-1]):
        x, y = map(int, input().split())
        a[i].append((x-1, y))

res = 0
for i in range(1<<n):
    flg = True
    cnt = 0
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            cnt += 1
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            for x,y in a[j]:
                if y == 0 and ( i >> x & 1 ) == 1:
                    flg = False
                if y == 1 and ( i << x & 1 ) == 0:
                    flg = False
    if flg:
        ans = max(ans, cnt)
print(ans)
Problem p02838 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7

res = 0
for dig in range(61):
    one = 0
    for i in a:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

Buggy submission (verdict: Runtime Error):
import math
import numpy as np
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9+7

res = 0
for dig in range(61):
    one = 0
    for i in a:
        if i & (1<<dig) != 0:
            one += 1
    res = (res + one*(n-one)*(1<<dig))%MOD
print(res)

Buggy submission (verdict: Runtime Error):
import math
import numpy as np
n = int(input())
a = list(map(int, input().split()))

dgt = int(math.sqrt(max(a)))+1
dp = np.zeros(dgt)

for i in range(n):
    k = np.array(list( bin(a[i])[2:].zfill(dgt)), dtype=int)
    dp += k

res = 0
for i in range(dgt):
    if dp[-i-1] > 0:
        res += 2**i*int(dp[-i-1])*int(n-dp[-i-1]) % (10**9+7)
print(res)
Problem p02853 (python)

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

prize = 0
if x==1:
    prize += 300000
elif x==2:
    prize += 200000
elif x==3:
    prize += 100000

if y==1:
    prize += 300000
elif y==2:
    prize += 200000
elif y==3:
    prize += 100000

if x==1 and y==1:
    prize += 400000

print(prize)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[-1::-1]))

cost = sum_r[-1]
for i in range(n+1):
    cost = min(cost, abs(sum_l[i]-sum_r[n-i]))
print(cost)
Problem p02854 (python)

Fixed submission:
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[-1::-1]))

cost = sum_r[-1]
for i in range(n+1):
    cost = min(cost, abs(sum_l[i]-sum_r[n-i]))
print(cost)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

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

sum_l = [0]+list(accumulate(a))
sum_r = [0]+list(accumulate(a[:-1]))

cost = sum_r[-1]
for i in range(n+1):
    cost = min(cost, abs(sum_l[i]-sum_r[n-i]))
print(cost)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))

sum_par = 0
cur, prv = 0, 0
sum_a = sum(a)
mid = sum_a//2
cost = 0
if sum_a%2 != 0:
    cost += 1
    mid += 1
for i in range(n):
    cur += a[i]
    if abs(cur-mid) > abs(prv-mid):
        obj = prv
        break
    prv = cur

cost += abs(obj-mid)*2
print(cost)
Problem p02855 (python)

Fixed submission:
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
ans = []
vac = []
num = 1
flg = 0
for i in range(H):
    cnt = 0
    res = []
    a = input()
    if '#' in a:
        for b in a[:-1]:
            if b == '#':
                cnt += 1
                if cnt > 1:
                    num += 1
            res.append(num)
        ans.append(res)
        num += 1
    else:
        if i == 0:
            flg = 1
            continue
        else:
            vac.append(i)

if flg:
    ans.insert(0, ans[0])
for k in vac:
    ans.insert(k, ans[k-1])

for a in ans:
    print(*a)

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

H, W, K = map(int, input().split())
ans = []
clm = []
num = 1
flg = 0
for i in range(H):
    cnt = 0
    res = []
    a = input()
    if '#' in a:
        for b in a[:-1]:
            if b == '#':
                cnt += 1
                if cnt > 1:
                    num += 1
            res.append(num)
        ans.append(res)
        num += 1
    else:
        if i == 0:
            flg = 1
            continue
        else:
            ans.append(ans[-1])

if flg:
    ans.insert(0, ans[0])

for a in ans:
    print(*a)

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

H, W, K = map(int, input().split())
ans = []
clm = []
num = 1
flg = 0
for i in range(H):
    cnt = 0
    res = []
    a = input()
    print(a)
    if '#' in a:
        for b in a[:-1]:
            if b == '#':
                cnt += 1
                if cnt > 1:
                    num += 1
            res.append(num)
        ans.append(res)
        num += 1
    else:
        if i == 0:
            flg = 1
            continue
        if i == H-1:
            ans.append(ans[-1])

if flg:
    ans.insert(0, ans[0])

for i in range(H):
    print(*ans[i])
Problem p02918 (python)

Fixed submission:
n, k = map(int, input().split())
lr = list(input())
j = 0
counts = [0]
for i in range(n):
    if lr[j] == lr[i]:
        counts[-1] += 1
    else:
        j = i
        counts.append(1)

for _ in range(k):
    if len(counts)>=3:
        counts[0] += counts[1]+counts[2]
        del counts[1:3]
    elif len(counts)==2:
        counts[0] += counts[1]
        del counts[1]
    else:
        break

count = sum(counts) - len(counts)
print(count)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
lr = list(input())
j = 0
counts = [0]
for i in range(n):
    if lr[j] == lr[i]:
        counts[-1] += 1
    else:
        j = i
        counts.append(1)

for _ in range(k):
    if len(counts)>=3:
        counts[0] += counts[1]+counts[2]
        del counts[1:3]
    else:
        counts[0] += counts[1]
        del counts[1]

count = sum(counts) - len(counts)
print(count)
Problem p02985 (python)

Fixed submission:
import sys
from collections import deque
MOD = 10**9+7
input = sys.stdin.readline

N, K = map(int, input().split())
adj = [ [] for _ in range(N+1) ]
for _ in range(N-1):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

ans = 1
que = deque( [(1, 0, K)] )

while que:
    u, p, k = que.popleft()
    ans = (ans*k) % MOD

    if p == 0:
        k_next = K-1
    else:
        k_next = K-2

    for v in adj[u]:
        if v == p:
            continue
        que.append( (v, u, k_next) )
        k_next -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
MOD = 10**9+7
input = sys.stdin.readline

N, K = map(int, input().split())
adj = [ [] for _ in range(N+1) ]
for _ in range(N-1):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

ans = 1
que = deque( [1, 0, K] )

while que:
    u, p, k = que.popleft()
    ans = (ans*k) % MOD

    if p==0:
        k_next = k-1
    else:
        k_next = k-2
    for v in adj[u]:
        if v == p:
            continue
        que.append( (v, u, k_next) )
        k_next -= 1

print(ans)
Problem p02991 (python)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
INF = 10**9
to = [ [] for _ in range(n) ]
dist = [ [INF]*n for _ in range(3) ]
for _ in range(m):
    u, v = map(int, input().split())
    to[u-1].append(v-1)
s, t = map(int, input().split())
s -= 1; t -= 1

dist[0][s] = 0
que = deque([(s, 0)])
while que:
    u, prv = que.popleft()
    d = dist[prv][u]
    cur = (prv+1) % 3
    if prv == 2:
        d += 1
    for v in to[u]:
        if dist[cur][v] != INF:
            continue
        que.append((v, cur))
        dist[cur][v] = d
print( dist[0][t] if dist[0][t] < INF else -1 )

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

n, m = map(int, input().split())
INF = 10**7
to = [ [] for _ in range(n) ]
dist = [ [INF]*n for _ in range(3) ]
for _ in range(m):
    u, v = map(int, input().split())
    to[u-1].append(v-1)
s, t = map(int, input().split())
s -= 1
t -= 1

dist[s][0] = 0
que = deque([(s, 0)])
while que:
    u, t = que.popleft()
    d = dist[t][u]
    w = (t+1) % 3
    if t == 2:
        d += 1
    for v in to[u]:
        if dist[w][v] != INF:
            continue
        que.append((v, w))
        dist[w][v] = d
print( dist[0][t] if dist[0][t] < INF else -1 )
Problem p03000 (python)

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

dist, count = 0, 1
for i in range(n):
    dist += l[i]
    if dist > x:
        break
    count += 1

print(count)

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

dist, count = 0, 1
for i in range(n+1):
    dist += l[i]
    if dist > x:
        break
    count += 1

print(count)

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

dist, count = 0, 0
while dist <= x and count < n+1:
    dist += l[count]
    count += 1

print(count)
Problem p03359 (python)

Fixed submission:
a, b = map(int, input().split())
print(a) if a <= b else print(a-1)

Buggy submission (verdict: Runtime Error):
a, b = min(map(int, input().split()))
print(a) if a <= b else print(a-1)
Problem p03611 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]

for i in range(n):
    if a[i] > 1:
        ary[a[i]-2] += 1
        ary[a[i]-1] += 1
    ary[a[i]] += 1

print(max(ary))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]

for i in range(n):
    ary[a[i]-1] += 1
    ary[a[i]] += 1
    ary[a[i]+1] += 1

print(max(ary))
Problem p03633 (python)

Fixed submission:
from fractions import gcd
import sys
input = sys.stdin.readline

n = int(input())
ans = 1
for _ in range(n):
    t = int(input())
    ans = ans*t//gcd(ans, t)
print(ans)

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

n = int(input())
ans = 1
for _ in range(n):
    t = int(input())
    ans = ans*x//gcd(ans, x)
print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0:
        return a

    return gcd(b, a%b)

N = int(input())
t = []
for _ in range(N):
    t.append(int(input()))

lcm = max(t)

for i in range(N):
    if lcm % t[i] != 0:
        lcm = lcm * t[i] / gcd(lcm, lcm%t[i])

print(int(lcm))
Problem p02687 (python)

Fixed submission:
S = input()
if S[1] == "B":
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
last = input()
if input[1] == "B":
  print("ARC")
else:
  print("ABC")
Problem p02787 (python)

Fixed submission:
H, N = map(int, input().split())
ATK = []

for i in range(N):	
  ATK.append(list(map(int, input().split())))
mp_min = [0]
for hp in range(1, H+1):
  mp_min.append(min([mp_min[max(0, hp-ATK[i][0])] + ATK[i][1] for i in range(N)]))

 # print(mp_min)

print(mp_min[-1])

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split())
ATK = []

for i in range(N):	
  ATK.append(list(map(int, input().split())))
mp_min = [0]
for hp in range(1, H+1):
  mp_min.append(min([mp_min[max(0, hp-ATK[i][0])] + ATK[i][1] for i in range(N)]))

  print(mp_min)

print(mp_min[-1])

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split())
ATK = []

for i in range(N):	
  ATK.append(list(map(int, input().split())))
m = min([ATK[i][1] for i in range(N)])
mp_min = [0]
if m < H:
  for hp in range(1, H+1):
    mp_min.append(min([mp_min[max(0, hp-ATK[i][0])] + ATK[i][1] for i in range(N)]))

    #print(mp_min)

  print(mp_min[-1])
else:
  print(min([ATK[i][1] for i in range(N) if ATK[i][0] >= H]))
Problem p02811 (python)

Fixed submission:
K, X= map(int, input().split())
if K * 500 >= X:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
K, X= map(int, input().split())
if K * 500 >= X:
  print("Yes")
else:
  prine("No")

Buggy submission (verdict: Runtime Error):
K, X= map(int, input().split())
if K * 500 > X:
  print("Yes")
else:
  prine("No")
Problem p02848 (python)

Fixed submission:
N = int(input())
S = input()
ans = ""
for s in S:
  ans += chr((ord(s) + N-65)%26 + 65)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
ans = ""
for s in S:
  ans += chr((ord(S) + N - 65)%26 + 65)
print(ans)
Problem p02918 (python)

Fixed submission:
N, K = map(int,input().split())
S = input()
ans = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    ans += 1
print(min(N-1, ans + 2 * K))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input.split())
S = input()
ans = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    ans += 1
print(min(N-1, ans + 2 * K))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input.split())
S = input()
ans = 0
for i in range(N):
  if S[i] == S[i+1]:
    ans += 1
print(min(N-1, ans + 2 * K))
Problem p02924 (python)

Fixed submission:
N = int(input())
print((N - 1) * N // 2)

Buggy submission (verdict: Runtime Error):
N = input()
print(N * (N - 1)/2)
Problem p03001 (python)

Fixed submission:
W, H, x, y = map(int, input().split())
if (W, H) == (x*2, y*2):
  D = 1
else:
  D = 0
print(W * H / 2, D)

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
if (W, H) = (x*2, y*2):
  D = 0
else:
  D = 1
print(W * H / 2, D)
Problem p03074 (python)

Fixed submission:
N, K = map(int, input().split())
S = input()
l = [1]
for i in range(N-1):
  if S[i] == S[i+1]:
    l[-1] += 1
  else:
    l.append(1)
if S[0] == "0":
  l = [0] + l
if S[-1] == "0":
  l += [0]
#print(l)
n = len(l)
ans = sum(l[:min(K*2+1, n+1)])
i = 0
M = ans
while True:
  if K*2 + i+1 >= n:
    break
  M = M + l[K*2+1 + i] + l[K*2+1 + i+1] - l[i] -l[i+1]
  #print(ans, M)
  ans = max(ans, M)
  i += 2
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
l = [1]
for i in range(N-1):
  if S[i] == S[i+1]:
    l[-1] += 1
  else:
    l.append(1)
  if S[0] == 0:
    l = [0] + l
  if S[-1] == 0:
    l += [0]
#print(l)
n = len(l)
ans = sum(l[:min(K*2+1, n+1)])
i = 0
M = ans
while True:
  if K*2 + i+1 >= n:
    break
  M = M + l[K*2+1 + i] + l[K*2+1 + i+1] - l[i] -l[i+1]
  #print(ans, M)
  ans = max(ans, M)
  i += 2
print(ans)
Problem p03488 (python)

Fixed submission:
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
lon = [order[i] for i in range(len(order)) if i % 2 == 0]
lat = [order[i] for i in range(len(order)) if i % 2 == 1]
x -= lon[0]
lon = lon[1:]
def f(x, A):
  A.append(abs(x))
  A.sort(reverse=True)
  k = A[0]
  for p in A[1:]:
      if k > 0:
        k -= p
      else:
        k += p
  if k == 0:
    return True
  else:
    return False
  
#print(lon, lat)
if f(x, lon) == f(y, lat) == True:
  ans = "Yes"
  
print(ans)

Buggy submission (verdict: Runtime Error):
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
lon = [order[i] for i in range(len(order)) if i % 2 == 0]
lat = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, y, A, B, D):
  for p in A:
      if x > 0:
        x -= p
      else:
        x += p
  if x == 0:
    for q in B:
      if y > 0:
        y -= q
      else:
        y += q
    if y == 0:
      D = "Yes"
  return D
  
#print(lon, lat)
if sum(lon) >= abs(x):
  if sum(lati) >= abs(y):
    longi.sort(reverse=True)
    lati.sort(reverse=True)
    ans = f(x, y, longi, lati, ans)
    if ans == "No":
      x += x // abs(x) * abs(longi[-1])
      y += y // abs(y) * abs(lati[-1])
      ans = f(x, y, longi[:-1], lati[:-1], ans)
    
    
print(ans)

Buggy submission (verdict: Runtime Error):
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
longi = [order[i] for i in range(len(order)) if i % 2 == 0]
lati = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, y, A, B, D):
  for p in A:
      if x > 0:
        x -= p
      else:
        x += p
  if x == 0:
    for q in B:
      if y > 0:
        y -= q
      else:
        y += q
    if y == 0:
      D = "Yes"
  return D
  
#print(longi, lati)
if sum(longi) >= abs(x):
  if sum(lati) >= abs(y):
    longi.sort(reverse=True)
    lati.sort(reverse=True)
    ans = f(x, y, longi, lati, ans)
    if ans == "No":
      x += x // abs(x) * abs(longi[-1])
      y += y // abs(y) * abs(lati[-1])
      ans = f(x, y, longi[:-1], lati[:-1], ans)
    
    
print(ans)

Buggy submission (verdict: Runtime Error):
order = list(map(len, input().split("T")))
x, y = map(int, input().split())
ans = "No"
longi = [order[i] for i in range(len(order)) if i % 2 == 0]
lati = [order[i] for i in range(len(order)) if i % 2 == 1]
def f(x, y, A, B, D):
  for p in A:
      if x > 0:
        x -= p
      else:
        x += p
  if x == 0:
    for q in B:
      if y > 0:
        y -= q
      else:
        y += q
    if y == 0:
      D = "Yes"
  return D
  
print(longi, lati)
if sum(longi) >= abs(x):
  if sum(lati) >= abs(y):
    longi.sort(reverse=True)
    lati.sort(reverse=True)
    ans = f(x, y, longi, lati, ans)
    if ans == "No":
      x += x // abs(x) * abs(longi[-1])
      y += y // abs(y) * abs(lati[-1])
      ans = f(x, y, longi[:-2], lati[:-2], ans)
    
    
print(ans)
Problem p02787 (python)

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

dp = [float("inf")] * (h + 10010)
dp[0] = 0

for i in range(h + 1):
    for j in range(n):
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
print(min(dp[h:]))

Buggy submission (verdict: Runtime Error):
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

dp = [float("inf")] * (h + 1010)
dp[0] = 0

for i in range(h + 1):
    for j in range(n):
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
print(min(dp[h:]))