Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N = int(input())
que = []
tmp = []
A1 = int(input())
heapq.heappush(que, A1*-1)
for _ in range(N-1):
    a = int(input())
    while True:
        if len(que) == 0:
            heapq.heappush(que, a*-1)
            break
        A = heapq.heappop(que)*-1
        if A < a:
            heapq.heappush(que, a*-1)
            break
        else:
            tmp.append(A)

    for val in tmp:
        heapq.heappush(que, val*-1)
    tmp = []

print(len(que))

Fixed submission:
import bisect

N = int(input())
A = [-1]*N

for _ in range(N):
    val = int(input())
    n = bisect.bisect_left(A, val)
    A[n-1] = val

print(N-A.count(-1))
Buggy python submission (verdict: Runtime Error):
import sys

N,M = map(int, input().split())

A = int(input())
n = 1

dp = [0]*(N+1)
if N == 1:
    if 1 == A:
        print('0')
        sys.exit()
    else:
        print('1')
        sys.exit()
if 1 == A:
    dp[1] = 0
    if M != n:
        A = int(input())
        n += 1
else:
    dp[1] = 1
dp[0] = 1
for i in range(2, N+1):
    if i == A:
        dp[i] = 0
        if M != n:
            A = int(input())
            n += 1
    else:
        dp[i] = dp[i-1]%1000000007 + dp[i-2]%1000000007

print(dp[N]%1000000007)

Fixed submission:
import sys

N,M = map(int, input().split())

dp = [-1]*(N+1)
dp[0] = 1
dp[1] = 1
for i in range(M):
    num = int(input())
    dp[num] = 0

for i in range(2, N+1):
    if dp[i] == 0:
        continue
    dp[i] = dp[i-1]%1000000007 + dp[i-2]%1000000007

print(dp[N]%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N,M = map(int, input().split())
A = [0]*M
for i in range(M):
    A[i] = int(input())

dp = [0]*(N+1)
if N == 1:
    if 1 in A:
        print('0')
        sys.exit()
    else:
        print('1')
        sys.exit()

if 1 in A:
    dp[1] = 0
else:
    dp[1] = 1
dp[0] = 1
for i in range(2, N+1):
    if i in A:
        dp[i] = 0
    else:
        dp[i] = dp[i-1]%1000000007 + dp[i-2]%1000000007

print(dp[N]%1000000007)

Fixed submission:
import sys

N,M = map(int, input().split())

dp = [-1]*(N+1)
dp[0] = 1
dp[1] = 1
for i in range(M):
    num = int(input())
    dp[num] = 0

for i in range(2, N+1):
    if dp[i] == 0:
        continue
    dp[i] = dp[i-1]%1000000007 + dp[i-2]%1000000007

print(dp[N]%1000000007)
Buggy python submission (verdict: Runtime Error):
import copy

N,M = map(int, input().split())
jisho = [[] for i in range(N)]
for i in range(M):
    val = input().split()
    for j in val[1:]:
        jisho[int(j)-1].append(i)

p = list(map(int, input().split()))

sw = []
def create_ki(data):
    if len(data) == N:
        sw.append(data)
        return
    tmp = copy.copy(data)
    tmp.append(0)
    create_ki(tmp)
    tmp2 = copy.copy(data)
    tmp2.append(1)
    create_ki(tmp2)

create_ki([])

ans = 0
for val in sw:
    num = 0
    sw2 = [0]*M
    for i in val:
        if i == 0:
            num += 1
            continue
        data = jisho[num]
        for j in data:
            sw2[j] += 1
        num += 1
    cn = 0
    for j in sw2:
        if j % 2 == p[cn]:
            break
        cn += 1
    if cn == M:
        ans += 1

print(ans)
mac:128 ry

Fixed submission:
import copy

N,M = map(int, input().split())
jisho = [[] for i in range(N)]
for i in range(M):
    val = input().split()
    for j in val[1:]:
        jisho[int(j)-1].append(i)

p = list(map(int, input().split()))

sw = []
def create_ki(data):
    if len(data) == N:
        sw.append(data)
        return
    tmp = copy.copy(data)
    tmp.append(0)
    create_ki(tmp)
    tmp2 = copy.copy(data)
    tmp2.append(1)
    create_ki(tmp2)

create_ki([])

ans = 0
for val in sw:
    num = 0
    sw2 = [0]*M
    for i in val:
        if i == 0:
            num += 1
            continue
        data = jisho[num]
        for j in data:
            sw2[j] += 1
        num += 1
    cn = 0
    for j in sw2:
        if j % 2 != p[cn]:
            break
        cn += 1
    if cn == M:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for i in range(K+1):
    left = []
    if i != 0:
        left = V[:i]
    for j in range(K-i+1):
        right = []
        if j == 0:
            sort_merge = sorted(left+right)
            ans = max(ans, sum(sort_merge[k:]))
            continue
        elif (N-i) == 0:
            sort_merge = sorted(left+right)
            ans = max(ans, sum(sort_merge[k:]))
            continue
        elif i+j > N:
            right = V[-(N-i):]
        else:
            right = V[-j:]
        for k in range(K-i-j+1):
            if k > i+j:
                continue
            sort_merge = sorted(left+right)
            ans = max(ans, sum(sort_merge[k:]))

print(ans)

Fixed submission:
N,K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for i in range(K+1):
    left = []
    if i != 0:
        left = V[:i]
    for j in range(K-i+1):
        right = []
        if j == 0:
            right = []
        elif (N-i) == 0:
            right = []
        elif i+j > N:
            continue
        else:
            right = V[-j:]
        for k in range(K-i-j+1):
            if k > i+j:
                continue
            sort_merge = sorted(left+right)
            if sum(sort_merge[k:]) == 990000000:
                print(sort_merge)
            ans = max(ans, sum(sort_merge[k:]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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())
    insert_index = bisect.bisect_left(A,C)
    if insert_index == 0 and C > A[0]:
        A[0] = C
        continue
    elif insert_index == 0:
        continue

    if insert_index >= B:
        tmp = A[B:insert_index]+[C]*B+A[insert_index:]
    else:
        tmp = [C]*insert_index+A[insert_index:]
    A = tmp

print(sum(A))

Fixed submission:
N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

BC = []

for i in range(M):
    BC.append(list(map(int, input().split())))

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

bc = 0
a = 0
ans = 0
for i in range(N):
    if (bc < M) and (BC[bc][1] >= A[a]):
        ans += BC[bc][1]
        BC[bc][0] -= 1
        if BC[bc][0] == 0:
            bc += 1
    else:
        ans += A[a]
        a += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

tree = {}
for i in range(1,N):
    u, v, w = map(int, input().split())
    w = w%2
    if u in tree:
        tree[u].append([v,w])
    else:
        tree[u] = [[v,w]]

    if v in tree:
        tree[v].append([u,w])
    else:
        tree[v] = [[u,w]]

iro = [-1]*(N)
def seachTree(current, parent):
    if len(tree[current]) == 0:
        return

    for elms in tree[current]:
        if elms[0] == parent:
            continue
        if elms[1] == 0:
            iro[elms[0]-1] = iro[current-1]
        else:
            iro[elms[0]-1] = not iro[current-1]

        seachTree(elms[0], current)

iro[0] = False
seachTree(1, 0)
for val in iro:
    print(int(val))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N = int(input())

tree = {}
for i in range(1,N):
    u, v, w = map(int, input().split())
    w = w%2
    if u in tree:
        tree[u].append([v,w])
    else:
        tree[u] = [[v,w]]

    if v in tree:
        tree[v].append([u,w])
    else:
        tree[v] = [[u,w]]

iro = [-1]*(N)
def seachTree(current, parent):
    if len(tree[current]) == 0:
        return

    for elms in tree[current]:
        if elms[0] == parent:
            continue
        if elms[1] == 0:
            iro[elms[0]-1] = iro[current-1]
        else:
            iro[elms[0]-1] = not iro[current-1]

        seachTree(elms[0], current)

iro[0] = False
seachTree(1, 0)
for val in iro:
    print(int(val))

Buggy python submission (verdict: Runtime Error):
N = int(input())

tree = {}
for i in range(1,N):
    u, v, w = map(int, input().split())
    w = w%2
    if u in tree:
        tree[u].append([v,w])
    else:
        tree[u] = [[v,w]]

    if v in tree:
        tree[v].append([u,w])
    else:
        tree[v] = [[u,w]]

iro = [-1]*(N)
def seachTree(current, parent):
    if len(tree[current]) == 0:
        return

    for elms in tree[current]:
        if elms[0] == parent:
            continue
        if elms[1] == 0:
            iro[elms[0]-1] = iro[current-1]
        else:
            iro[elms[0]-1] = not iro[current-1]

        seachTree(elms[0], current)

print(tree)
iro[0] = False
seachTree(1, 0)
for val in iro:
    print(int(val))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N = int(input())

tree = {}
for i in range(1,N):
    u, v, w = map(int, input().split())
    w = w%2
    if u in tree:
        tree[u].append([v,w])
    else:
        tree[u] = [[v,w]]

    if v in tree:
        tree[v].append([u,w])
    else:
        tree[v] = [[u,w]]

iro = [-1]*(N)
def seachTree(current, parent):
    if len(tree[current]) == 0:
        return

    for elms in tree[current]:
        if elms[0] == parent:
            continue
        if elms[1] == 0:
            iro[elms[0]-1] = iro[current-1]
        else:
            iro[elms[0]-1] = not iro[current-1]

        seachTree(elms[0], current)

iro[0] = False
seachTree(1, 0)
for val in iro:
    print(int(val))
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

data_list = [A,B,C,D,E]
last_tmp = 10
last = 0
for data in data_list:
    data_str = str(data)
    if int(data_str[len(data_str)-1]) != 0:
        if last_tmp >= int(data_str[len(data_str)-1]):
            last = data
            last_tmp = int(data_str[len(data_str)-1])

data_list.remove(last)
ans = last
for data in data_list:
    ans += data
    data_str = str(data)
    if int(data_str[len(data_str)-1]) != 0:
        ans += 10-int(data_str[len(data_str)-1])

print(ans)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

data_list = [A,B,C,D,E]
last_tmp = 10
last = 0
for data in data_list:
    data_str = str(data)
    if int(data_str[len(data_str)-1]) != 0:
        if last_tmp >= int(data_str[len(data_str)-1]):
            last = data
            last_tmp = int(data_str[len(data_str)-1])

if last != 0:
    data_list.remove(last)
ans = last
for data in data_list:
    ans += data
    data_str = str(data)
    if int(data_str[len(data_str)-1]) != 0:
        ans += 10-int(data_str[len(data_str)-1])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

X,Y,Z,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

que = []
heapq.heappush(que, [(A[0]+B[0]+C[0])*-1,0,0,0])
data = [[0,0,0]]
for i in range(K):
    tmp = heapq.heappop(que)
    print(tmp[0]*-1)
    if tmp[1]+1 < len(A) and [(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]] not in data:
        heapq.heappush(que, [(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]])
        data.append([(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]])
    if tmp[2]+1 < len(B) and [(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]] not in data:
        heapq.heappush(que, [(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]])
        data.append([(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]])
    if tmp[3]+1 < len(C) and [(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1] not in data:
        heapq.heappush(que, [(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1])
        data.append([(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1])

Fixed submission:
import heapq

X,Y,Z,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

que = []
heapq.heappush(que, [(A[0]+B[0]+C[0])*-1,0,0,0])
data = [[0,0,0]]
for i in range(K):
    tmp = heapq.heappop(que)
    print(tmp[0]*-1)
    if tmp[1]+1 < len(A) and [(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]] not in data:
        heapq.heappush(que, [(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]])
        data.append([(A[tmp[1]+1]+B[tmp[2]]+C[tmp[3]])*-1,tmp[1]+1,tmp[2],tmp[3]])
    if tmp[2]+1 < len(B) and [(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]] not in data:
        heapq.heappush(que, [(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]])
        data.append([(A[tmp[1]]+B[tmp[2]+1]+C[tmp[3]])*-1,tmp[1],tmp[2]+1,tmp[3]])
    if tmp[3]+1 < len(C) and [(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1] not in data:
        heapq.heappush(que, [(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1])
        data.append([(A[tmp[1]]+B[tmp[2]]+C[tmp[3]+1])*-1,tmp[1],tmp[2],tmp[3]+1])
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
S = str(input())

before = ''
i = 0
num = 0
data_list = {}
for s in S:
    if before == 'A' and s == 'C':
        num += 1
    before = s
    data_list[i] = num
    i += 1

ans = ''
for q in range(Q):
    r,l = map(int, input().split())
    ans += str(data_list[l-1]-data_list[r-1])+'\n'

print(ans.rstrip())

Fixed submission:
N,Q = map(int, input().split())
S = str(input())

before = ''
i = 0
num = 0
data_list = {}
for s in S:
    if before == 'A' and s == 'C':
        num += 1
    before = s
    data_list[i] = num
    i += 1

ans = ''
for q in range(Q):
    r,l = map(int, input().split())
    ans += str(data_list[l-1]-data_list[r-1])+'\n'

print(ans.rstrip())

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
S = str(input())

before = ''
i = 0
num = 0
data_list = [0]*N
for s in S:
    if before == 'A' and s == 'C':
        num += 1
    before = s
    data_list[i] = num
    i += 1

ans = ''
for q in range(Q):
    r,l = map(int, input().split())
    ans += str(data_list[l-1]-data_list[r-1])+'\n'

print(ans.rstrip())

Fixed submission:
N,Q = map(int, input().split())
S = str(input())

before = ''
i = 0
num = 0
data_list = {}
for s in S:
    if before == 'A' and s == 'C':
        num += 1
    before = s
    data_list[i] = num
    i += 1

ans = ''
for q in range(Q):
    r,l = map(int, input().split())
    ans += str(data_list[l-1]-data_list[r-1])+'\n'

print(ans.rstrip())

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
S = str(input())

ans = ''
for q in range(Q):
    l,r = map(int, input().split())
    s = S[l-1:r]
    ans += str(len(s.split('AC'))-1)+'\n'

print(ans.rstrip())

Fixed submission:
N,Q = map(int, input().split())
S = str(input())

before = ''
i = 0
num = 0
data_list = {}
for s in S:
    if before == 'A' and s == 'C':
        num += 1
    before = s
    data_list[i] = num
    i += 1

ans = ''
for q in range(Q):
    r,l = map(int, input().split())
    ans += str(data_list[l-1]-data_list[r-1])+'\n'

print(ans.rstrip())

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
S = str(input())

ans = ''
for q in range(Q):
    l,r = map(int, input().split())
    s = S[l-1:r]
    ans += str(len(s.split('AC'))-1)+'\n'

print(ans.rstrip())

Fixed submission:
N,Q = map(int, input().split())
S = str(input())

before = ''
i = 0
num = 0
data_list = {}
for s in S:
    if before == 'A' and s == 'C':
        num += 1
    before = s
    data_list[i] = num
    i += 1

ans = ''
for q in range(Q):
    r,l = map(int, input().split())
    ans += str(data_list[l-1]-data_list[r-1])+'\n'

print(ans.rstrip())
Buggy python submission (verdict: Runtime Error):
N = int(input())

ans = 0.0
for i in range(N):
    x,u = map(str, input().split())
    x = float(x)
    if u == 'JPY':
        ans += x
    else:
        ans += x*(380000)

print(ans)
mac:119 ryonakay$

Fixed submission:
N = int(input())

ans = 0.0
for i in range(N):
    x,u = map(str, input().split())
    x = float(x)
    if u == 'JPY':
        ans += x
    else:
        ans += x*(380000)

print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect

A,B,Q = map(int, input().split())

S = []
for i in range(A):
    S.append(int(input()))

T = []
for i in range(B):
    T.append(int(input()))

ans = []
for i in range(Q):
    x = int(input())
    s = bisect.bisect_left(S, x)
    s = min([s,len(S)-1])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori1 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    s = max([s-1,0])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori2 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    t = bisect.bisect_left(T, x)
    t = min([t,len(T)-1])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([st2-1,0])
    kyori3 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    t = max([t-1,0])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([st2-1,0])
    kyori4 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    ans.append(min([kyori1,kyori2,kyori3,kyori4]))

for i in ans:
    print(i)

Fixed submission:
import bisect

A,B,Q = map(int, input().split())

S = []
for i in range(A):
    S.append(int(input()))

T = []
for i in range(B):
    T.append(int(input()))

ans = []
for i in range(Q):
    x = int(input())
    s = bisect.bisect_left(S, x)
    s = min([s,len(S)-1])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori1 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    s = max([s-1,0])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori2 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    t = bisect.bisect_left(T, x)
    t = min([t,len(T)-1])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([ts1-1,0])
    kyori3 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    t = max([t-1,0])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([ts1-1,0])
    kyori4 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    ans.append(min([kyori1,kyori2,kyori3,kyori4]))

for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
PY = [[0] * 2 for i in range(M)]

for i in range(M):
    p,y = map(int,input().split())
    PY[i][0] = p
    PY[i][1] = y

indices = [*range(len(PY))]
sorted_indices = sorted(indices, key=lambda i: PY[i])
PY.sort()

def calc(x):
    n = len(str(x))
    res = ""
    if n < 6:
        for i in range(6-n):
            res += "0"
    res += str(x)
    return res

before = 0
num = 1
ans = [0]*M
for i in range(M):
    if before != PY[i][0]:
        num = 1
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]
    else:
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]

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

Fixed submission:
N,M = map(int, input().split())
PY = [[0] * 2 for i in range(M)]

for i in range(M):
    p,y = map(int,input().split())
    PY[i][0] = p
    PY[i][1] = y

indices = list(range(M))
sorted_indices = sorted(indices, key=lambda i: PY[i])
PY.sort()

def calc(x):
    n = len(str(x))
    res = ""
    if n < 6:
        for i in range(6-n):
            res += "0"
    res += str(x)
    return res

before = 0
num = 1
ans = [0]*M
for i in range(M):
    if before != PY[i][0]:
        num = 1
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]
    else:
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]

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

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
PY = [[0] * 2 for i in range(M)]

for i in range(M):
    p,y = map(int,input().split())
    PY[i][0] = p
    PY[i][1] = y

indices = [*range(len(PY))]
sorted_indices = sorted(indices, key=lambda i: PY[i])
PY.sort()

def calc(x):
    n = len(str(x))
    res = ""
    if n < 6:
        for i in range(6-n):
            res += "0"
    res += str(x)
    return res

before = 0
num = 1
ans = [0]*M
for i in range(M):
    if before != PY[i][0]:
        num = 1
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]
    else:
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]

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

Fixed submission:
N,M = map(int, input().split())
PY = [[0] * 2 for i in range(M)]

for i in range(M):
    p,y = map(int,input().split())
    PY[i][0] = p
    PY[i][1] = y

indices = list(range(M))
sorted_indices = sorted(indices, key=lambda i: PY[i])
PY.sort()

def calc(x):
    n = len(str(x))
    res = ""
    if n < 6:
        for i in range(6-n):
            res += "0"
    res += str(x)
    return res

before = 0
num = 1
ans = [0]*M
for i in range(M):
    if before != PY[i][0]:
        num = 1
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]
    else:
        ans[sorted_indices[i]] = calc(PY[i][0])+calc(num)
        num += 1
        before = PY[i][0]

for i in range(M):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
from math import gcd

N,a = map(int, input().split())
X = list(map(int, input().split()))

S = []
for i in range(N):
    S.append(abs(a-X[i]))

ans = S[0]
for i in range(1, N):
    ans = gcd(ans,S[i])

print(ans)

Fixed submission:
from fractions import gcd

N,a = map(int, input().split())
X = list(map(int, input().split()))

S = []
for i in range(N):
    S.append(abs(a-X[i]))

ans = S[0]
for i in range(1, N):
    ans = gcd(ans,S[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
l=list(map(int,input.split(" ")))
print(l.index("0")+1)

Fixed submission:
l=list(map(int,input().split(" ")))
#print(l)
print(l.index(0)+1)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
n=int(input())
a=list(map(int,input().split()))
ans=gcd(a[0],a[1])
if n>2:
  for i in range(2,n):
    ans=gcd(ans,a[i])
print(ans)

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

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

ans=gcd(a[0],a[1])
if n>2:
  for i in range(2,n):
    ans=gcd(ans,a[i])
print(ans)