Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    Reds = [list(map(int, input().split(" "))) for i in range(N)]
    Blues = [list(map(int, input().split(" "))) for i in range(N)]
    maxpairs = 0
    for blues in itertools.permutations(Blues, N):
        npairs = 0
        for i in range(N):
            if able_to_be_pair(Reds[i], blues[i]):
                npairs += 1
        maxpairs = max(maxpairs, npairs)
    print(maxpairs)

def able_to_be_pair(red, blue):
    return True if (blue[0] - red[0]) > 0 and (blue[1] - red[1]) > 0 else False

if '__main__' == __name__:
    resolve()

Fixed submission:
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    Reds = sorted([list(map(int, input().split(" "))) for i in range(N)], key=lambda x: x[1], reverse=True)
    Blues = sorted([list(map(int, input().split(" "))) for i in range(N)], key=lambda x: x[0])
    used = []
    for red in Reds:
        for blue in Blues:
            if blue not in used and able_to_be_pair(red, blue):
                used.append(blue)
                break
    print(len(used))

def able_to_be_pair(red, blue):
    return True if (blue[0] - red[0]) > 0 and (blue[1] - red[1]) > 0 else False

if '__main__' == __name__:
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    Reds = [list(map(int, input().split(" "))) for i in range(N)]
    Blues = [list(map(int, input().split(" "))) for i in range(N)]
    maxpairs = 0
    BluePerms = permutations(Blues)
    for blues in BluePerms:
        npairs = 0
        for i in range(N):
            if able_to_be_pair(Reds[i], blues[i]):
                npairs += 1
        maxpairs = max(maxpairs, npairs)
    print(maxpairs)

def able_to_be_pair(red, blue):
    return True if (blue[0] - red[0]) > 0 and (blue[1] - red[1]) > 0 else False

import itertools
def permutations(array, choose=None):
    if choose is None:
        choose = len(array)
    return list(itertools.permutations(array, choose))

if '__main__' == __name__:
    resolve()

Fixed submission:
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    Reds = sorted([list(map(int, input().split(" "))) for i in range(N)], key=lambda x: x[1], reverse=True)
    Blues = sorted([list(map(int, input().split(" "))) for i in range(N)], key=lambda x: x[0])
    used = []
    for red in Reds:
        for blue in Blues:
            if blue not in used and able_to_be_pair(red, blue):
                used.append(blue)
                break
    print(len(used))

def able_to_be_pair(red, blue):
    return True if (blue[0] - red[0]) > 0 and (blue[1] - red[1]) > 0 else False

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s = input()
    s = [c for c in s]
    t = input()
    t = [c for c in t]
    import itertools
    S = list(itertools.permutations(s, len(s)))
    T = list(itertools.permutations(t, len(t)))
    for s in S:
        for t in T:
            if "".join(s) < "".join(t):
                print("Yes")
                return
    print("No")
            

if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    S = sorted(input())
    T = sorted(input(), reverse=True)
    print("Yes" if S < T else "No")
            

if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = list(map(int, input().split()))
    XY = []
    X = []
    Y = []
    for _ in range(N):
        x, y = list(map(int, input().split()))
        XY.append((x, y))
        X.append(x)
        Y.append(y)
    
    X.sort()
    Y.sort()
    
    ans = float("inf")
    for i in range(N-1):
        for j in range(i+1, N):
            for k in range(N-1):
                for l in range(k+1, N):
                    cnt = 0
                    xmin, xmax, ymin, ymax = X[i], X[j], Y[k], Y[l]
                    for x, y in XY:
                        if xmin <= x <= xmax and ymin <= y <= ymax:
                            cnt += 1
                    if cnt >= K:
                        ans = min(ans, abs(xmax-xmin)*abs(ymax-ymin))
    print(ans)




if '__main__' == __name__:
    resolve()


Fixed submission:
def resolve():
    N, K = list(map(int, input().split()))
    XY = []
    X = []
    Y = []
    for _ in range(N):
        x, y = list(map(int, input().split()))
        XY.append((x, y))
        X.append(x)
        Y.append(y)
    
    X.sort()
    Y.sort()
    
    ans = float("inf")
    for i in range(N-1):
        for j in range(i+1, N):
            for k in range(N-1):
                for l in range(k+1, N):
                    cnt = 0
                    xmin, xmax, ymin, ymax = X[i], X[j], Y[k], Y[l]
                    for x, y in XY:
                        if xmin <= x <= xmax and ymin <= y <= ymax:
                            cnt += 1
                    if cnt >= K:
                        ans = min(ans, abs(xmax-xmin)*abs(ymax-ymin))
    print(ans)




if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    idx = 0
    target = 1
    cnt = 1
    passed = []
    while True:
        if idx >= N:
            print(-1)
            return
        if A[idx]-1 == target:
            print(cnt)
            return
        if A[idx]-1 in passed:
            print(-1)
            return
        passed.append(idx)
        idx = A[idx]-1
        cnt += 1



if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    idx = 0
    target = 1
    cnt = 1
    passed = [False]*N
    while True:
        if idx >= N:
            print(-1)
            return
        if A[idx]-1 == target:
            print(cnt)
            return
        if passed[A[idx]-1]:
            print(-1)
            return
        passed[idx] = True
        idx = A[idx]-1
        cnt += 1



if '__main__' == __name__:
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    idx = 0
    target = 1
    cnt = 1
    passed = []
    while True:
        if idx >= N:
            print(-1)
            return
        if A[idx]-1 == target:
            print(cnt)
            return
        if A[idx]-1 in passed:
            print(-1)
            return
        passed.append(idx)
        idx = A[idx]-1
        cnt += 1



if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    A = [int(input()) for i in range(N)]
    idx = 0
    target = 1
    cnt = 1
    passed = [False]*N
    while True:
        if idx >= N:
            print(-1)
            return
        if A[idx]-1 == target:
            print(cnt)
            return
        if passed[A[idx]-1]:
            print(-1)
            return
        passed[idx] = True
        idx = A[idx]-1
        cnt += 1



if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
import math
def bsearch_int(init_ng, init_ok, cond):
    ng = init_ng
    ok = init_ok
    while(abs(ok - ng) > 0):
        mid = math.floor(abs(ok + ng)/2)
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok if ok != init_ok else -1

def condition(cnt, N, A, B, hs):
    basedmg = B*cnt
    diff = A - B
    diffcnt = 0
    for h in hs:
        if h < basedmg:
            break
        else:
            diffcnt += math.ceil((h-basedmg)/diff)
    if diffcnt > cnt:
        return False
    else:
        return True

import functools
def resolve():
    N, A, B = list(map(int, input().split(" ")))
    hs = [int(input()) for i in range(N)]
    hs.sort(reverse=True)
    print(bsearch_int(0, math.ceil(hs[0]/B), functools.partial(condition, N=N, A=A, B=B, hs=hs)))


if __name__ == '__main__':
    resolve()

Fixed submission:
import math
def bsearch_int(init_ng, init_ok, cond):
    ng = init_ng
    ok = init_ok
    while(abs(ok - ng) > 1):
        mid = math.floor(abs(ok + ng)/2)
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok

def condition(cnt, N, A, B, hs):
    basedmg = B*cnt
    diff = A - B
    diffcnt = 0
    for h in hs:
        if h < basedmg:
            break
        else:
            diffcnt += math.ceil((h-basedmg)/diff)
    if diffcnt > cnt:
        return False
    else:
        return True

import functools
def resolve():
    N, A, B = list(map(int, input().split(" ")))
    hs = [int(input()) for i in range(N)]
    hs.sort(reverse=True)
    print(bsearch_int(0, math.ceil(hs[0]/B), functools.partial(condition, N=N, A=A, B=B, hs=hs)))


if __name__ == '__main__':
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, W = list(map(int, input().split()))
    WV = [[0, 0]]+[list(map(int, input().split())) for _ in range(N)]
    dp = [[0 for _ in range(W+1)] for ___ in range(N+1)]
    
    for i in range(1, N+1):
        for j in range(W+1):
            w, v = WV[i]
            if j >= w:
                dp[i][j] = max(dp[i-1][j-w] + v, dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[N][W])


if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    N, W = list(map(int, input().split()))
    WV = [list(map(int, input().split())) for _ in range(N)]
    wbase = WV[0][0]
    d = {
        wbase: [0],
        wbase+1: [0],
        wbase+2: [0],
        wbase+3: [0],
    }
    for w, v in WV:
        d[w].append(v)
    for v in d.values():
        v.sort(reverse=True)
    
    accs = {}
    for i in range(4):
        accs[wbase+i] = [0]
        for j in range(len(d[wbase+i])):
            accs[wbase+i].append(accs[wbase+i][j]+d[wbase+i][j])
    
    res = 0
    for i in range(len(d[wbase])):
        for j in range(len(d[wbase+1])):
            for k in range(len(d[wbase+2])):
                for l in range(len(d[wbase+3])):
                    if i*wbase+j*(wbase+1)+k*(wbase+2)+l*(wbase+3) <= W:
                        res = max(res, accs[wbase][i]+accs[wbase+1][j]+accs[wbase+2][k]+accs[wbase+3][l])
    print(res)


if __name__ == '__main__':
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    power = 1
    for i in range(1, N+1):
        power *= i
    print(power%(10**9+7))


if '__main__' == __name__:
    resolve()

Fixed submission:
def resolve():
    N = int(input())
    power = 1
    for i in range(1, N+1):
        power *= i
        power = power%(10**9+7)
    print(power)


if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    # A = input().replace(" ", "")
    A = list(map(int, readline().rstrip().split()))
    import collections
    counter = collections.Counter(A)
    if N % 2 == 1:
        if counter["0"] != 1:
            print("0")
            return
        for k, v in counter.items():
            if k == "0":
                continue
            if int(k) % 2 == 1:
                print("0")
                return
            if v != 2:
                print("0")
                return
    else:
        for k, v in counter.items():
            if int(k) % 2 == 0:
                print("0")
                return
            if v != 2:
                print("0")
                return
    
    print( (2**(N//2)) % (10**9+7) )




if '__main__' == __name__:
    resolve()



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

def resolve():
    N = int(input())
    # A = input().replace(" ", "")
    A = readline().rstrip().split()
    import collections
    counter = collections.Counter(A)
    if N % 2 == 1:
        if counter["0"] != 1:
            print("0")
            return
        for k, v in counter.items():
            if k == "0":
                continue
            if int(k) % 2 == 1:
                print("0")
                return
            if v != 2:
                print("0")
                return
    else:
        for k, v in counter.items():
            if int(k) % 2 == 0:
                print("0")
                return
            if v != 2:
                print("0")
                return
    
    print( (2**(N//2)) % (10**9+7) )




if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    S = input()
    strings = ["dream", "dreamer", "erase", "eraser"]
    import collections
    deq = collections.deque(["dream", "dreamer", "erase", "eraser"])

    while deq:
        s = deq.pop()
        if s == S:
            print("YES")
            return
        if len(s) < len(S):
            for item in strings:
                deq.append(s+item)
    print("NO")




if '__main__' == __name__:
    resolve()



Fixed submission:
def resolve():
    S = input()
    strings = ["dream", "dreamer", "erase", "eraser"]
    while True:
        if S == "":
            print("YES")
            return

        if S.startswith("eraser"):
            S = S[len("eraser"):]
            continue
        elif S.startswith("erase"):
            S = S[len("erase"):]
            continue
        elif S.startswith("dreamer"):
            if S.startswith("dreamerase"):
                S = S[len("dream"):]
                continue
            else:
                S = S[len("dreamer"):]
                continue
        elif S.startswith("dream"):
            S = S[len("erase"):]
            continue
        else:
            print("NO")
            return




if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N = int(input())
    TA = [list(map(int, input().split())) for i in range(N)]
    t, a = TA[0]
    for i in range(1, len(TA)):
        t_next, a_next = TA[i]
        mul = 1
        while True:
            if t_next*mul >= t and a_next*mul >= a:
                t = t_next*mul
                a = a_next*mul
                break
            mul += 1
    print(t+a)


if '__main__' == __name__:
    resolve()



Fixed submission:
import math
def resolve():
    N = int(input())
    TA = [list(map(int, input().split())) for i in range(N)]
    t, a = TA[0]
    for i in range(1, len(TA)):
        t_next, a_next = TA[i]
        div = max((t//t_next)+(t%t_next!=0), (a//a_next)+(a%a_next!=0))
        t = t_next*div
        a = a_next*div
    print(t+a)


if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, A = list(map(int, input().split()))
    X = sorted(list(map(int, input().split())))
    cnt = 0
    for bits in range(1, 1<<N):
        flags = list(bin(bits)[2:].zfill(N))
        _X = [x for i, x in enumerate(X) if flags[i]=="1"]
        cnt += 1 if sum(_X)/len(_X) == A else 0
    print(cnt)
    


if '__main__' == __name__:
    resolve()



Fixed submission:
def resolve():
    N, A = list(map(int, input().split()))
    X = [int(i) - A for i in input().split()]
    d = {0: 1}
    for x in X:
        for _sum, count in list(d.items()):
            d[_sum+x] = d.get(_sum+x, 0) + count

    print(d[0]-1)
    


if '__main__' == __name__:
    resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    N, A = list(map(int, input().split()))
    X = sorted(list(map(int, input().split())))
    cnt = 0
    for bits in range(1, 1<<N):
        flags = list(bin(bits)[2:].zfill(N))
        _X = [x for i, x in enumerate(X) if flags[i]=="1"]
        cnt += 1 if sum(_X)/len(_X) == A 
    print(cnt)
    


if '__main__' == __name__:
    resolve()



Fixed submission:
def resolve():
    N, A = list(map(int, input().split()))
    X = [int(i) - A for i in input().split()]
    d = {0: 1}
    for x in X:
        for _sum, count in list(d.items()):
            d[_sum+x] = d.get(_sum+x, 0) + count

    print(d[0]-1)
    


if '__main__' == __name__:
    resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    S = list(input())
    if len(S) == 2:
        print(-1, -1)    
    for i in range(len(S)-3):
        if S[i] == S[i+1] or S[i+1] == S[i+2] or S[i+2] == S[i]):
            print(i+1, i+3)
            return
    print(-1, -1)


if __name__ == '__main__':
    resolve()

Fixed submission:
def resolve():
    S = list(input())
    if len(S) == 2:
        if S[0] == S[1]:
            print(1, 2)
        else:
            print(-1, -1)
        return
    for i in range(len(S)-2):
        if S[i] == S[i+1] or S[i+1] == S[i+2] or S[i+2] == S[i]:
            print(i+1, i+3)
            return
    print(-1, -1)


if __name__ == '__main__':
    resolve()
Buggy python submission (verdict: Runtime Error):
X, N = list(map(int,input().split()))
if N !=0:
  P = list(map(int,input().split()))
  ab = 100
  for i in range(101):
    if i not in P:
      if abs(X-i)<ab:
        ab = abs(X-i)
        ans = i
      elif abs(X-i)==ab:
        ans = min(ans,i)
  print(ans)
else:
  print(X)
    

Fixed submission:
X, N = list(map(int,input().split()))
if N !=0:
  P = list(map(int,input().split()))
  ab = 100
  for i in range(-100,200):
    if i not in P:
      if abs(X-i)<ab:
        ab = abs(X-i)
        ans = i
  print(ans)
else:
  print(X)

Buggy python submission (verdict: Runtime Error):
10 5
4 7 10 6 5

Fixed submission:
X, N = list(map(int,input().split()))
if N !=0:
  P = list(map(int,input().split()))
  ab = 100
  for i in range(-100,200):
    if i not in P:
      if abs(X-i)<ab:
        ab = abs(X-i)
        ans = i
  print(ans)
else:
  print(X)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for i in range(N-1):
  ans = ans * A[i+1]

if ans > 10**18:
    ans = -1  
print(ans)

Fixed submission:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
ans = A[0]
if 0 in A:
  ans = 0
for i in range(N-1):
  ans = ans * A[i+1]
  if ans > 10**18 or ans < -1:
    ans = -1  

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
l = len(S)
count = 0
for i in range(4,l+1):
  for j in range(l-i+1):
    if float(S[j:j+i]) % 2019 == 0:
      count += 1
print(count)

Fixed submission:
S, W = list(map(int, input().split()))
if S <= W:
  print("unsafe")
else:
  print("safe")
Buggy python submission (verdict: Runtime Error):
N = int(input())
count = 0
for i in range(N+1):
  if i % 3 != 0 and i % 5 != 0:
  print(i)
print(count)

Fixed submission:
N = input()
flag = 0
for i in range(len(N)):
  if int(N[i]) == 7:
    flag = 1
if flag == 1:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
N = input()
for i in range(len(N)):
  if int(N[i]) == 7:
    flag = 1
if flag == 1:
  print('Yes')
else:
  print('No')

Fixed submission:
N = input()
flag = 0
for i in range(len(N)):
  if int(N[i]) == 7:
    flag = 1
if flag == 1:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
N = input()
for i in range(len(N)):
  if N[i] == 7;
	flag = 1
if flag = 1:
  print('Yes')
else:
  print('No')

Fixed submission:
N = input()
flag = 0
for i in range(len(N)):
  if int(N[i]) == 7:
    flag = 1
if flag == 1:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
count = 0
for i in range(N+1):
  if i % 3 != 0 and i % 5 != 0:
  print(i)
print(count)

Fixed submission:
N = int(input())
count = 0
for i in range(N+1):
  if i % 3 != 0 and i % 5 != 0:
    count += i
print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())
def f(N):
  if N % 5 == 0 and N % 3 == 0:
    return f(N-1)
  elif N % 5 == 0:
    return f(N-1)
  elif N % 3 == 0:
    return f(N-1)
  elif N == 1:
    return 1
  else:
    return f(N-1)+N
print(f(N))

Fixed submission:
N = int(input())
count = 0
for i in range(N+1):
  if i % 3 != 0 and i % 5 != 0:
    count += i
print(count)
Buggy python submission (verdict: Runtime Error):
X = input()
tmp = X // 500
ans = tmp * 1000 + X % 500 - ((X % 500) % 5)
print(ans)

Fixed submission:
X = int(input())
tmp = X // 500
ans = tmp * 1000 + X % 500 - ((X % 500) % 5)
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, A, B = list(map(int,input().split()))

t1 = np.ones(A,dtype=np.int64)
t2 = np.zeros(B,dtype=np.int64)
t = np.hstack((t1, t2))

L = len(t)

Q = N // L
R = N % L
ANS = Q*(np.sum(t))+np.sum(t[0:R])
print(ANS)

Fixed submission:
a = list(map(int,input().split()))
N = a[0]
blue = a[1]
red = a[2]
ans = 0
A = blue + red
X = N // A
Y = N % A
if Y <= blue:
    ans = blue * X + Y
else:
    ans = blue * X + blue
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [input() for i in range(N)]
a.sort()
b = [0] * N
flag = 1
cc = 0
for i in range(N):
    c = a.count(a[cc])
    b[cc] = c
    if flag == 1:
        max = c
        flag = 0
    if c > max:
        max = c
    cc = cc + c
    if cc >= N:
        break
for i in range(N):
    if b[i] == max:
        print(a[i])




Fixed submission:
N = int(input())
a = [input() for i in range(N)]
a.sort()
b = [0] * N
flag = 1
cc = 0
bef = 132
c = 1
for i in range(N):
    if a[i] == bef:
        c = c + 1
    else:
        c = 1
    bef = a[i]
    b[i] = c
    if flag == 1:
        max = c
        flag = 0
    if c > max:
        max = c
        
for i in range(N):
    if b[i] == max:
        print(a[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [input() for i in range(N)]
b = []
ans = []
flag = 1
for i in range(N):
    c = a.count(a[i])
    b.append(c)
    if flag == 1:
        max = c
        flag = 0
    if c > max:
        max = c
for i in range(N):
    if b[i] == max:
        if(ans.count(a[i]) < 1):
            ans.append(a[i])
ans = sorted(ans, key=str.lower)

for i in range(len(ans)):
    print(ans[i])

Fixed submission:
N = int(input())
a = [input() for i in range(N)]
a.sort()
b = [0] * N
flag = 1
cc = 0
bef = 132
c = 1
for i in range(N):
    if a[i] == bef:
        c = c + 1
    else:
        c = 1
    bef = a[i]
    b[i] = c
    if flag == 1:
        max = c
        flag = 0
    if c > max:
        max = c
        
for i in range(N):
    if b[i] == max:
        print(a[i])
Buggy python submission (verdict: Runtime Error):
import fractions
a = list(map(int,input().split()))
N = a[0]
b = []
x = list(map(int,input().split()))
x.append(a[1])
x.sort()
flag = 0
for i in range(N):
    c = x[i+1] - x[i]
    if flag == 1:
        ans = fractions.gcd(c, b[i-1]) # 最大公約数を求める
    b.append(c)
    flag = 1
print(ans)

Fixed submission:
import fractions
a = list(map(int,input().split()))
N = a[0]
b = []
x = list(map(int,input().split()))
x.append(a[1])
x.sort()
flag = 0
for i in range(N):
    c = x[i+1] - x[i]
    if flag == 1:
        ans = fractions.gcd(c, ans) # 最大公約数を求める
    else:
        ans = c # 数列が一つの場合は差が答え
    b.append(c)
    flag = 1
print(ans)