Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**7)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

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

n,k = MAP()

for i in range(1,k+1):
    print(cmb(n-k+1,i)*cmb(k-1,i-1)%MOD)

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**7)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

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

n,k = MAP()

for i in range(1,k+1):
    try:
        print(cmb(n-k+1,i)*cmb(k-1,i-1)%MOD)
    except:
        print(0)
Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())

import math

def num(N,c,d):
    lcm = (c*d)//math.gcd(c,d)
    return N - (N//c) - (N//d) +  N//lcm

print(num(B,C,D)-num(A-1,C,D))


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

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

def num(N,c,d):
    lcm = (c*d)//gcd(c,d)
    return N - (N//c) - (N//d) +  N//lcm

print(num(B,C,D)-num(A-1,C,D))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D = map(int,input().split())

res = 0

for i in range(A,B+1):
    if (i%C != 0) and (i%D != 0):
        res += 1

print(res)

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

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

def num(N,c,d):
    lcm = (c*d)//gcd(c,d)
    return N - (N//c) - (N//d) +  N//lcm

print(num(B,C,D)-num(A-1,C,D))
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
*l, =  map(int, input().split())

point = 0
count = 0
while point <= x:
    point = point + l[count]
    count += 1

print(count)

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

d = [0]
count = 0
for i in range(n):
    d.append(d[i]+l[i])
for i in range(n+1):
    if d[i] <= x:
        count += 1
        
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
a = [INT() for _ in range(m)]

def fib(n):
    if (n==1) or (n==2):
        return 1
    else:
        return fib(n-1)+fib(n-2)

start = 0
ans = 1

for k in a:
    tmp = k-start
    if tmp==0:
        print(0)
        exit(0)
    ans *= fib(tmp)
    ans%=MOD
    start = k+1

ans*=fib(n-start+1)
ans%=MOD

print(ans)

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
a = [INT() for _ in range(m)]

# 高速版
def fib(n):
    if n <= 1:
        return n
    result = [1, 0, 0, 1]
    matrix = [1, 1, 1, 0]
    while n > 0:
        if n % 2:
            result = mul(matrix, result)
        matrix = mul(matrix, matrix)
        n //= 2
    return result[2]

def mul(a, b):
    return [a[0]*b[0] + a[1]*b[2],
            a[0]*b[1] + a[1]*b[3],
            a[2]*b[0] + a[3]*b[2],
            a[2]*b[1] + a[3]*b[3]]

start = 0
ans = 1

for k in a:
    tmp = k-start
    if tmp==0:
        print(0)
        exit(0)
    ans *= fib(tmp)
    ans%=MOD
    start = k+1

ans*=fib(n-start+1)
ans%=MOD

print(ans)

Buggy python submission (verdict: Runtime Error):
mod = 10**9+7
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]

def fib(n):
    if (n==1) or (n==2):
        return 1
    else:
        return fib(n-1)+fib(n-2)

start = 0
ans = 1

for k in a:
    tmp = k-start
    if tmp==0:
        print(0)
        exit(0)
    ans *= fib(tmp)
    ans%=mod
    start = k+1

ans*=fib(n-start+1)
ans%=mod

print(ans)

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
a = [INT() for _ in range(m)]

# 高速版
def fib(n):
    if n <= 1:
        return n
    result = [1, 0, 0, 1]
    matrix = [1, 1, 1, 0]
    while n > 0:
        if n % 2:
            result = mul(matrix, result)
        matrix = mul(matrix, matrix)
        n //= 2
    return result[2]

def mul(a, b):
    return [a[0]*b[0] + a[1]*b[2],
            a[0]*b[1] + a[1]*b[3],
            a[2]*b[0] + a[3]*b[2],
            a[2]*b[1] + a[3]*b[3]]

start = 0
ans = 1

for k in a:
    tmp = k-start
    if tmp==0:
        print(0)
        exit(0)
    ans *= fib(tmp)
    ans%=MOD
    start = k+1

ans*=fib(n-start+1)
ans%=MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
l,r = MAP()
res = set(range(l,r+1))
for i in range(m-1):
    l,r = MAP()
    res = res & set(range(l,r+1))

print(len(res))

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
l,r = [], []
for i in range(m):
    a,b = MAP()
    l.append(a)
    r.append(b)

max_l = max(l)
min_r = min(r)
if min_r<max_l:
    print(0)
    exit()
print(min_r-max_l+1)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
L = []
R = []
for idx in range(M):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

lst = []
result = 0
for idx in range(M):
    lst.append(range(L[idx],R[idx]+1))
for id in range(1,max(R)+1):
    flag = True
    for i in range(M):
        if (id in lst[i]) == False:
            flag = False
            break
    if flag == True:
        result += 1
print(result)

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
l,r = [], []
for i in range(m):
    a,b = MAP()
    l.append(a)
    r.append(b)

max_l = max(l)
min_r = min(r)
if min_r<max_l:
    print(0)
    exit()
print(min_r-max_l+1)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
L = []
R = []
for idx in range(M):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

lst = []
result = 0
for idx in range(M):
    lst.append(range(L[idx],R[idx]+1))
for id in range(1,N+1):
    flag = True
    for i in range(M):
        if (id in lst[i]) == False:
            flag = False
            break
    if flag == True:
        result += 1
print(result)

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
l,r = [], []
for i in range(m):
    a,b = MAP()
    l.append(a)
    r.append(b)

max_l = max(l)
min_r = min(r)
if min_r<max_l:
    print(0)
    exit()
print(min_r-max_l+1)
Buggy python submission (verdict: Runtime Error):
def MAP(): return map(int,input().split())
import math

n = int(input())
*a, = MAP()

mx = max(a)
a = sorted(a,key=lambda x:math.gcd(mx,x))
print(math.gcd(a[1],mx))

Fixed submission:
def MAP(): return map(int,input().split())
def gcd(a, b):
    while b:
        a %= b
        a, b = b, a
    return a

n = int(input())
*a, = MAP()

x=[0 for _ in range(n)]
y=[0 for _ in range(n)]
for i in range(1,n):
    x[i]=gcd(x[i-1],a[i-1])
for i in range(n-1)[::-1]:
    y[i]=gcd(y[i+1],a[i+1])
Z=[gcd(x[i],y[i]) for i in range(n)]
print(max(Z))

Buggy python submission (verdict: Runtime Error):
def MAP(): return map(int,input().split())
import math

n = int(input())
*a, = MAP()

mx = max(a)
a = sorted(a,key=lambda x:math.gcd(mx,x))
print(math.gcd(a[1],mx))

Fixed submission:
def MAP(): return map(int,input().split())
def gcd(a, b):
    while b:
        a %= b
        a, b = b, a
    return a

n = int(input())
*a, = MAP()

x=[0 for _ in range(n)]
y=[0 for _ in range(n)]
for i in range(1,n):
    x[i]=gcd(x[i-1],a[i-1])
for i in range(n-1)[::-1]:
    y[i]=gcd(y[i+1],a[i+1])
Z=[gcd(x[i],y[i]) for i in range(n)]
print(max(Z))
Buggy python submission (verdict: Runtime Error):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n,k = MAP()
s = input()
k*=2

lst = [0]
for i in range(n-1):
    if s[i]!=s[i+1]:
        lst.append(i+1)

r = len(lst)
lst += [n]*10
ans=[]
for i in range(r):
    if s[lst[i]]=="0":
        ans.append(lst[i+k] - lst[i])
    else:
        ans.append(lst[i+k+1] - lst[i])

print(max(ans))

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n,k = MAP()
s = input()
k*=2

lst = [0]
for i in range(n-1):
    if s[i]!=s[i+1]:
        lst.append(i+1)

r = len(lst)
lst += [n]
ans=[]
for i in range(r):
    if s[lst[i]]=="0":
        ans.append(lst[min(i+k,r)] - lst[i])
    else:
        ans.append(lst[min(i+k+1,r)] - lst[i])

print(max(ans))

Buggy python submission (verdict: Runtime Error):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n,k = MAP()
s = input()
k*=2

lst = [0]
for i in range(n-1):
    if s[i]!=s[i+1]:
        lst.append(i+1)

r = len(lst)
lst += [n]*10
ans=[]
for i in range(r):
    if s[lst[i]]=="0":
        ans.append(lst[i+k] - lst[max(i-1,0)])
    else:
        ans.append(lst[i+k+1] - lst[i])

print(max(ans))

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n,k = MAP()
s = input()
k*=2

lst = [0]
for i in range(n-1):
    if s[i]!=s[i+1]:
        lst.append(i+1)

r = len(lst)
lst += [n]
ans=[]
for i in range(r):
    if s[lst[i]]=="0":
        ans.append(lst[min(i+k,r)] - lst[i])
    else:
        ans.append(lst[min(i+k+1,r)] - lst[i])

print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

x,y,z,k = MAP()
a = MAP()
b = MAP()
c = MAP()

a.sort()
b.sort()

l = []
for i in a:
    for j in b:
        l.append(i+j)

l.sort()
c.sort()
l2 = []
for i in l[-k:]:
    for j in c[-k:]:
        l2.append(i+j)

l2.sort(reverse = True)
for i in l2[:k]:
    print(i)

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

x,y,z,k = MAP()
a = MAP()
b = MAP()
c = MAP()

a.sort()
b.sort()

l = []
for i in a:
    for j in b:
        l.append(i+j)

l.sort()
c.sort()
l2 = []
for i in l[-k:]:
    for j in c[-k:]:
        l2.append(i+j)

l2.sort(reverse = True)
for i in l2[:k]:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return map(int,input().split())

n,q = MAP()
s = list(input())
lr = [input().split() for _ in range(q)]
AC_place =[]

for i in range(n-1):
    if s[i]+s[i+1]=="AC":
        AC_place.append(i)

for i in lr:
    tmp=0
    for j in range(int(i[0])-1,int(i[1])-1):
        if j in AC_place:
            tmp+=1
    print(tmp)

Fixed submission:
def MAP(): return map(int,input().split())

n,q = MAP()
s = input()
t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i]+(1 if s[i:i+2]=="AC" else 0)
for i in range(q):
    l,r = MAP()
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return map(int,input().split())

n,q = MAP()
s = list(input())
lr = [input().split() for _ in range(q)]
AC_place =[]

for i in range(n-1):
    if s[i]+s[i+1]=="AC":
        AC_place.append(i)

for i in lr:
    tmp=0
    for j in range(int(i[0])-1,int(i[1])-1):
        if j in AC_place:
            tmp+=1
    print(tmp)

Fixed submission:
def MAP(): return map(int,input().split())

n,q = MAP()
s = input()
t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i]+(1 if s[i:i+2]=="AC" else 0)
for i in range(q):
    l,r = MAP()
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
flag = True
cnt=0

while flag:
    flag = False
    n = len(s)
    for i in range(n-1):
        k = s[i]+s[i+1]
        if (k=="01") or (k=="10"):
            del(s[i:i+2])
            flag = True
            cnt+=1
            break

print(cnt*2)

Fixed submission:
s = list(input())

print(min(s.count("0"),s.count("1"))*2)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
flag = True
cnt=0

while flag:
    flag = False
    n = len(s)
    for i in range(n-1):
        k = s[i]+s[i+1]
        if (k=="01") or (k=="10"):
            del(s[i:i+2])
            flag = True
            cnt+=1
            break

print(cnt*2)

Fixed submission:
s = list(input())

print(min(s.count("0"),s.count("1"))*2)
Buggy python submission (verdict: Runtime Error):
def MAP(): return list(map(int,input().split()))
import math

n = int(input())
A = MAP()

tmp=A[0]
for i in range(1,n):
    tmp = math.gcd(tmp,A[i])
print(tmp)

Fixed submission:
def MAP(): return list(map(int,input().split()))
import fractions

n = int(input())
A = MAP()

tmp=A[0]
for i in range(1,n):
    tmp = fractions.gcd(tmp,A[i])
print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0

for i in range(n):
    for j in range(1,k+1):
        if i+j>=n:
            break
        dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[n-1])

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,k = MAP()
h = MAP()

dp = [MOD]*n
dp[0]=0

for i in range(n-1):
    for j in range(i+1,min(i+k+1,n)):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[n-1])

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

dp = [10**9]*n
dp[0] = 0

for i in range(n):
    for j in range(1,k+1):
        if i+j>=n:
            break
        dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
    print(dp)

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,k = MAP()
h = MAP()

dp = [MOD]*n
dp[0]=0

for i in range(n-1):
    for j in range(i+1,min(i+k+1,n)):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,k = MAP()
h = MAP()

dp = [MOD]*n
dp[0]=0

for i in range(n-1):
    for j in range(i+1,min(i+k+1,n)):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[n-1])

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,k = MAP()
h = MAP()

dp = [MOD]*n
dp[0]=0

for i in range(n-1):
    for j in range(i+1,min(i+k+1,n)):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,W = MAP()
weight=[]
value=[]
for i in range(N):
    w,v = MAP()
    weight.append(w)
    value.append(v)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if sum_w-weight[i]>=0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i])

        dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w])

print(dp[N][W])

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,W = MAP()
weight=[]
value=[]
for i in range(N):
    w,v = MAP()
    weight.append(w)
    value.append(v)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if sum_w-weight[i]>=0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i])

        dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w])

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,W = MAP()
weight=[]
value=[]
for i in range(N):
    w,v = MAP()
    weight.append(w)
    value.append(v)
MAX_V = 100100

dp = [[MOD]*(MAX_V+1) for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(MAX_V):
        if sum_v - value[i]>=0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v-value[i]]+weight[i])
        dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v])


for sum_v in range(MAX_V):
    if dp[N][sum_v]<=W:
        res=sum_v
print(res)

Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,W = MAP()
weight=[]
value=[]
for i in range(N):
    w,v = MAP()
    weight.append(w)
    value.append(v)
MAX_V = 100100

dp = [[MOD]*(MAX_V+1) for _ in range(N+1)]
dp[0][0]=0

for i in range(N):
    for sum_v in range(MAX_V):
        if sum_v - value[i]>=0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v-value[i]]+weight[i])
        dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v])


for sum_v in range(MAX_V):
    if dp[N][sum_v]<=W:
        res=sum_v
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

s = input()
t = input()
n = len(s)
m = len(t)

pre = [[0]*(m+1) for _ in range(n+1)]
dp = [[0]*(m+1) for _ in range(n+1)]

for si in range(n):
    for ti in range(m):
        if s[si]==t[ti]:
            dp[si+1][ti+1] = dp[si][ti]+1
        else:
            dp[si+1][ti+1] = max(dp[si+1][ti],dp[si][ti+1])

ans = ""
x = dp[-1][-1]
for i in range(n,-1,-1):
    for j in range(m,-1,-1):
        if dp[i][j]==x:
            if (dp[i-1][j]==x-1) and (dp[i][j-1]==x-1):
                ans = s[i-1]+ans
                x-=1
                break
print(ans)


Fixed submission:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

s = input()
t = input()
n = len(s)
m = len(t)

pre = [[0]*(m+1) for _ in range(n+1)]
dp = [[0]*(m+1) for _ in range(n+1)]

for si in range(n):
    for ti in range(m):
        if s[si]==t[ti]:
            dp[si+1][ti+1] = dp[si][ti]+1
        else:
            dp[si+1][ti+1] = max(dp[si+1][ti],dp[si][ti+1])

ans = ""
x = dp[-1][-1]
for i in range(n,-1,-1):
    for j in range(m,-1,-1):
        if dp[i][j]==x:
            if (dp[i-1][j]==x-1) and (dp[i][j-1]==x-1):
                ans = s[i-1]+ans
                x-=1
                break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,M = MAP()
Y = [0]*(10**5)
P = [0]*(10**5)
yd =[[] for _ in range(N)]
for i in range(M):
    p,y = MAP()
    P[i] = p-1
    Y[i] = y
    yd[p-1].append(y)

for i in range(N):
    yd[i].sort()

for i in range(M):
    print("{0:06d}".format(P[i]+1),end="")
    print("{0:06d}".format(yd[P[i]].index(Y[i])+1))

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,M = MAP()
Y = [0]*(10**5)
P = [0]*(10**5)
yd =[[] for _ in range(N)]
for i in range(M):
    p,y = MAP()
    P[i] = p-1
    Y[i] = y
    yd[p-1].append(y)

for i in range(N):
    yd[i].sort()

for i in range(M):
    print("{0:06d}".format(P[i]+1),end="")
    print("{0:06d}".format(bisect.bisect_left(yd[P[i]],Y[i])+1))

Buggy python submission (verdict: Time Limit Exceeded):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,M = MAP()
Y = [0]*(10**5)
P = [0]*(10**5)
yd =[[] for _ in range(N)]
for i in range(M):
    p,y = MAP()
    P[i] = p-1
    Y[i] = y
    yd[p-1].append(y)

for i in range(N):
    yd[i].sort()

for i in range(M):
    print("{0:06d}".format(P[i]+1),end="")
    print("{0:06d}".format(yd[P[i]].index(Y[i])+1))

Fixed submission:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N,M = MAP()
Y = [0]*(10**5)
P = [0]*(10**5)
yd =[[] for _ in range(N)]
for i in range(M):
    p,y = MAP()
    P[i] = p-1
    Y[i] = y
    yd[p-1].append(y)

for i in range(N):
    yd[i].sort()

for i in range(M):
    print("{0:06d}".format(P[i]+1),end="")
    print("{0:06d}".format(bisect.bisect_left(yd[P[i]],Y[i])+1))