Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
T=[int(input()) for _ in range(N)]
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd(a, b)
ans = lcm(T[0], T[1])
for i in range(2,N-1):
    ans = lcm(ans, T[i])
print(ans)

Fixed submission:
N = int(input())
T=[int(input()) for _ in range(N)]
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd(a, b)
if N>1:
    ans = lcm(T[0], T[1])
    for i in range(2,N):
        ans = lcm(ans, T[i])
else:
    ans=T[0]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(str(a[i]))
    b.reverse()
b = ' '.join(b)
print(b)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = []
i=0
while n-1-i>=0:
    b.append(str(a[n - 1 - i]))
    i += 2
if n%2==0:
    for i in range(0,n,2):
        b.append(str(a[i]))
else:
    for i in range(1,n,2):
        b.append(str(a[i]))
b=' '.join(b)
print(b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()
b=[str(i) for i in b]
b = ' '.join(b)
print(b)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = []
i=0
while n-1-i>=0:
    b.append(str(a[n - 1 - i]))
    i += 2
if n%2==0:
    for i in range(0,n,2):
        b.append(str(a[i]))
else:
    for i in range(1,n,2):
        b.append(str(a[i]))
b=' '.join(b)
print(b)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x + y + z == S:
                count += 1
print(count)

Fixed submission:
K, S = map(int, input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if 0<=z and z<=K:
            count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
H, A = input().split()

print(int(H/A)+1)


Fixed submission:
H, A = input().split()
H = int(H) 
A = int(A)
if(H <= A):
  	answer = 1
else:
	answer = int(H / A)
	if( H % A != 0):
  		answer += 1

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def resolve_c():
    n = input()
    s_l = [input() for i in range(int(n))]
    c = collections.Counter(s_l)
    results = []
    for k, v in c.most_common():
        if v == c.most_common()[0][1]:
            results.append(k)
        else:
            break
    results = sorted(results)
    for r in results:
        print(r)
resolve_c()

Fixed submission:
import collections
def resolve_c():
    n = input()
    s_l = [input() for i in range(int(n))]
    c = collections.Counter(s_l)
    values, counts = zip(*c.most_common())
    results = sorted(list(values[:collections.Counter(counts)[max(counts)]]))
    fin = [print(r) for r in results]
resolve_c()

Buggy python submission (verdict: Runtime Error):
import collections
def resolve_c():
    n = input()
    s_l = [input() for i in range(int(n))]
    c = collections.Counter(s_l)
    for k, v in c.items():
        if v == c.most_common()[0][1]:
            results.append(v)
        else:
            break
    results = sorted(results)
    for r in results:
        print(r)
resolve_c()

Fixed submission:
import collections
def resolve_c():
    n = input()
    s_l = [input() for i in range(int(n))]
    c = collections.Counter(s_l)
    values, counts = zip(*c.most_common())
    results = sorted(list(values[:collections.Counter(counts)[max(counts)]]))
    fin = [print(r) for r in results]
resolve_c()

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def resolve_c():
    n = input()
    s_l = [input() for i in range(int(n))]
    c = collections.Counter(s_l)
    results = [k for k, v in c.items() if v == c.most_common()[0][1]]
    results = sorted(results)
    for r in results:
        print(r)
resolve_c()

Fixed submission:
import collections
def resolve_c():
    n = input()
    s_l = [input() for i in range(int(n))]
    c = collections.Counter(s_l)
    values, counts = zip(*c.most_common())
    results = sorted(list(values[:collections.Counter(counts)[max(counts)]]))
    fin = [print(r) for r in results]
resolve_c()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
n_list = list(map(int, input().split()))
count = 0
for i in range(n):
    test = n_list[:i+1]
    if min(test) == n_list[i]:
        count+=1
print(count)

Fixed submission:
n = int(input())
n_list = list(map(int, input().split()))
min_num = n
count = 0
for i in range(n):
    if min_num >= n_list[i]:
        min_num = n_list[i]
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
def resolve_c():
    n, m = map(int, input().split())
    ac_list = [0] * m
    wa_list = [0] * m
    wa_tmp_list = [0] * m
    for i in range(m):
        p, s = input().split()
        if ac_list[int(p)] == 0:
            if s == "AC":
                ac_list[int(p)] = 1
                wa_list[int(p)] = wa_tmp_list[int(p)]
            elif s == "WA":
                wa_tmp_list[int(p)] += 1
    print(str(sum(ac_list)) + " " + str(sum(wa_list)))
resolve_c()

Fixed submission:
def resolve_c():
    n, m = map(int, input().split())
    ac_list = [0] * n
    wa_list = [0] * n
    wa_tmp_list = [0] * n
    for i in range(m):
        p, s = input().split()
        if ac_list[int(p)-1] == 0:
            if s == "AC":
                ac_list[int(p)-1] = 1
                wa_list[int(p)-1] = wa_tmp_list[int(p)-1]
            elif s == "WA":
                wa_tmp_list[int(p)-1] += 1
    print(str(sum(ac_list)) + " " + str(sum(wa_list)))
resolve_c()

Buggy python submission (verdict: Runtime Error):
def resolve_c():
    n, m = map(int, input().split())
    ac_list = [0] * m
    wa_list = [0] * m
    wa_tmp_list = [0] * m
    for i in range(m):
        p, s = input().split()
        if ac_list[int(p)] == 0:
            if s == "AC":
                ac_list[int(p)] = 1
                wa_list[int(p)] = wa_tmp_list[int(p)]
            elif s == "WA":
                wa_tmp_list[int(p)] += 1
    print(str(sum(ac_list)) + " " + str(sum(wa_list)))
resolve_c()

Fixed submission:
def resolve_c():
    n, m = map(int, input().split())
    ac_list = [0] * n
    wa_list = [0] * n
    wa_tmp_list = [0] * n
    for i in range(m):
        p, s = input().split()
        if ac_list[int(p)-1] == 0:
            if s == "AC":
                ac_list[int(p)-1] = 1
                wa_list[int(p)-1] = wa_tmp_list[int(p)-1]
            elif s == "WA":
                wa_tmp_list[int(p)-1] += 1
    print(str(sum(ac_list)) + " " + str(sum(wa_list)))
resolve_c()

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
P = [input().split() for i in range(M)]

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
wa_sum = 0
ac_uq_list = []

ac_uq_list = get_unique_list([P[i] for i in range(M) if P[i][1] == "AC"])


for ac in ac_uq_list:
    c_list = [P[i] for i in range(len(P)) if P[i][0] == ac[0]]
    wa_sum += len(c_list[:c_list.index(ac)])

print(str(len(ac_uq_list)) + " " + str(wa_sum))   

Fixed submission:
def resolve_c():
    n, m = map(int, input().split())
    ac_list = [0] * n
    wa_list = [0] * n
    wa_tmp_list = [0] * n
    for i in range(m):
        p, s = input().split()
        if ac_list[int(p)-1] == 0:
            if s == "AC":
                ac_list[int(p)-1] = 1
                wa_list[int(p)-1] = wa_tmp_list[int(p)-1]
            elif s == "WA":
                wa_tmp_list[int(p)-1] += 1
    print(str(sum(ac_list)) + " " + str(sum(wa_list)))
resolve_c()
Buggy python submission (verdict: Runtime Error):
x = int(input())
try_n = x - 1
b_flg = True
roop_c = 0
while b_flg:
    try_n += 1
    for n in range(2, try_n):
        roop_c += 1
        if try_b == 2: # 2の場合は特別
            b_flg =False
            break
        if try_n % n == 0: # 素数でないことが確定した場合
            break
        else:
            if roop_c == try_n - 2:
                b_flg = False
print(try_n)

Fixed submission:
x = int(input())
b_flg = True
try_n = x - 1
roop_c = 0
if x == 2:
    print(x)
else:
    while b_flg:
        try_n += 1
        for n in range(2, try_n):
            roop_c += 1
            if try_n % n == 0: # 素数でないことが確定した場合
                break
            else:
                if roop_c == try_n - 2:
                    b_flg = False
    print(try_n)

Buggy python submission (verdict: Runtime Error):
x = int(input())
try_n = x - 1
b_flg = True
roop_c = 0
while b_flg:
    try_n += 1
    for n in range(2, try_n):
        roop_c += 1
        if try_b == 2: # 2の場合は特別
            b_flg =False
            break
        if try_n % n == 0: # 素数でないことが確定した場合
            break
        else:
            if roop_c == try_n - 2:
                b_flg = False
print(try_n)

Fixed submission:
x = int(input())
b_flg = True
try_n = x - 1
roop_c = 0
if x == 2:
    print(x)
else:
    while b_flg:
        try_n += 1
        for n in range(2, try_n):
            roop_c += 1
            if try_n % n == 0: # 素数でないことが確定した場合
                break
            else:
                if roop_c == try_n - 2:
                    b_flg = False
    print(try_n)
Buggy python submission (verdict: Runtime Error):
n = input()
mochi = [input() for i in range(int(n))]
print(len(set(mochi))

Fixed submission:
n = input()
mochi = [input() for i in range(int(n))]
print(len(set(mochi)))
Buggy python submission (verdict: Runtime Error):
s = input()
num_list = list(map(int, input().split()))

flg_break = True

while flg_break:
    count = 0
    num_tmp_list = []
    for n in num_list:
        print(n)
        if n % 2 != 0:
            flg_break = False
            break
        else:
            num_tmp = n / 2
            num_tmp_list.append(num_tmp)
    num_list = num_tmp_list
    count+=1

print(count)

Fixed submission:
s = input()
count = 0
if s[0] == "1":
  count+=1
if s[1] == "1":
  count+=1
if s[2] == "1":
  count+=1
  
print(count)
Buggy python submission (verdict: Runtime Error):
s = input()
num_list = list(map(int, input().split()))
count = -1
while flg_break:
    count+=1
    num_tmp_list = []
    for n in num_list:
        if n % 2 != 0:
            flg_break = False
            break
        else:
            num_tmp = n / 2
            num_tmp_list.append(num_tmp)
    num_list = num_tmp_list
print(count)

Fixed submission:
s = input()
num_list = list(map(int, input().split()))

flg_break = True

count = -1
while flg_break:
    count+=1
    num_tmp_list = []
    for n in num_list:
        if n % 2 != 0:
            flg_break = False
            break
        else:
            num_tmp = n / 2
            num_tmp_list.append(num_tmp)
    num_list = num_tmp_list
    

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N,A,B=map(int,input().split())
ans=0
count=0
Flag=False
waru=N//(A+B)
amari=N%(A+B)
for i in range (10**18):
    if amari==0:
        break
    for j in range(A):
        ans+=1
        count+=1
        if count==amari:
            Flag=True
            break
    for k in range(B):
        if Flag:
            break
        count+=1
        if count==amari:
            Flag=True
            break
    if Flag:
        break
print(ans+waru*A)

Fixed submission:
N,A,B=map(int,input().split())
ans=0
count=0
Flag=False
waru=N//(A+B)
amari=N%(A+B)
if amari>A:
    print(waru*A+A)
else:
    print(waru*A+amari)

Buggy python submission (verdict: Time Limit Exceeded):
N,A,B=map(int,input().split())
ans=0
count=0
Flag=False
for i in range (10**100):
    for j in range(A):
        ans+=1
        count+=1
        if count==N:
            Flag=True
            break
    for k in range(B):
        if Flag:
            break
        count+=1
        if count==N:
            Flag=True
            break
    if Flag:
        break
print(ans)

Fixed submission:
N,A,B=map(int,input().split())
ans=0
count=0
Flag=False
waru=N//(A+B)
amari=N%(A+B)
if amari>A:
    print(waru*A+A)
else:
    print(waru*A+amari)
Buggy python submission (verdict: Runtime Error):
import sys
N=int(input())
A=list(map(int,input().split()))
flag=True
for i in range(N):
    if A[i]%2==0:
        if A[i]%3!=0 or A[i]%5!=0:
            flag=False
if flag==True:
    print('APPROVED')
else:
    print('DENIED'

Fixed submission:
import sys
N=int(input())
A=list(map(int,input().split()))
flag=True
for i in range(N):
    if A[i]%2==0:
        if A[i]%3!=0 and A[i]%5!=0:
            flag=False
if flag==True:
    print('APPROVED')
else:
    print('DENIED')
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B=map(int,input().split())
print(lcm(A,B))

Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
A,B=map(int,input().split())
print(lcm(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
Number=[0]*n
Numstr=""
for i in range(n):
    Number[a[i]-1]=i+1
for j in range(n):
    if j!=n:
        Numstr=Numstr+str(Number[j])+" "
    else:
        Numstr=Numstr+str(Number[j])
print(Numstr)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
Number=[0]*n
for i in range(n):
    Number[a[i]-1]=i+1

print(" ".join(map(str,Number)))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
Number=[0]*n
Numstr=""
for i in range(n):
    Number[a[i]-1]=i+1
for j in range(n):
    if j!=n:
        Numstr=Numstr+str(Number[j])+" "
    else:
        Numstr=Numstr+str(Number[j])
print(Numstr)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
Number=[0]*n
for i in range(n):
    Number[a[i]-1]=i+1

print(" ".join(map(str,Number)))
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[0]*N
maxim=[0]*N
for i in range(N):
    a[i]=int(input())
maxim=sorted(list(a), reverse=True)
for k in range(N):
    if a[k]!=maxim[0]:
        print(maxim[0])
    else:
        print(maxim[1])

Fixed submission:
r=int(input())
print(r*r*3)

Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[0]*(N)
maxim=[0]*(N)
for i in range(N):
    a[i]=int(input())
maxim=sorted(list(a), reverse=True)
for k in range(N):
    if a[k]!=maxim[0]:
        print(maxim[0])
    else:
        print(maxim[1])

Fixed submission:
r=int(input())
print(r*r*3)
Buggy python submission (verdict: Runtime Error):
i=list(int,input().split())
if i[0]*i[1]>i[2]:
    print(i[0]*i[1])
elif:
    print(i[2])

Fixed submission:

i=list(map(int,input().split()))
if i[2]>i[0]*i[1]:
    print(i[0]*i[1])
else:
    print(i[2])
Buggy python submission (verdict: Time Limit Exceeded):
L,R=map(int,input().split())
flag=0
for i in range(L,R+1):
    if i%2019==0:
        flag=1
ans=[]
if flag==1:
    print(0)
else:
    for m in range(L,R+1):
        for j in range(m+1,R+1):
            ans.append(m*j%2019)
    print(min(ans))
            
            


Fixed submission:
L,R=map(int,input().split())
ans=[]
if (R-L)>2019:
    print(0)
else:
    for m in range(L,R+1):
        for j in range(m+1,R+1):
            ans.append(m*j%2019)
    print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
L,R=map(int,input().split())
flag=0
for i in range(L,R+1):
    if i%2019==0:
        flag=1
ans=[]
if flag==1:
    print(0)
else:
    for m in range(L,R+1):
        for j in range(m+1,R+1):
            ans.append(m*j%2019)
    print(min(ans))
            
            


Fixed submission:
L,R=map(int,input().split())
ans=[]
if (R-L)>2019:
    print(0)
else:
    for m in range(L,R+1):
        for j in range(m+1,R+1):
            ans.append(m*j%2019)
    print(min(ans))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N,A=map(int,input()split())
print(N-A+1)

Fixed submission:
# coding: utf-8
# Your code here!

N,A=map(int,input().split())
print(N-A+1)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input()split())
print(A*B-A-B+1)

Fixed submission:
A,B=map(int,input().split())
print(A*B-A-B+1)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
#codebegin
R=input()
r=int(R)
if r<1200:
    print("ABC"):
if r>(1200-1) and r<2800:
    print("ARC")
if r>(2800-1):
    print("AGC")

Fixed submission:
# coding: utf-8
# Your code here!

R=input()
r=int(R)
if r<1200:
    print("ABC")
elif r<2800:
    print("ARC")
else:
    print("AGC")

Buggy python submission (verdict: Runtime Error):
# using-utf8
#codebegin
R=input()
r=int(R)
if r<1200:
    print("ABC"):
if r>(1200-1) and r<2800:
    print("ARC")
if r>(2800-1):
    print("AGC")

Fixed submission:
# coding: utf-8
# Your code here!

R=input()
r=int(R)
if r<1200:
    print("ABC")
elif r<2800:
    print("ARC")
else:
    print("AGC")
Buggy python submission (verdict: Runtime Error):
S=input()
T=input()
S=S[::-1]
if S=T:
  print("Yes")
else:
  print("No")

Fixed submission:
S=input()
T=input()
S=S*2
if T in S:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N=int(input())
n=list(str(N))
n=[int(n) for i in n]
summer=sum(n)
if N%summer==0:
  print("Yes")
else:
  print("No")

Fixed submission:
N=input()
wa=0
for i in N:
  wa+=int(i)
if (int(N)%wa)==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
D,N=map(int,input()split())

if N<100:
  print(100**D*N)
else:
  print(100**D*101)


Fixed submission:
A,B=map(int,input().split())
if (A>8) or (B>8):
  print(":(")
else:
  print("Yay!")

Buggy python submission (verdict: Runtime Error):
D,N=map(int,input()split())

if N<100:
  print(pow(100,D)*N)
else:
  print(pow(100,D)*101)


Fixed submission:
A,B=map(int,input().split())
if (A>8) or (B>8):
  print(":(")
else:
  print("Yay!")

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

if N<100:
  print(pow(100,D)*N)
else:
  print(pow(100,D)*101)

Fixed submission:
A,B=map(int,input().split())
if (A>8) or (B>8):
  print(":(")
else:
  print("Yay!")

Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split)
if (A>8) or (B>8):
  print(":(")
else:
  print("Yay!")

Fixed submission:
A,B=map(int,input().split())
if (A>8) or (B>8):
  print(":(")
else:
  print("Yay!")

Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split)
if A>8 or B>8:
  print(":(")
else:
  print("Yay!")

Fixed submission:
A,B=map(int,input().split())
if (A>8) or (B>8):
  print(":(")
else:
  print("Yay!")
Buggy python submission (verdict: Runtime Error):
D,N=map(int,input()split())

if N<100:
  print(100**D*N)
else:
  print(100**D*101)


Fixed submission:
D,N=map(int,input().split())

if N<100:
  print(100**D*N)
else:
  print(100**D*101)

Buggy python submission (verdict: Runtime Error):
D,N=map(int,input()split())

if N<100:
  print(pow(100,D)*N)
else:
  print(pow(100,D)*101)


Fixed submission:
D,N=map(int,input().split())

if N<100:
  print(100**D*N)
else:
  print(100**D*101)
Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
ac = set()
wa = 0
for i in range(m):
  p, s = input.split()
  p = int(p)
  if p in ac:
    continue
  if s == 'WA':
    wa += 1
  else:
    ac.add(p)
print("%d %d" % (len(ac), wa))

Fixed submission:
n, m = list(map(int, input().split()))
ac = set()
wa = {}
for i in range(m):
  p, s = input().split()
  p = int(p)
  if p in ac:
    continue
  if s == 'WA':
    wa[p] = wa.get(p, 0) + 1
  else:
    ac.add(p)
pe = 0
for p in set(ac) & set(wa.keys()):
    pe += wa[p]
print("%d %d" % (len(ac), pe))
Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
maze = []
for i in range(n):
  l = input()
  dl = []
  for j in range(m):
    if l[j] == '.':
      dl.append(0)
    else:
      dl.append(1)
  maze.append(dl)
ans = 0
for i in range(n):
  for j in range(m):
    if maze[i][j] == 0:
      a = [list(l) for l in maze]
      a[i][j] = 1
      q = [(i, j)]
      d = 0
      while len(q) > 0:
        nq = []
        d += 1
        for x, y in q:
          if x > 0 and a[x - 1][y] == 0:
            a[x - 1][y] = 1
            np.append((x - 1, y))
          if y > 0 and a[x][y - 1] == 0:
            a[x][y - 1] = 1
            np.append((x, y - 1))
          if x < n - 1 and a[x + 1][y] == 0:
            a[x + 1][y] = 1
            np.append((x + 1, y))
          if y < m - 1 and a[x][y + 1] == 0:
            a[x][y + 1] = 1
            np.append((x, y + 1))
        q = nq
      ans = max(ans, d)
print(ans)

Fixed submission:
n, m = list(map(int, input().split()))
maze = []
for i in range(n):
  l = input()
  dl = []
  for j in range(m):
    if l[j] == '.':
      dl.append(0)
    else:
      dl.append(1)
  maze.append(dl)
ans = 0
for i in range(n):
  for j in range(m):
    if maze[i][j] == 0:
      a = [list(l) for l in maze]
      a[i][j] = 1
      q = [(i, j)]
      d = 0
      while len(q) > 0:
        nq = []
        for x, y in q:
          if x > 0 and a[x - 1][y] == 0:
            a[x - 1][y] = 1
            nq.append((x - 1, y))
          if y > 0 and a[x][y - 1] == 0:
            a[x][y - 1] = 1
            nq.append((x, y - 1))
          if x < n - 1 and a[x + 1][y] == 0:
            a[x + 1][y] = 1
            nq.append((x + 1, y))
          if y < m - 1 and a[x][y + 1] == 0:
            a[x][y + 1] = 1
            nq.append((x, y + 1))
        if len(nq) > 0:
          d += 1
        q = nq
      ans = max(ans, d)
print(ans)
Buggy python submission (verdict: Runtime Error):
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

sa = a1 * t1 + a2 * t2
sb = b1 * t1 + b2 * t2

if sa == sb:
	print("infinity")
	exit()

# a is faster
if sa < sb:
	a1, a2, b1, b2 = b1, b2, a1, a2
	sa, sb = sb, sa
delta = sa - sb

# no meeting
if a1 > b1:
	print(0)
	exit()

# count the meeting in T1 period
cnt = (b1 - a1) * t1 // delta

# count the meeting in T2 period
cnt += (b1 - a1) * t1 // delta + 1

# common one
if (b1 - a1) * t1 % delta == 0:
	cnt -= 1

print(cnt)

Fixed submission:
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

sa = a1 * t1 + a2 * t2
sb = b1 * t1 + b2 * t2

if sa == sb:
	print("infinity")
	exit()

# a is faster
if sa < sb:
	a1, a2, b1, b2 = b1, b2, a1, a2
	sa, sb = sb, sa
delta = sa - sb

# no meeting
if a1 > b1:
	print(0)
	exit()

# count the meeting in T1 period
cnt = (b1 - a1) * t1 // delta

# count the meeting in T2 period
cnt += (b1 - a1) * t1 // delta + 1

# common one
if (b1 - a1) * t1 % delta == 0:
	cnt -= 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, t = map(int, input().split())
f = [[0, 0] for i in range(t + 1)]
for i in range(n):
  w, v = map(int, input().split())
  for j in range(t, 0, -1):
    f[j][1] = max(f[j][1], f[j - 1][0] + v)
    if j >= w:
      f[j][0] = max(f[j][0], f[j - w][0] + v)
      f[j][1] = max(f[j][1], f[j - w][1] + v)
print(f[t][1])

Fixed submission:
n, t = map(int, input().split())
f = [[0, 0] for i in range(t + 1)]
for i in range(n):
  w, v = map(int, input().split())
  for j in range(t, 0, -1):
    f[j][1] = max(f[j][1], f[j - 1][0] + v)
    if j >= w:
      f[j][0] = max(f[j][0], f[j - w][0] + v)
      f[j][1] = max(f[j][1], f[j - w][1] + v)
print(f[t][1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
if n == m:
  print(0)
  exit()
h = list(map(int, input().split()))
maxi = sum(h)
f = [e for e in h]
# print(f)
for i in range(n - m - 1):
  for j in range(n - 1, i, -1):
    res = maxi
    for k in range(i, j):
      res = min(res, f[k] + max(0, h[j] - h[k]))
    f[j] = res
  # print(f)
print(min(f[n - m - 1:]))

Fixed submission:
n, m = list(map(int, input().split()))
if n == m:
  print(0)
  exit()
h = list(map(int, input().split()))
maxi = sum(h)
f = [e for e in h]
# print(f)
for i in range(n - m - 1):
  for j in range(n - 1, i, -1):
    res = maxi
    for k in range(i, j):
      res = min(res, f[k] + max(0, h[j] - h[k]))
    f[j] = res
  # print(f)
print(min(f[n - m - 1:]))