Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

calc_A = [0]
calc_B = [0]

for i in range(N):
    calc_A.append(calc_A[i] + A[i])

for j in range(M):
    calc_B.append(calc_B[j] + B[j])

ans = 0

for i in range(N+1):
    j = M
    if calc_A[i] > K:
        break
    while calc_B[j] > K - calc_A[i]:
        if j > 0:
            j -= 1
        else:
            break
    if ans < i + j:
        ans = i + j

print(ans)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

check_A = [0]
check_B = [0]

for a in range(N):
    check_A.append(check_A[a] + A[a])

for b in range(M):
    check_B.append(check_B[b] + B[b])

ans = 0
j = M

for i in range(N+1):
    if check_A[i] > K:
        break
    while check_B[j] > K - check_A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
check = 0
check_A = [0]
check_B = [0]

for n in range(N):
    check_A.append(check_A[n] + A[n])

for m in range(M):
    check_B.append(check_B[m] + B[m])

for n in range(N+1):
    if check_A[n] > K:
        break
    for m in range(M+1):
        if check_B[m] > K:
            break
        calc = check_A[n] + check_B[m]
        if calc > K:
            break
        if check <= calc:
            check = calc
            ans = n + m

print(ans)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

check_A = [0]
check_B = [0]

for a in range(N):
    check_A.append(check_A[a] + A[a])

for b in range(M):
    check_B.append(check_B[b] + B[b])

ans = 0
j = M

for i in range(N+1):
    if check_A[i] > K:
        break
    while check_B[j] > K - check_A[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)
Buggy python submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if (A < 0 and B < 0) or (A > 0 and B > 0):
    D = max(A, B) - min(A, B)
elif (A > 0 and B < 0) or (A < 0 and B > 0):
    D = max(A, B) + abs(min(A, B))

check = D + (W * T) - (V * T)

if check > 0:
    print('NO')
else:
    print('YES')

Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if abs(A - B) <= (V - W) * T:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

V *= T
W *= T

if (A < 0 and B < 0) or (A > 0 and B > 0):
    D = max(A, B) - min(A, B)
elif (A > 0 and B < 0) or (A < 0 and B > 0):
    D = max(A, B) + abs(min(A, B))

check = D + W - V

if check > 0:
    print('NO')
else:
    print('YES')

Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if abs(A - B) <= (V - W) * T:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1

for i in range(N):
    num = A[i]
    ans *= num

if ans > 10**18:
    ans = -1

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 1
check = 10 ** 18

for i in range(N):
    num = A[i]
    ans *= num
    if ans > check:
        ans = -1
        break
    elif ans == 0:
        break

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

for s in S:
    if s == 'h':
        Flag = True
    elif s == 'i' and Flag == True:
        Flag = False
    else:
        Flag = False
        print('No')
        exit()

print('Yes')

Fixed submission:
S = input().replace('hi', '*')

for s in S:
    if s != '*':
        print('No')
        exit()

print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 10**9 + 10

for i in range(A):
    for j in range(B):
        num = a[i] + b[j]
        if num < ans:
            ans = num

for m in range(M):
    x, y, c = list(map(int, input().split()))
    calc = a[x-1] + b[y-1] - c
    if calc < ans:
        ans = calc

print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 10**9 + 10

num = min(a) + min(b)
if num < ans:
    ans = num

for m in range(M):
    x, y, c = list(map(int, input().split()))
    calc = a[x-1] + b[y-1] - c
    if calc < ans:
        ans = calc

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ans = ['-1'] * N

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == str(c):
        continue
    elif ans[s-1] == '-1':
        ans[s-1] = str(c)
    else:
        ans = -1
        print(ans)
        exit()

for i in range(N):
    if ans[i] == '-1':
        ans[i] = str(0)

if N == 3 and ans[0] == '0' or ans[1] == '0':
    ans = -1
    print(ans)
    exit()
elif N == 2 and ans[0] == '0':
    ans = -1
    print(ans)
    exit()
else:
    print(''.join(ans))

Fixed submission:
N, M = map(int, input().split())
ans = ['-1'] * N

if N == 1 and M == 0:
    ans = 0
    print(ans)
    exit()

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == str(c):
        continue
    elif ans[s-1] == '-1':
        ans[s-1] = str(c)
    else:
        ans = -1
        print(ans)
        exit()

if N >= 2 and ans[0] == '0':
    ans = -1
    print(ans)
    exit()
elif ans[0] == '-1':
    ans[0] = '1'

ans = ''.join(ans).replace('-1', '0')

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(N):
    check = P[:i+1]
    if min(check) == P[i]:
        ans += 1

print(ans)

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

ans = 0
check = 10**9 + 7

for i in range(N):
    if check > P[i]:
        ans += 1
        check = P[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(N):
    check = P[:i+1]
    if min(check) == check[-1]:
        ans += 1

print(ans)

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

ans = 0
check = 10**9 + 7

for i in range(N):
    if check > P[i]:
        ans += 1
        check = P[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

ans = N

for i in range(N):
    for j in range(i):
        if P[i] > P[j]:
            ans -= 1
            break

print(ans)

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

ans = 0
check = 10**9 + 7

for i in range(N):
    if check > P[i]:
        ans += 1
        check = P[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
ans = 0

for i in range(1, N+1):
    cnt = 0
    for j in range(N):
        if j <= i-1 and P[i-1] <= P[j]:
            cnt += 1
            if cnt == i:
                ans += 1
        else:
            break

print(ans)

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

ans = 0
check = 10**9 + 7

for i in range(N):
    if check > P[i]:
        ans += 1
        check = P[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        l = L[j+1:]
        ans += sum(c < (a+b) for c in l)

print(ans)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

from bisect import bisect_left
for i in range(N):
    for j in range(i+1, N):
        ab = L[i] + L[j]
        index = bisect_left(L, ab)
        num = index - j - 1
        ans += max(0, num)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        l = L[j+1:]
        ans += sum(c < (a+b) for c in l)

print(ans)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

from bisect import bisect_left
for i in range(N):
    for j in range(i+1, N):
        ab = L[i] + L[j]
        index = bisect_left(L, ab)
        num = index - j - 1
        ans += max(0, num)

print(ans)

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

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

seq = list(itertools.combinations(L, 3))
num = len(seq)

for i in range(num):
    a = seq[i][0]
    b = seq[i][1]
    c = seq[i][2]
    if (a < b + c) and (b < a + c) and (c < a + b):
        ans += 1

print(ans)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

from bisect import bisect_left
for i in range(N):
    for j in range(i+1, N):
        ab = L[i] + L[j]
        index = bisect_left(L, ab)
        num = index - j - 1
        ans += max(0, num)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            a = L[i]
            b = L[j]
            c = L[k]
            if (a < b + c) and (b < a + c) and (c < a + b):
                ans += 1
            else:
                break

print(ans)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

from bisect import bisect_left
for i in range(N):
    for j in range(i+1, N):
        ab = L[i] + L[j]
        index = bisect_left(L, ab)
        num = index - j - 1
        ans += max(0, num)

print(ans)
Buggy python submission (verdict: Runtime Error):
# ユークリッドの互除法
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

# 約数の列挙
def make_divisions(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

A, B = map(int, input().split())
num = gcd(A, B)

arr = make_divisions(num)
arr.sort()

ans = [arr[0]]
for i in range(1, len(arr)):
    if gcd(ans[i-1], arr[i]) == 1:
        ans.append(arr[i])

print(len(ans))

Fixed submission:
def prime_factorize(n):
    pf = []
    while n % 2 == 0:
        pf.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            pf.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        pf.append(n)
    return pf

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

prime_A = set(prime_factorize(A))
prime_B = set(prime_factorize(B))
ans = len(prime_A & prime_B) + 1

print(ans)

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

def cf(a, b):
    cf = [1]
    for i in range(2, min(a, b)+1):
        if a % i == 0 and b % i == 0:
            if (i == 2) or (i > 2 and i % 2 != 0):
                if i >= 5 and i % cf[-1] == 0:
                    pass
                else:
                    cf.append(i)
            else:
                pass
    return cf

cf_l = cf(A, B)

print(len(cf_l))

Fixed submission:
def prime_factorize(n):
    pf = []
    while n % 2 == 0:
        pf.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            pf.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        pf.append(n)
    return pf

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

prime_A = set(prime_factorize(A))
prime_B = set(prime_factorize(B))
ans = len(prime_A & prime_B) + 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def cf(a, b):
    cf = [1]
    for i in range(2, min(a, b)+1):
        if a % i == 0 and b % i == 0:
            if (i == 2) or (i > 2 and i % 2 != 0):
                cf.append(i)
            else:
                pass
    return cf

A, B = map(int, input().split())
cf_l = cf(A, B)

for i in range(1, len(cf_l)):
    for j in range(i+1, len(cf_l)):
        if cf_l[j] % cf_l[i] == 0:
            cf_l.pop(j)

print(len(cf_l))


Fixed submission:
def prime_factorize(n):
    pf = []
    while n % 2 == 0:
        pf.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            pf.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        pf.append(n)
    return pf

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

prime_A = set(prime_factorize(A))
prime_B = set(prime_factorize(B))
ans = len(prime_A & prime_B) + 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split())) + [10**9 + 10]
check = 0
ans = [0]

for i in range(1, N + 1):
    if H[i - 1] >= H[i]:
        check += 1
    else:
        if min(ans) < check:
            ans.append(check)
            check = 0

print(max(ans))

Fixed submission:
N = int(input())
H = list(map(int, input().split())) + [10**9 + 10]
check = 0
ans = [0]

for i in range(1, N + 1):
    if H[i - 1] >= H[i]:
        check += 1
    else:
        if min(ans) < check:
            ans.append(check)
            check = 0

print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
array = [i for i in range(1, N+1)]
num = 0

for i in range(N-1):
    num += i + 1

print(num)

Fixed submission:
N = int(input())
print(N * (N-1) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
array = [i for i in range(1, N+1)]
num = 0

for i in range(1, N):
    num += array[i-1] % array[i]

print(num)

Fixed submission:
N = int(input())
print(N * (N-1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)] + [0]
ans = [max(a[1:])]

for i in range(1, n):
    if a[i] in a[:i] or a[i] in a[i+1:]:
        ans.append(ans[i-1])
    else:
        max_l = max(a[:i])
        max_r = max(a[i+1:])
        ans.append(max(max_l, max_r))

print(*ans, sep='\n')

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)] + [0]

sorted_a = sorted(a)
a_first = sorted_a[-1]
a_second = sorted_a[-2]

for i in range(n):
    if a[i] == a_first:
        print(a_second)
    else:
        print(a_first)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    l = a[i+1:]
    r = a[:i]
    ans = l + r
    print(max(ans))

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)] + [0]

sorted_a = sorted(a)
a_first = sorted_a[-1]
a_second = sorted_a[-2]

for i in range(n):
    if a[i] == a_first:
        print(a_second)
    else:
        print(a_first)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
mod = 2019
num = (R - L) + 1
ans = 10**9 + 10

for i in range(num):
    for j in range(1+i, num):
        l = L + i
        r = L + j
        if l < r:
            check = (l * r) % mod
            if ans > check:
                ans = check
        else:
            break

print(ans)

Fixed submission:
L, R = map(int, input().split())
mod = 2019
ans = 10 ** 9 * 10

for l in range(L, min(L + mod, R) + 1):
    for r in range(l + 1, min(L + mod, R) + 1):
        ans = min(ans, (l * r) % mod)

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

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b, c, d = map(int, input().split())
cd = lcm(c, d)
num = b - a + 1

if a <= cd <= b:
    cd_count = (b // cd) - (a // cd)
else:
    cd_count = 0

if a % c == 0:
    c_count = (b // c) - (a // c) + 1
else:
    c_count = (b // c) - (a // c)
if a % d == 0:
    d_count = (b // d) - (a // d) + 1
else:
    d_count = (b // d) - (a // d)

ans = num - c_count - d_count + cd_count

print(ans)

Fixed submission:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a, b, c, d = map(int, input().split())
a -= 1
cd = lcm(c, d)

upper = b - b//c - b//d + b//cd
lower = a - a//c - a//d + a//cd
ans = upper - lower

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b, c, d = map(int, input().split())
cd = lcm(c, d)
num = b - a + 1

if a <= cd <= b:
    cd_count = (b // cd) - (a // cd)
else:
    cd_count = 0

if a % c == 0:
    c_count = (b // c) - (a // c) + 1
else:
    c_count = (b // c) - (a // c)
if a % d == 0:
    d_count = (b // d) - (a // d) + 1
else:
    d_count = (b // d) - (a // d)

ans = num - c_count - d_count + cd_count

print(ans)

Fixed submission:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a, b, c, d = map(int, input().split())
a -= 1
cd = lcm(c, d)

upper = b - b//c - b//d + b//cd
lower = a - a//c - a//d + a//cd
ans = upper - lower

print(ans)
Buggy python submission (verdict: Runtime Error):
w, h, x, y = map(int, input().split())
ans = []

ans.append('{:.7f}'.format(w*h/2))

if w % x == 0 and h % y == 0:
    ans.append(1)
else:
    ans.append(0)

print(*ans, sep=' ')

Fixed submission:
w, h, x, y = map(int, input().split())
ans = []

if w == x*2 and h == y*2:
    ans.append('{:.7f}'.format(w*h/2))
    ans.append(1)
else:
    ans.append('{:.7f}'.format(w*h/2))
    ans.append(0)

print(*ans, sep=' ')
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]

is_broken = [1] * (n+1)
for i in range(n):
    if i in a:
        is_broken[i] = 0

step = [i for i in range(n+1)]
step[0] = 1

for i in range(n):
    if i - 1 >= 0:
        step[i+1] = step[i] * is_broken[i] + step[i-1] * is_broken[i-1]
    else:
        step[i+1] = step[i] * is_broken[i]
    step[i+1] %= mod

print(step[n])

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

is_broken = [1] * (n+1)

for i in range(m):
    is_broken[a[i]] = 0

step = [i for i in range(n+1)]
step[0] = 1

for i in range(n):
    if i - 1 >= 0:
        step[i+1] = step[i] * is_broken[i] + step[i-1] * is_broken[i-1]
    else:
        step[i+1] = step[i] * is_broken[i]
    step[i+1] %= mod

print(step[n])
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(int(i) for i in input().split())
i = 1
ans = 1

if h[0] <= max(h[1:]):
    while i in range(n):
        if h[i-1] <= h[i]:
            ans += 1
        i += 1
print(ans)

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

for i in range(1, n):
    if max(h[:i]) <= h[i]:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
l = [a, b, c, d, e]
sur = 0

for i in range(len(l)):
    if sur < l[i] % 10:
        sur = 10 - (l[i] % 10)
        last = i
    if l[i] % 10 != 0:
        l[i] += 10 - (l[i] % 10)

order = l[:last]+l[last+1:]
ans = (sum(order))+l[last]-sur

print(ans)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

now_time = [a, b, c, d, e]
next_time = []

for i in now_time:
    if i % 10 == 0:
        next_time.append(i)
    else:
        while i % 10 != 0:
            i += 1
        next_time.append(i)

combined = sorted([x - y for (x, y) in zip(next_time, now_time)])

best_time = sum(next_time) - max(combined)
print(best_time)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
    left = lr[i][0] - 1
    right = lr[i][1]
    count = s[left:right].count('AC')
    print(count)

Fixed submission:
n, q = map(int, input().split())
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(int, input().split())
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
def chmin(a, b):
    if a > b:
        a = b
    return a

n, k = map(int, input().split())
h = list(map(int, input().split()))

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

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

print(dp[-1])

Fixed submission:
def chmin(a, b):
    if a > b:
        a = b
    return a

n, k = map(int, input().split())
h = list(map(int, input().split()))

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

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

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
N = len(S)
ans = 0
num = S.count('B')
check = ['W']*(N-num) + ['B']*num

while S != check:
    for i in range(1, N):
        if S[i-1] == 'B' and S[i] == 'W':
            S[i-1], S[i] = 'W', 'B'
            ans += 1

print(ans)

Fixed submission:
S = input()
N = len(S)
ans = 0

cnt_B = S.count('B')
idx_B = N - cnt_B

for i in range(N):
    if S[i] == 'B':
        ans += idx_B - i
        idx_B += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
py = [[i] + list(map(int, input().split())) for i in range(m)]
py.sort(key=lambda x:(x[1], x[2]))

city = py[1][2]
num = 0

for i in py:
    if i[1] == city:
        num += 1
    else:
        num = 1
        city = i[1]
    i.append(num)

py.sort()

for i in py:
    print('{:06}{:06}'.format(i[1], i[3]))

Fixed submission:
n, m = map(int, input().split())
py = [[i] + list(map(int, input().split())) for i in range(m)]
py.sort(key=lambda x:(x[1],x[2]))

city = py[0][1]
num = 0

for i in py:
    if i[1] == city:
        num += 1
    else:
        city = i[1]
        num = 1
    i.append(num)

py.sort()

for i in py:
    print('{:06}{:06}'.format(i[1], i[3]))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
py = sorted([[i] + list(map(int, input().split())) for i in range(m)], key=lambda x:(x[1], x[2]))

city = py[1][2]
num = 0

for i in py:
    if i[1] == city:
        num += 1
    else:
        num = 1
        city = i[1]
    i.append(num)

py.sort()

for i in py:
    print('{:06}{:06}'.format(i[1], i[3]))

Fixed submission:
n, m = map(int, input().split())
py = [[i] + list(map(int, input().split())) for i in range(m)]
py.sort(key=lambda x:(x[1],x[2]))

city = py[0][1]
num = 0

for i in py:
    if i[1] == city:
        num += 1
    else:
        city = i[1]
        num = 1
    i.append(num)

py.sort()

for i in py:
    print('{:06}{:06}'.format(i[1], i[3]))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

def lcm(a, b):
    return (a*b) // gcd(a, b)

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

L = lcm(N, M)
X = [S[0]] * L
step_N = L // N
step_M = L // M

if S[0] != T[0]:
    ans = -1
elif step_N == 1 or step_M == 1:
    ans = -1
else:
    for i in range(1, N):
        X[i * step_N] = S[i]

    for i in range(1, M):
        X[i * step_M] = T[i]

    check_N = ''.join(X[::step_N])
    check_M = ''.join(X[::step_M])

    if check_N == S and check_M == T:
        ans = L
    else:
        ans = -1

print(ans)

Fixed submission:
from fractions import gcd

def lcm(a, b):
    return (a*b) // gcd(a, b)

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

n = N // gcd(N, M)
m = M // gcd(N, M)
k = gcd(N, M)

for i in range(k):
    if S[i * n] != T[i * m]:
        print(-1)
        exit()

print(lcm(N, M))
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
ans = 1

for i in range(1, n):
    if max(h[:i]) <= h[i]:
        ans += 1

print(ans)

Fixed submission:
n, t = map(int, input().split())
ct = []
for i in range(n):
    ct.append(list(map(int, input().split())))
num = 1001
has_tle = False

for i in range(n):
    if t >= ct[i][1]:
        if num >= ct[i][0]:
            num = ct[i][0]
        has_tle = True

if has_tle == True:
    print(num)
else:
    print('TLE')