Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys,itertools,copy
input = sys.stdin.readline
N=int(input().strip())
an=[int(x) for x in input().strip().split()]

if N==3:
    if an[0]^an[1]==an[2]:
        print("Yes")
    else:
        print("No")
elif N%3!=0:
    if len(set(an))==1:
        print("Yes")
    else:
        print("No")
else:
    bn = list(set(an))
    if bn[0]^bn[1]!=bn[2]:
        print("No")
    else:
        for b in bn:
            if an.count(b)%(N/3)!=0:
                print("No")
                break
        else:
            print("Yes")

Fixed submission:
import sys,itertools,copy
input = sys.stdin.readline
N=int(input().strip())
an=[int(x) for x in input().strip().split()]

if N==3:
    if an[0]^an[1]==an[2]:
        print("Yes")
    else:
        print("No")
elif N%3!=0:
    if len(set(an))==1:
        print("Yes")
    else:
        print("No")
else:
    bn = list(set(an))
    if len(bn)>3:
        print("No")
    elif len(bn)==1:
        if bn[0]==0:
            print("Yes")
        else:
            print("No")
    elif len(bn)==2:
        if an.count(0)==(N/3):
            print("Yes")
        else:
            print("No")
    elif bn[0]^bn[1]!=bn[2]:
        print("No")
    else:
        for b in bn:
            if an.count(b)!=(N/3):
                print("No")
                break
        else:
            print("Yes")
Buggy python submission (verdict: Runtime Error):
import sys
from itertools import combinations, permutations
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
d = {}

pascals_triangle = [1] * 2001
pascals_triangle[0] = [1]
for i in range(1, 2001):
    pascals_triangle[i] = [pascals_triangle[i-1][0]] * (i+1)
    for j in range(1, i):
        pascals_triangle[i][j] = pascals_triangle[i-1][j-1] + pascals_triangle[i-1][j]

for i in range(1, K + 1):
    ans = 0
    blue_ball = pascals_triangle[K-1][i-1]
    red_ball = pascals_triangle[N-K+1][i]
    ans += (blue_ball * red_ball) % (10 ** 9 + 7)
    print(ans)

Fixed submission:
import sys
from itertools import combinations, permutations
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
d = {}

pascals_triangle = [1] * 2001
pascals_triangle[0] = [1]
for i in range(1, 2001):
    pascals_triangle[i] = [pascals_triangle[i-1][0]] * (i+1)
    for j in range(1, i):
        pascals_triangle[i][j] = pascals_triangle[i-1][j-1] + pascals_triangle[i-1][j]

for i in range(1, K + 1):
    if i > N - K + 1:
        print(0)
        continue
    ans = 0
    blue_ball = pascals_triangle[K-1][i-1]
    red_ball = pascals_triangle[N-K+1][i]
    ans += (blue_ball * red_ball) % (10 ** 9 + 7)
    print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
from itertools import combinations, permutations
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
d = {}

def pascals_triangle(a, b):
    l = [1]
    for i in range(2, a+2):
        l_ = l[:]
        l = [l_[0]] * i
        for j in range(1, i - 1):
            l[j] = l_[j-1] + l_[j]
    return l[b]
            
for i in range(1, K + 1):
    ans = 0
    if not (K-1, i-1) in d:
        d[(K-1, i-1)] = pascals_triangle(K-1, i-1)    
    blue_ball = d[(K-1, i-1)]
    if not (N-K+1, i) in d:
        d[(N-K+1, i)] = pascals_triangle(N-K+1, i)
    red_ball = d[(N-K+1, i)]
    ans += (blue_ball * red_ball) % (10 ** 9 + 7)
    print(ans)

Fixed submission:
import sys
from itertools import combinations, permutations
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
d = {}

pascals_triangle = [1] * 2001
pascals_triangle[0] = [1]
for i in range(1, 2001):
    pascals_triangle[i] = [pascals_triangle[i-1][0]] * (i+1)
    for j in range(1, i):
        pascals_triangle[i][j] = pascals_triangle[i-1][j-1] + pascals_triangle[i-1][j]

for i in range(1, K + 1):
    if i > N - K + 1:
        print(0)
        continue
    ans = 0
    blue_ball = pascals_triangle[K-1][i-1]
    red_ball = pascals_triangle[N-K+1][i]
    ans += (blue_ball * red_ball) % (10 ** 9 + 7)
    print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = [int(x) for x in input().split()]
LN = [int(x) for x in input().split()]
p = 0
c = 1
while True:
  if p + LN[c-1] <= X:
    p += LN[c-1]
    c += 1
  else:
    break
print(c)

Fixed submission:
N, X = [int(x) for x in input().split()]
LN = [int(x) for x in input().split()]
p = 0
c = 1
while True:
  if p + LN[c-1] <= X:
    p += LN[c-1]
    c += 1
    if c > len(LN):
      break
  else:
    break
print(c)
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    N = int(input())
    XY = sorted([tuple([int(x) for x in input().strip().split()]) for _ in range(N)], key=lambda x: x[0])
    dic = defaultdict(int)
    for d in range(1, N):
        for i in range(N-d):
            if XY[i+d][1] > XY[i][1]:
                dic[(XY[i+d][0]-XY[i][0], XY[i+d][1]-XY[i][1])] += 1

    print(N-max(dic.values()))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    N = int(input())
    if N == 1:
        print(1)
        exit()
    XY = [0] * N
    for i, (x, y) in enumerate([[int(x) for x in input().strip().split()] for _ in range(N)]):
        XY[i] = (x, y)
    XY.sort(key=lambda x:(x[0], x[1]))

    dic = defaultdict(int)
    for d in range(1, N):
        for i in range(N-d):
            dic[(XY[i+d][0]-XY[i][0], XY[i+d][1]-XY[i][1])] += 1
            dic[(XY[i][0]-XY[i+d][0], XY[i][1]-XY[i+d][1])] += 1

    print(N-max(dic.values()))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
A = sorted([int(x) for x in input().strip().split()])
BC = [0] * M

for m in range(M):
    BC[m] = tuple([int(x) for x in input().strip().split()])

BC.sort(reverse=True, key=lambda x: x[1])

offset = 0
ans = 0
for i, bc in enumerate(BC):
    if offset >= len(A):
        break
    if bc[1] >= A[min(offset+bc[0]-1, len(A)-1)]:
        ans += min(bc[0], len(A[offset:])) * bc[1]
        offset += bc[0]
        continue
    elif bc[1] <= A[offset]:
        ans += sum(A[offset:])
        break
    else:
        c = 0
        while bc[1] >= A[offset+c]:
            ans += bc[1]
            c += 1
        else:
            offset += c
else:
    if offset < len(A):
        ans += sum(A[offset:])
print(ans)

Fixed submission:
import sys
from bisect import bisect_left
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
A = sorted([int(x) for x in input().strip().split()])
BC = [0] * M

for m in range(M):
    BC[m] = tuple([int(x) for x in input().strip().split()])

BC.sort(reverse=True, key=lambda x: x[1])

offset = 0
ans = 0
for i, bc in enumerate(BC):
    if offset >= len(A):
        break
    if bc[1] >= A[min(offset+bc[0]-1, len(A)-1)]:
        ans += min(bc[0], N - offset) * bc[1]
        offset += bc[0]
        continue
    elif bc[1] <= A[offset]:
        ans += sum(A[offset:])
        break
    else:
        c = 0
        while bc[1] >= A[offset+c]:
            ans += bc[1]
            c += 1
        else:
            offset += c
else:
    if offset < len(A):
        ans += sum(A[offset:])
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K=[int(x) for x in input().split()]
S=input()
print(S[:K]+S[K].lower()+S[min(K+1,N-1):])

Fixed submission:
N,K=[int(x) for x in input().split()]
S=input()
print(S[:K-1]+S[K-1].lower()+S[K:])

Buggy python submission (verdict: Runtime Error):
N,K=[int(x) for x in input().split()]
S=input()
print(S[:K]+S[K].lower()+S[min(K+1,N-1)]:)

Fixed submission:
N,K=[int(x) for x in input().split()]
S=input()
print(S[:K-1]+S[K-1].lower()+S[K:])
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
L = [deque([]) for _ in range(N)]
ans = [-1] * N

for n in range(N-1):
    u, v, w = [int(x) for x in input().strip().split()]
    L[u-1].append((v, w))
    L[v-1].append((u, w))

def dfs(x, w):
    if ans[x-1] >= 0:
        return
    ans[x-1] = w % 2
    for nx, w_ in L[x-1]:
        dfs(nx, (w + w_) % 2)
    return

dfs(1, 0)

for a in ans:
    print(a)

Fixed submission:
import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
L = [deque([]) for _ in range(N)]
ans = [-1] * N

for n in range(N-1):
    u, v, w = [int(x) for x in input().strip().split()]
    L[u-1].append((v, w))
    L[v-1].append((u, w))

def dfs(x, w):
    if ans[x-1] >= 0:
        return
    ans[x-1] = w % 2
    for nx, w_ in L[x-1]:
        dfs(nx, (w + w_) % 2)
    return

dfs(1, 0)

for a in ans:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys,math,copy
from fractions import gcd
input = sys.stdin.readline

N=int(input().strip())
A=[int(x) for x in input().strip().split()]
# def gcd(a,b):
#     if b==0:
#         return a
    
#     return gcd(b,a%b)

ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[i]))
    R=[gcd(A[-1-i],R[0])]+R

for i in range(len(L)-1):
    ANS.append(gcd(L[i],R[i+1]))

print(max(ANS))


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

N=int(input().strip())
A=[int(x) for x in input().strip().split()]
# def gcd(a,b):
#     if b==0:
#         return a
    
#     return gcd(b,a%b)

ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[-1]))
    R.append(gcd(A[-1-i],R[-1]))

R.reverse()
for i in range(len(L)-1):
    ANS.append(gcd(L[i],R[i+1]))

print(max(ANS))

Buggy python submission (verdict: Time Limit Exceeded):
import sys,math,copy
input = sys.stdin.readline

N=int(input().strip())
A=[int(x) for x in input().strip().split()]
def gcd(a,b):
    if b==0:
        return a
    
    return gcd(b,a%b)

ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[i]))
    R=[gcd(A[-1-i],R[0])]+R

for i in range(len(L)-1):
    ANS.append(gcd(L[i],R[i+1]))

print(max(ANS))


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

N=int(input().strip())
A=[int(x) for x in input().strip().split()]
# def gcd(a,b):
#     if b==0:
#         return a
    
#     return gcd(b,a%b)

ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[-1]))
    R.append(gcd(A[-1-i],R[-1]))

R.reverse()
for i in range(len(L)-1):
    ANS.append(gcd(L[i],R[i+1]))

print(max(ANS))

Buggy python submission (verdict: Time Limit Exceeded):
import sys,math,copy
input = sys.stdin.readline

N=int(input().strip())
A=[int(x) for x in input().strip().split()]
def gcd(a,b):
    if b==0:
        return a
    
    return gcd(b,a%b)

ANS=[]
for i in range(len(A)):
    B=copy.deepcopy(A)
    if len(B)>1:
        B.pop(i)
    t=0
    for c in range(len(B)):
        t=gcd(B[c],t)
    ANS.append(t)

print(max(ANS))


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

N=int(input().strip())
A=[int(x) for x in input().strip().split()]
# def gcd(a,b):
#     if b==0:
#         return a
    
#     return gcd(b,a%b)

ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[-1]))
    R.append(gcd(A[-1-i],R[-1]))

R.reverse()
for i in range(len(L)-1):
    ANS.append(gcd(L[i],R[i+1]))

print(max(ANS))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(x) for x in input().split()]
B=[x for x in A if x<0]

if len(B)%2==0:
  minus=0
else:
  minus=max(B)
  
print(sum(A)+B)

Fixed submission:
N=int(input())
A=[int(x) for x in input().split()]
B=[x for x in A if x<0]
absA=[abs(x) for x in A]
if len(B)%2==0:
  minus=0
else:
  minus=min(absA)
  
print(sum(absA)-minus*2)
Buggy python submission (verdict: Runtime Error):
import sys,re,copy
input = sys.stdin.readline

N,K=[int(x) for x in input().strip().split()]

f=1
cnt=0
S=[]
r=0
for s in input().strip():
    s=int(s)
    if s==f:
        cnt+=1
    else:
        r+=cnt
        S.append(r)
        cnt=1
        f=1-f
else:
    r+=cnt
    S.append(r)
if len(S)%2==0:
    S.append(r)

Max=0
i=0
if len(S)==1:
    Max=S[0]
else:
    while True:
        r=i+2*K
        cnt=S[min(r,len(S)-1)]-S[max(i-1,0)]
        if cnt > Max:
            Max = cnt
        i+=2

print(Max)

Fixed submission:
import sys,re,copy
input = sys.stdin.readline

N,K=[int(x) for x in input().strip().split()]

f=1
cnt=0
S=[]
r=0
for s in input().strip():
    s=int(s)
    if s==f:
        cnt+=1
    else:
        r+=cnt
        S.append(r)
        cnt=1
        f=1-f
else:
    r+=cnt
    S.append(r)
if len(S)%2==0:
    S.append(r)

Max=0
i=0
if len(S)==1:
    Max=S[0]
else:
    while True:
        if i >=len(S):
            break
        r=i+2*K
        cnt=S[min(r,len(S)-1)]-S[max(i-1,0)]
        if cnt > Max:
            Max = cnt
        i+=2

print(Max)

Buggy python submission (verdict: Time Limit Exceeded):
import sys,re,copy
input = sys.stdin.readline

N,K=[int(x) for x in input().strip().split()]
S=input().strip()
Z=[len(x) for x in re.split(r'1+',S)]
O=[len(x) for x in re.split(r'0+',S)]

m=0
i=0
if S[0]=='1':
    Z.pop(0)
l1=len(O)
l0=len(Z)
while True:
    c=sum(O[i:i+K+1])+sum(Z[i:i+K])
    if c > m:
        m = c
    i+=1
    if i+K>l1 or i+K>l0:
        break

print(m)

Fixed submission:
import sys,re,copy
input = sys.stdin.readline

N,K=[int(x) for x in input().strip().split()]

f=1
cnt=0
S=[]
r=0
for s in input().strip():
    s=int(s)
    if s==f:
        cnt+=1
    else:
        r+=cnt
        S.append(r)
        cnt=1
        f=1-f
else:
    r+=cnt
    S.append(r)
if len(S)%2==0:
    S.append(r)

Max=0
i=0
if len(S)==1:
    Max=S[0]
else:
    while True:
        if i >=len(S):
            break
        r=i+2*K
        cnt=S[min(r,len(S)-1)]-S[max(i-1,0)]
        if cnt > Max:
            Max = cnt
        i+=2

print(Max)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N,Q=[int(x) for x in input().strip().split()]
S=input().strip()

for _ in range(Q):
    l,r=[int(x) for x in input().strip().split()]
    print(S[l-1:r].count('AC'))

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

N,Q=[int(x) for x in input().strip().split()]
S=input().strip()
n=[]
cnt=0
p=''
for s in S:
    if p=='A' and s =='C':
        cnt+=1
        p=''
    else:
        p=s
    n.append(cnt)

for _ in range(Q):
    l,r=[int(x) for x in input().strip().split()]
    ans = n[r-1]-n[l-1]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

A,B=[int(x) for x in input().strip().split()]
ans=[]
if A==B:
    print(A)
else:
    for i in range(40):
        if i >= 1:
            numList=[]
            temp=A
            while True:
                if format(temp,'040b')[39-i]=='1':
                    numList.append(temp)
                    temp+=1
                else:
                    break
            temp=B
            while True:
                if format(temp,'040b')[39-i]=='1':
                    numList.append(temp)
                    temp-=1
                else:
                    break
        else:
            numList=[x for x in range(A,B+1)]
        temp=0
        for c,num in enumerate(numList):
            temp=temp^num
        temp=format(temp,'040b')
        ans.append(temp[39-i])
    ans.reverse()
    print(int(''.join(ans),2))


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

def main():
    def count1(d, i):
        i2 = 2 ** i
        ret = (d // i2) * (i2 // 2)
        d -= 2 * ret
        if d >= i2 // 2:
            ret += d - (i2 // 2) + 1
        return ret

    A, B = [int(x) for x in input().strip().split()]
    ans = 0
    for i in range(40):
        ans += ((count1(B, i+1) - count1(A-1, i+1)) % 2) * 2 ** i
    
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
S=list(input().strip())

flag=True
cnt=0
i=0
f=[]
if len(S) != 1:
    while flag:
        if S[i] != S[i+1]:
            f.append(i)
            f.append(i+1)
            i+=2
        else:
            i+=1
        if i>=len(S)-1:
            cnt+=len(f)
            f.reverse()
            for k in f:
                S.pop(k)
            f=[]
            if '1' not in S or '0' not in S:
                break
            i=0
print(cnt)

Fixed submission:
import sys
input = sys.stdin.readline
S=list(input().strip())
zero=S.count('0')
one=S.count('1')
print(min(zero,one)*2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

N, K = [int(x) for x in input().strip().split()]
highest = 0
lowest = 10 ** 9
q = deque([])
ans = 10 ** 9
pre = -1
H = sorted([int(input()) for _ in range(N)])
for n, ne in enumerate(H):
    q.append(ne)
    if len(q) > K:
        pre = q.popleft()
    if ne > highest:
        highest = ne
    if ne < lowest:
        lowest = ne
    if pre == highest:
        highest = max(q)
    if pre == lowest:
        lowest = min(q)
    if n >= K - 1:
        ans = min(ans, highest - lowest)

print(ans)

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

N, K = [int(x) for x in input().strip().split()]
H = sorted([int(input()) for _ in range(N)])
ans = 10 ** 9
for n in range(N - (K - 1)):
    ans = min(ans, H[n+K-1] - H[n])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

N, K = [int(x) for x in input().strip().split()]
highest = 0
lowest = 10 ** 9
high = [0] * N
low = [0] * N
q = deque([])
ans = 10 ** 9
pre = -1
H = sorted([int(input()) for _ in range(N)])
for n, ne in enumerate(H):
    q.append(ne)
    if len(q) > K:
        pre = q.popleft()
    if ne > highest:
        highest = ne
    if ne < lowest:
        lowest = ne
    if pre == highest:
        highest = max(q)
    if pre == lowest:
        lowest = min(q)
    if n >= K - 1:
        ans = min(ans, highest - lowest)

print(ans)

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

N, K = [int(x) for x in input().strip().split()]
H = sorted([int(input()) for _ in range(N)])
ans = 10 ** 9
for n in range(N - (K - 1)):
    ans = min(ans, H[n+K-1] - H[n])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

N, K = [int(x) for x in input().strip().split()]
highest = 0
lowest = 10 ** 9
high = [0] * N
low = [0] * N
q = deque([])
ans = 10 ** 9
pre = -1
H = sorted([int(input()) for _ in range(N)])
for n, ne in enumerate(H):
    q.append(ne)
    if len(q) > K:
        pre = q.popleft()
    if ne > highest:
        highest = ne
    if ne < lowest:
        lowest = ne
    if pre == highest:
        highest = max(q)
    if pre == lowest:
        lowest = min(q)
    high[n] = highest
    low[n] = lowest
    if n >= K - 1:
        ans = min(ans, highest - lowest)

print(ans)

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

N, K = [int(x) for x in input().strip().split()]
H = sorted([int(input()) for _ in range(N)])
ans = 10 ** 9
for n in range(N - (K - 1)):
    ans = min(ans, H[n+K-1] - H[n])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

N, M = [int(x) for x in input().strip().split()]
NL = [deque([]) for n in range(10 ** 5)]

IN = [0] * M
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].append(y)

for i, nl in enumerate(NL):
    NL[i] = sorted(nl)

for p, y in IN:
    print('{:06d}{:06d}'.format(p, NL[p-1].index(y) + 1))



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

N, M = [int(x) for x in input().strip().split()]
NL = [deque([]) for n in range(10 ** 5)]

IN = [0] * M
d = {}
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].append(y)

for p, nl in enumerate(NL, start=1):
    d[p] = {}
    for i, n in enumerate(sorted(nl), start=1):
        d[p][n] = i

for p, y in IN:
    print('{:06d}{:06d}'.format(p, d[p][y]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

N, M = [int(x) for x in input().strip().split()]
NL = [[] for n in range(10 ** 5)]

IN = [0] * M
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].insert(bisect.bisect_left(NL[p-1], y), y)

for p, y in IN:
    print('{:06d}{:06d}'.format(p, NL[p-1].index(y) + 1))



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

N, M = [int(x) for x in input().strip().split()]
NL = [deque([]) for n in range(10 ** 5)]

IN = [0] * M
d = {}
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].append(y)

for p, nl in enumerate(NL, start=1):
    d[p] = {}
    for i, n in enumerate(sorted(nl), start=1):
        d[p][n] = i

for p, y in IN:
    print('{:06d}{:06d}'.format(p, d[p][y]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

N, M = [int(x) for x in input().strip().split()]
NL = [[] for n in range(10 ** 5)]

IN = [0] * M
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].insert(bisect.bisect_left(NL[p-1], y), y)

for p, y in IN:
    print('{:06d}{:06d}'.format(p, NL[p-1].index(y) + 1))



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

N, M = [int(x) for x in input().strip().split()]
NL = [deque([]) for n in range(10 ** 5)]

IN = [0] * M
d = {}
for m in range(M):
    IN[m] = tuple([int(x) for x in input().strip().split()]) 

for p, y in IN:
    NL[p-1].append(y)

for p, nl in enumerate(NL, start=1):
    d[p] = {}
    for i, n in enumerate(sorted(nl), start=1):
        d[p][n] = i

for p, y in IN:
    print('{:06d}{:06d}'.format(p, d[p][y]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().strip().split())
ans = 1
if N == 1:
    print(M)
    exit()
while ans > 0:
    ans = M // N
    if M % ans == 0 and M / ans >= N:
        break
    N += 1
print(ans)

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

N, M = map(int, input().strip().split())
ans = 1
if N == 1:
    print(M)
    exit()

for n in range(2, int(M ** 0.5) +1):
    if M % n == 0:
        if n < N and M // n < N:
            continue
        elif n >= N and M // n < N:
            ans = max(ans, M // n)
        elif n < N and M // n >= N:
            ans = max(ans, n)
        else:
            ans = max(ans, n, M // n)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().strip().split())
ans = 1
while ans > 0:
    ans = M // N
    if M % ans == 0 and M / ans >= N:
        break
    N += 1
print(ans)

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

N, M = map(int, input().strip().split())
ans = 1
if N == 1:
    print(M)
    exit()

for n in range(2, int(M ** 0.5) +1):
    if M % n == 0:
        if n < N and M // n < N:
            continue
        elif n >= N and M // n < N:
            ans = max(ans, M // n)
        elif n < N and M // n >= N:
            ans = max(ans, n)
        else:
            ans = max(ans, n, M // n)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, M = map(int, input().strip().split())
ans = 1
while ans > 0:
    ans = M // N
    if M % ans == 0 and M / ans >= N:
        break
    N += 1
print(ans)

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

N, M = map(int, input().strip().split())
ans = 1
if N == 1:
    print(M)
    exit()

for n in range(2, int(M ** 0.5) +1):
    if M % n == 0:
        if n < N and M // n < N:
            continue
        elif n >= N and M // n < N:
            ans = max(ans, M // n)
        elif n < N and M // n >= N:
            ans = max(ans, n)
        else:
            ans = max(ans, n, M // n)

print(ans)