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

Fixed submission:
# abc_111_a

def transform (bango):
    if bango == "1":
        return "9"
    elif bango == "9":
        return "1"
    else:
        return bango

def solve(string):
    return "".join(list(map(transform, string)))

if __name__ == "__main__":
    string = input("")
    print (solve(string))

Buggy submission (verdict: Runtime Error):
# abc111_c_new

from collections import Counter


def solve(n, seq):
    odd = seq[::2]  # odd numbers of the seq
    even = seq[1::2]  # even numbers of the seq

    # print(odd)
    # print(even)

    # odd = Counter(odd).most_common()  # example -> returns [(1, 5), (2, 5)]
    # even = Counter(even).most_common()
    odd = sorted([(k, v) for k, v in Counter(odd).items()], key=lambda x: x[1], reverse=True)
    even = sorted([(k, v) for k, v in Counter(even).items()], key=lambda x: x[1], reverse=True)

    # print(odd)
    # print(even)

    sol = 0
    if odd[0][0] == even[0][0]:
        if len(odd) == 1 and len(even) == 1:  # seq [1, 1, 1, 1]  (special case)
            sol = int(n // 2)  # [1, 1, 1, 1] sol = N / 2
        else:
            if odd[0][1] > even[1][1]:
                # sol = n - odd[0][1] - even[1][1] ==
                sol = (n // 2 - odd[0][1]) + (n // 2 - even[1][1])
            else:
                # sol = n - odd[1][1] - even[0][1] ==
                sol = (n // 2 - odd[1][1]) + (n // 2 - even[0][1])
    else:
        # sol = n - odd[0][1] - even[0][1] ==
        sol = (n // 2 - odd[0][1]) + (n // 2 - even[0][1])

    return sol


if __name__ == "__main__":
    n = int(input())
    seq = list(map(int, input("").split(" ")))
    print(solve(n, seq))

Buggy submission (verdict: Runtime Error):
# abc111_c_new


from collections import Counter


def solve(n, seq):
    odd = seq[::2]                      # odd numbers of the seq
    even = seq[1::2]                    # even numbers of the seq

    odd = Counter(odd).most_common()    # example -> returns [(1, 5), (2, 5)]
    even = Counter(even).most_common()

    sol = 0
    if odd[0][0] == even[0][0]:
        if len(odd) == 1 and len(even) == 1:
            sol = int(n / 2)
        else:
            if odd[1][1] > even[1][1]:
                sol = n - odd[1][1] - even[0][1]
            else:
                sol = n - odd[0][1] - even[1][1]
    else:
        sol = n - odd[0][1] - even[0][1]

    return sol


if __name__ == "__main__":
    n = int(input())
    seq = list(map(int, input("").split(" ")))
    print(solve(n, seq))
Problem p03041 (python)

Fixed submission:
n, k = list(map(int, input().split()))
k = k - 1
s = input()

s = s[:k] + s[k].lower() + s[k+1:]

print(s)

Buggy submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
s = list(input())
s[k] = s[k].lower()
print("".join(s))
Problem p03045 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**6)

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

counter = 0
c = [-1 for i in range(n)]
p = [[] for n in range(n)]

for i in range(m):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    p[x].append(y)
    p[y].append(x)

def dfs(num, depth):
    if c[num] != -1:
        return
    else:
        c[num] = depth
    for i in p[num]:
        dfs(i, depth)

for i in range(n):
    if c[i] == -1:
        counter += 1
        dfs(i, counter)

print(max(c))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**5)

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

counter = 0
c = [-1 for i in range(n)]
p = [[] for n in range(n)]

for i in range(m):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    p[x].append(y)
    p[y].append(x)

def dfs(num, depth):
    if c[num] != -1:
        return
    else:
        c[num] = depth
    for i in p[num]:
        dfs(i, depth)

for i in range(n):
    if c[i] == -1:
        counter += 1
        dfs(i, counter)

print(max(c))

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

counter = 0
c = [-1 for i in range(n)]
p = [[] for n in range(n)]

for i in range(m):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    p[x].append(y)
    p[y].append(x)

def dfs(num, depth):
    if c[num] != -1:
        return
    else:
        c[num] = depth
    for i in p[num]:
        dfs(i, depth)

for i in range(n):
    if c[i] == -1:
        counter += 1
        dfs(i, counter)

print(max(c))
Problem p03295 (python)

Fixed submission:
def main():
    n = [int(i) for i in input().split()]
    bridge = set()
    counter = 0
    reqs = [[int(j) for j in input().split()] for i in range(n[1])]
    reqs.sort(key=lambda x:(x[0],x[1]))
    
    preset = 0
    for i in range(1, n[0]+1):
        if i in bridge:
            bridge.clear()
            counter += 1
        for j in range(preset, len(reqs)):
            if reqs[j][0] == i:
                bridge.add(reqs[j][1])
            else:
                preset = j
                break
    
    print(counter)

main()

Buggy submission (verdict: Runtime Error):
def main():
    n = [int(i) for i in input().split()]
    bridge = set()
    counter = 0
    reqs = [[int(j) for j in input().split()] for i in range(n[1])]
    reqs.sort(key=lambda x:(x[0],x[1]))
    
    preset = 0
    for i in range(1, n[0]+1):
        if i in bridge:
            bridge = []
            counter += 1
        for j in range(preset, len(reqs)):
            if reqs[j][0] == i:
                bridge.add(reqs[j][1])
            else:
                preset = j
                break
    
    print(counter)

main()
Problem p03041 (python)

Fixed submission:
N, K = map(int,input().split())
S = input()
S = list(S)
S[K-1] = S[K-1].lower()
print(''.join(S))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
S = input()
S = list(S)
S[K-1] = S[K-1].lower()
print(''.join(S)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
S = input()
S = list(S)
S[K] = S[K].lower()
print(S)

Buggy submission (verdict: Runtime Error):
N, K = input().split()
N = list(N)
N[int(K)] = N[int(K)].lower()
print(''.join(N))

Buggy submission (verdict: Runtime Error):
N, K = input().split()
N = list(N)
N[int(K)] = N[int(K)].lower()
print(str(N))

Buggy submission (verdict: Runtime Error):
N, K = input().split()
N = list(N)
N[int(K)] = N[int(K)].lower()
print(N)

Buggy submission (verdict: Runtime Error):
N, K = input().split()
N[int(K)] = N[int(K)].lower()
print(N)

Buggy submission (verdict: Runtime Error):
N, K = input().split()
N[K] = N[K].lower()
print(N)
Problem p03242 (python)

Fixed submission:
def henkan(str):
    for s in str:
        print('1' if s == '9' else '9',end='')
    print('')
henkan(input())

Buggy submission (verdict: Runtime Error):
def henkan(str):
    for s in str:
        print('1' if s = '9' else '9',end='')
        print('')
henkan(input())

Buggy submission (verdict: Runtime Error):
def henkan(str)
    for s in str:
        print('1' if s = '9' else '9',end='')
        print('')
henkan(input())
Problem p03315 (python)

Fixed submission:
s = input()
num = 0

for i in range(len(s)):
    num = num + 1 if  s[i] == '+' else num - 1

print(num)

Buggy submission (verdict: Runtime Error):
def prob(n):
    n = str(n)
    sn = 0
    for i in n:
        sn += int(i)
    n = int(n)
    print('Yes') if not n % sn else ('No')

n = input()
prob(n)

Buggy submission (verdict: Runtime Error):
s = input()
num = 0
for _ in range(len(s)):

    if s == '+':
        num += 1
    else:
Problem p03036 (python)

Fixed submission:
r, d, x = map(int, input().split())
for i in range(10):
  x = r * x - d
  print(x)

Buggy submission (verdict: Runtime Error):
r, d, x = map(int, input().strip())
for i in range(10):
  x = r * x - d
  print(x)
Problem p03038 (python)

Fixed submission:
N, M = map(int, input().split())
As = list(map(int, input().split()))
ones = [1 for _ in range(N)]
Bs = []
Cs = []
both = list(zip(As, ones))
for _ in range(M):
  b, c = map(int, input().split())
  both.append((c, b))
both.sort()
a, b = zip(*both)
cnt = 0
out = 0
for k in reversed(range(N+M)):
  if N - cnt > b[k]:
    out += a[k] * b[k]
    cnt += b[k]
  else:
    out += a[k] * (N - cnt)
    break
print(out)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
As = list(map(int, input().split()))
ones = [1 for _ in range(N)]
for _ in range(M):
  b, c = map(int, input().split())
  Bs.append(b)
  Cs.append(c)
both = list(zip(As, ones))
both.append(list(zip(Cs, Bs)))
both.sort()
a, b = zip(*both)
cnt = 0
out = 0
for k in reversed(range(N+M)):
  if N - cnt > b[k]:
    out += a[k] * b[k]
    cnt += b[k]
  else:
    out += a[k] * (N - cnt)
    break
print(out)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = map(int, input().split())
As = list(map(int, input().split()))
As = np.array(As)

B = []
C = []
for _ in range(M):
  Bs, Cs = map(int, input().split())
both = zip(Bs, Cs)
both.sort()
Bs, Cs = zip(*both)
for k in reversed(range(N)):
  As.sort()
  b = Bs[k]
  c = Cs[k]
  cnt = (As < c).sum()
  if cnt == 0:
    break
  else:
    if b > cnt:
      for l in range(cnt):
        As[l] = c
    else:
      for l in range(b):
        As[l] = c
print(As.sum())
Problem p03073 (python)

Fixed submission:
import numpy as np
S = input()
N = len(S)
if N // 2 == 0:
  even = np.array([int(S[2*k]) for k in range(N // 2)])
  odd = np.array([int(S[2*k + 1]) for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 > odd_1:
    print(int(N//2 - even_1 + odd_1))
  else:
    print(int(N//2 + even_1 - odd_1))
else:
  even = np.array([int(S[2*k]) for k in range( (N+1) // 2)])
  odd = np.array([int(S[2*k + 1]) for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 <= odd_1:
    print(int(even_1 + N//2 - odd_1))
  else:
    print(int(odd_1 + (N+1)//2 - even_1))

Buggy submission (verdict: Runtime Error):
import numpy as np
S = input()
N = len(S)
if N // 2 == 0:
  even = np.array([S[2*k] for k in range(N // 2)])
  odd = np.array([S[2*k + 1] for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 > odd_1:
    print(N//2 - even_1 + odd_1)
  else:
    print(N//2 + even_1 - odd_1)
else:
  even = np.array([S[2*k] for k in range( (N+1) // 2)])
  odd = np.array([S[2*k + 1] for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 <= odd_1:
    print(even_1 + N//2 - odd_1)
  else:
    print(odd_1 + (N+1)//2 - even_1)
Problem p03041 (python)

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

s = (input())

if s[k-1] is 'A':
	o = s[:k-1] + 'a' +s[k:] 
elif s[k-1] is 'B':
	o = s[:k-1] + 'b' +s[k:] 
elif s[k-1] is 'C':
	o = s[:k-1] + 'c' +s[k:] 

print(o)

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

s = (input())

if s[k] is 'A':
	o = s[:k] + 'a' +s[k:] 
elif s[k] is 'B':
	o = s[:k] + 'b' +s[k:] 
elif s[k] is 'C':
	o = s[:k] + 'c' +s[k:] 

print(o)

Buggy submission (verdict: Runtime Error):
n, k = map(input().split())
s = (input())

if s[k] is 'A':
	s[k] = 'a'
elif s[k] is 'B':
	s[k] = 'b'
elif s[k] is 'C':
	s[k] = 'c'

print(s)

Buggy submission (verdict: Runtime Error):
n, k = map(input().split())
s = (input())

if s[k] is 'A'
	s[k] = 'a'
elif s[k] is 'B'
	s[k] = 'b'
elif s[k] is 'C'
	s[k] = 'c'

print(s)
Problem p03036 (python)

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

new_x = r * x - d
print(new_x) #2011
for i in range(2002, 2011):
    new_x = r * new_x - d
    print(new_x)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())

if a>=13:
    print(b)
elif a >= 6:
    print(int(b / 2))
else:
    print(0)
Problem p03041 (python)

Fixed submission:
n,k=map(int,input().split())
s=input()
new=s[k-1:k]
news=new.lower()
print(s[:k-1]+news+s[k:])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
new=s[k]
news=new.lower()
print(s[:k-1]+news+s[k:])

Buggy submission (verdict: Runtime Error):
n,k=int(input().split())
s=input()
print(s[:k-1]+s.replace(s[k-1], s[k-1].lower())+s[k:])

Buggy submission (verdict: Runtime Error):
n,k=int(input().split())
s=input()
print('s[:k-1]'+'s.replace(s[k-1], s[k-1].lower())'+'s[k:]')

Buggy submission (verdict: Runtime Error):
n,k=int(input().split())
s=input()
s[k-1]=s[k-1].lower()
print(s)
Problem p03242 (python)

Fixed submission:
for i in input():
    print(9 if i == '1' else 1, end='')

Buggy submission (verdict: Runtime Error):
n=input()
for i in range(2)
if n[i]=1:
  n[i]=9
else:
  n[i]=1
print(n)
Problem p03041 (python)

Fixed submission:
N,K = map(int, input().strip().split())
S = input().strip()

for ix, c in enumerate(S):
    if K == (ix + 1):
        print(c.lower(), end='')
    else:
        print(c, end='')

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
x = [[] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1].append([v-1, w])
     x[v-1].append([u-1,w])



ret = {}
done = []

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for neigh in x[curr]:
        if neigh in done:
            continue
        if neigh[1] % 2 == 0:
            ret[neigh[0]] = ret[curr]
        else:
            ret[neigh[0]] = 0 if ret[curr] == 1 else 1

        queue.append(neigh[0])
    done.append(curr)


for i in range(N):
    print(ret[i])
Problem p03072 (python)

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

count = 0

for num, hight in enumerate(h):
  if hight >= max(h[:num+1]):
    count += 1

print(count)

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

count = 0

for num, hight in enumerate(h):
  if h[num] >= max(h[:num]):
    count += 1

print(count)
Problem p03617 (python)

Fixed submission:
Q, H, S, D = input().split()
Q, H, S, D = int(Q), int(H), int(S), int(D)
N = int(input())

needtobuy_l = N
needtobuy_m = 0
per_2l_price = [D,
                S*2, S+H*2, S+H+Q*2,
                H*4, H*3+Q*2, H*2+Q*4, H+Q*6,
                Q*8]
per_1l_price = [S,
                H*2, H+Q*2,
                Q*4]

if needtobuy_l % 2 == 0:
    mincost = min(per_2l_price)
    needtobuy_m = mincost * (needtobuy_l // 2)
else:
    mincost = min(per_2l_price)
    needtobuy_m = mincost * (needtobuy_l // 2)
    mincost = min(per_1l_price)
    needtobuy_m += mincost * 1

print(needtobuy_m)

Buggy submission (verdict: Runtime Error):
Q, H, S, D = input().split()
Q, H, S, D = int(Q), int(H), int(S), int(D) # price 0.25 0.5 1.0 2.0
N = int(input())

per_2l_price = [Q*8, H*4, S*2, D]
per_1l_price = [Q*4, H*2, S]
per_05_price = [Q*2, H]
per_025_price = [Q]
needtobuy_l = N
needtobuy_m = 0


def st_min(lt):
    min_num = 0
    min_ = 1000000000000000000000000
    for i in range(len(lt)):
        if lt[i] < min_:
            min_num = i
            min_ = lt[i]
    return min_num
st_min


if needtobuy_l >= 2.0:
    mn = st_min(per_2l_price)
    needtobuy_m += per_2l_price[mn] * (needtobuy_l // 2.0)
    needtobuy_l -= 2.0 * (needtobuy_l // 2.0)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 1.0:
    mn = st_min(per_1l_price)
    needtobuy_m += per_1l_price[mn] * (needtobuy_l // 1.0)
    needtobuy_l -= 1.0 * (needtobuy_l // 1.0)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 0.5:
    mn = st_min(per_05_price)
    needtobuy_m += per_05_price[mn] * (needtobuy_l // 0.5)
    needtobuy_l -= 0.5 * (needtobuy_l // 0.5)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 0.25:
    needtobuy_m += Q * (needtobuy_l // 0.25)
    needtobuy_l -= 0.25 * (needtobuy_l // 0.25)

print(int(needtobuy_m))
Problem p03201 (python)

Fixed submission:
import math
from collections import defaultdict
N = int(input())
A = sorted(int(i) for i in input().split())

d = defaultdict(lambda: 0)
for i in A:
    d[i] += 1

c = 0
for k in sorted(d.keys(), reverse=True):
    l = 2**int(math.log(k, 2) + 1) - k
    v = d[k]
    if k == l:
        c += v // 2
    elif l in d:
        w = d[l]
        if v > w:
            c += w
            d[l] = 0
        else:
            c += v
            d[l] = w-v
print(c)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = sorted((int(i) for i in input().split()), reverse=True)

k = 2**int(math.log(A[0], 2) + 1)

def f(A, k):
    if len(A) == 1:
        return 0

    v = A[0]

    while k >= 2*v:
        k //= 2
    w = k - v

    if w in A[1:]:
        print(k, "=", v, "+", w)
        A.remove(w)
        r = 1
    else:
        r = 0

    return r + f(A[1:], k)
print(f(A, k))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
A = [int(i) for i in input().split()]

A.sort(reverse=True)
B = [2**int(math.log(i, 2)+1) - i for i in A]

c = 0
for i, v in enumerate(B[:-1]):
    print(i, v, A[i+1:])
    if v in A[i+1:]:
        c += 1
        A.remove(v)
print(c)
Problem p03038 (python)

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

d = []

bc = []
for i in range(m):
    b,c = map(int,input().split())
    bc.append([b,c])

bc = sorted(bc,key=lambda x:x[1],reverse=True)

for elm in bc:
    for i in range(elm[0]):
        d.append(elm[1])
        if len(d) >= n:
            break
    if len(d) >= n:
        break

d.sort()
d.reverse()

#print(a)
#print(d)

sum = 0
ln = len(d)
for i in range(n):
    if i < ln:
        if a[i] < d[i]:
            sum += d[i]
        else:
            sum += a[i]
    else:
        sum += a[i]

print(sum)

Buggy submission (verdict: Runtime Error):
from bisect import insort_left

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

d = []

for i in range(m):
    b,c = map(int,input().split())
    
    for j in range(b):
        d.append(c)        

d.sort()
d.reverse()

#print(a)
#print(d)

for i in range(n):
    if a[i] < d[i]:
        a[i] = d[i]
    else:
        break

#print(a)

sum = 0
for v in a:
    sum += v

print(sum)

Buggy submission (verdict: Runtime Error):
from bisect import insort_left

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

for i in range(m):
    b,c = map(int,input().split())

    for j in range(b+1):        
        if a[j] < c:
            a.remove(a[j])
            insort_left(a,c)
sum = 0
for v in a:
    sum += v

print(sum)

Buggy submission (verdict: Runtime Error):
from bisect import insort

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

for i in range(m):
    b,c = map(int,input().split())

    for j in range(b+1):        
        if a[j] < c:
            a.remove(a[j])
            insort(a,c)

sum = 0
for v in a:
    sum += v

print(sum)

Buggy submission (verdict: Runtime Error):
from bisect import insort

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

#print(a)
for i in range(m):
    a.sort()
    b,c = map(int,input().split())

    for j in range(b+1):        
        if a[j] < c:
            a.remove(a[j])
            insort(a,c)

sum = 0
for v in a:
    sum += v

print(sum)
Problem p03209 (python)

Fixed submission:
a = []
p = []

def dfs (x,i,depth):

    if i <= 1:
        #print(x)
        if x == 0:
            return 0
        elif x == 1:
            return 1
        elif x == 2:
            return 2
        elif x >= 3:
            return 3
    else:
        #print(a[i],a[i]//2,x)
        if a[i]//2 < x  :
            x = x - a[i]//2 - 1
            #print("right>>>",p[i-1] + 1,x)
            return (p[i-1] + 1) + dfs(x,i-1,depth)
        elif a[i]//2 == x :
            #print("<<<mid>>>",1,x)
            return (1 + dfs(x-1,i-1,depth))
        else:
            #print("left<<<",0,x)
            if x - 1 <= 0:
                return 0
            else:
                return dfs(x-1,i-1,depth)

def ddff (i,depth):
    if i >= depth-1:
        return 'bpppb'
    else:
        return 'b' + ddff(i+1,depth) + 'p' + ddff(i+1,depth) + 'b'
 
n,x = map(int,input().split())

for i in range(n+1):
    p.append(2**(i+1)-1)
    b = 2**(i+1)-2
    a.append(p[i] + b)
#print(a,p)

r = dfs(x-1,n,n)
print(r)

Buggy submission (verdict: Runtime Error):
def dfs (i,depth):
    if i >= depth-1:
        return 'bpppb'
    else:
        s = dfs(i+1,depth)
        return 'b' + s + 'p' + s + 'b'
n,x = map(int,input().split())
r = dfs(0,n)
print(r.count('p',0,x))

Buggy submission (verdict: Runtime Error):
ef dfs (i,depth):

    if i >= depth-1:
        return 'bpppb'
    else:
        s = dfs(i+1,depth)
        return 'b' + s + 'p' + s + 'b'

n,x = map(int,input().split())

p = 2**(n+1)-1
b = 2**(n+1)-2
a = p + b
#print(p,a,b)
pos = a / x
#print(pos)
#print(p / pos)

r = dfs(0,n)
print(r.count('p',0,x))
Problem p03221 (python)

Fixed submission:
import sys as sys

lines =  input().split()
n = int(lines[0])
m = int(lines[1])

py = []
od = {}

#lines = sys.stdin.readlines()

for i in range(0,m):


    #l =  lines[i].split()
    l = input().split()
    p = int(l[0])
    y = int(l[1])
    
    if p in od :
        od[p].append([i,y])
    else:
        od[p] = [[i,y]]

a = []
for p in od.keys():
    od[p].sort(key=lambda x:x[1])
    r = 1

    for o in od[p]:
        cs = ""

        tmp = p
        digit = 0
        while tmp > 0 :        
            digit += 1
            tmp = tmp // 10
        
        l = 6-digit
        for j in range(l):
            cs += '0'
        cs += str(p)

        tmp = r 
        digit = 0
        while tmp > 0 :        
            digit += 1
            tmp = tmp // 10

        l = 6-digit
        for j in range(l):
            cs += '0'
        cs += str(r)        

        a.append([o[0],cs])
        r += 1

a.sort(key=lambda x:x[0])
for aa in a:
    print(aa[1])

Buggy submission (verdict: Runtime Error):
import time as time

lines =  input().split()
n = int(lines[0])
m = int(lines[1])
#n,m = map(int,input().split())

py = []
od = [[]*1 for i in range(n)]

#print ("create list: " + str(time.time() - s) )

s = time.time()
for i in range(0,m):

    lines =  input().split()
    p = int(lines[0])
    y = int(lines[1])
    py.append([p,y])
       
    odlen = len(od[p-1])
    od[p-1].append(y)
    od[p-1].sort()
    """ if odlen >= 1 :

        low = 0
        high = odlen - 1
        mid = odlen >> 1

        while low <= high:
            mid = (low + high) >> 1
            guess = od[p-1][mid]
            if guess == y:
                break
            if guess > y :
                high = mid - 1
            else:
                low  = mid + 1
        od[p-1].insert(low,y)

    else:
        od[p-1].append(y) """

#print ("sort: " + str(time.time() - s) )
#exit(0)

s = time.time()
for i in range(0,m):
    py0 = py[i][0]
    
    low = 0
    high = odlen - 1
    mid = odlen >> 1
    while low <= high:
        mid = (low + high) >> 1
        guess = od[py0-1][mid]
        if guess == py[i][1]:
           break
        if guess > py[i][1]:
           high = mid - 1
        else:
           low  = mid + 1
    r = low
    #print(r)
    #r = od[py0-1].index(py[i][1])

    tmp = py0
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = tmp // 10
    
    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(py0,end="")

    tmp = r + 1
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = r // 10

    l = 6-digit
    for j in range(l):
        print('0',end="")
    print(r+1)

#print ("index: " + str(time.time() - s) )