Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding: utf8

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


def read_int_n():
    return list(map(int, input().split()))


n, x = read_int_n()
y = read_int_n()
y.append(x)

y.sort()
w = [y[i] - y[i-1] for i in range(1, len(y))]
print(gcd(*w))


Fixed submission:
# coding: utf8

from functools import reduce

def gcda(x, y):
    while y:
        x, y = y, x % y
    return x

def gcd(*numbers):
    return reduce(gcda, numbers)


def read_int_n():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n, x = read_int_n()
    y = read_int_n()
    y.append(x)

    y.sort()
    w = [y[i] - y[i-1] for i in range(1, len(y))]
    print(gcd(*w))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
h_list = [int(elem) for elem in fin().split()]
original_h_list = [x for x in h_list]

flag = True
result = 'Yes'
h_list = [-1] + h_list + [10**10]
for i in range(1, len(h_list)-1):
    # print(h_list[i])
    min_right_h = min(h_list[i+1:])
    if h_list[i] <= min_right_h:
        # 右側最小値以下の場合
        if h_list[i] >= h_list[i-1]:
            # 左側の値以上の場合
            continue
    else:
        # 右側最小値以上の場合
        h_list[i] -= 1
        if min_right_h >= h_list[i] >= h_list[i - 1]:
            continue
        else:
            result = 'No'
            flag = False
    if not flag:
        break

print(result)


Fixed submission:
import sys

fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
h_list = [int(elem) for elem in fin().split()]
original_h_list = [x for x in h_list]

flag = True
result = 'Yes'
h_list = [-1] + h_list + [10**10]
min_h_list = min(h_list[1:-1])
for i in range(1, len(h_list)-1):
    if h_list[i] - 1 >= h_list[i-1]:
        h_list[i] -= 1

for i in range(1, len(h_list)-1):
    if not (h_list[i-1] <= h_list[i] <= h_list[i+1]):
        result = 'No'

print(result)
Buggy python submission (verdict: Runtime Error):
import sys
import math


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


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


fin = sys.stdin.readline
N, K = [int(elem) for elem in fin().split()]

for i in range(1, K):
    if (N-K+1) < i:
        print(0)
    else:
        result = int(permutations_count(N-K+1, i) / math.factorial(i-1))
        print(int(result % 1000000007))

if (N-K+1) < K:
    print(0)
else:
    result = int(combinations_count(N-K+1, K))
    print(int(result % 1000000007))


Fixed submission:
import sys
import math


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


fin = sys.stdin.readline
N, K = [int(elem) for elem in fin().split()]

for i in range(1, K+1):
    if (N-K+1) < i:
        print(0)
    else:
        result = int(combinations_count(N-K+1, i) * combinations_count(K-1, i-1))
        print(int(result % 1000000007))

Buggy python submission (verdict: Runtime Error):
import sys
import math


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


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


fin = sys.stdin.readline
N, K = [int(elem) for elem in fin().split()]

for i in range(1, K):
    result = int(permutations_count(N-K+1, i) / math.factorial(i-1))
    print(int(result % 1000000007))

result = int(combinations_count(N-K+1, K))
print(int(result % 1000000007))


Fixed submission:
import sys
import math


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


fin = sys.stdin.readline
N, K = [int(elem) for elem in fin().split()]

for i in range(1, K+1):
    if (N-K+1) < i:
        print(0)
    else:
        result = int(combinations_count(N-K+1, i) * combinations_count(K-1, i-1))
        print(int(result % 1000000007))
Buggy python submission (verdict: Runtime Error):
import sys

fin = sys.stdin.readline
num = str(int(fin()))

readable = True
prev_num = num[0]
for i in range(1, 4):
    cur_num = num[i]
    if prev_num == cur_num:
        readable = False
    prev_num = cur_num

if readable:
    print('Good')
else:
    print('Bad')


Fixed submission:
import sys

fin = sys.stdin.readline
num = str(fin()).split()[0]

readable = True
prev_num = num[0]
for i in range(1, 4):
    cur_num = num[i]
    if prev_num == cur_num:
        readable = False
    prev_num = cur_num

if readable:
    print('Good')
else:
    print('Bad')
Buggy python submission (verdict: Time Limit Exceeded):
import sys

fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
conditions = [tuple(int(elem) for elem in fin().split()) for _ in range(M)]

current_set = set(range(1, 100001))
for l, r in conditions:
    new_set = set(range(l, r+1))
    current_set = new_set & current_set

print(len(current_set))


Fixed submission:
import sys

fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
conditions = [tuple(int(elem) for elem in fin().split()) for _ in range(M)]

l_list = [x[0] for x in conditions]
r_list = [x[1] for x in conditions]

print(max(0, min(r_list) - max(l_list) + 1))
Buggy python submission (verdict: Runtime Error):
import sys

a = []
for l in sys.stdin:
    a.append(l)

_input = a[0]

def is_month(x):
    # x: 2桁の数字
    if 12 >= x > 0:
        return True
    else:
        return False

input_l = _input[:2]
input_r = _input[2:]

if is_month(input_l):
    if is_month(input_r):
        result = 'AMBIGUOUS'
    else:
        result = 'MMYY'
else:
    if is_month(input_r):
        result = 'YYMM'
    else:
        result = 'NA'
        
print(result)


Fixed submission:
import sys

a = []
for l in sys.stdin:
    a.append(l)

_input = a[0]

def is_month(x):
    # x: 2桁の数字
    if 12 >= x > 0:
        return True
    else:
        return False


input_l = int(_input[:2])
input_r = int(_input[2:])

if is_month(input_l):
    if is_month(input_r):
        result = 'AMBIGUOUS'
    else:
        result = 'MMYY'
else:
    if is_month(input_r):
        result = 'YYMM'
    else:
        result = 'NA'

print(result)
Buggy python submission (verdict: Runtime Error):
import sys


def count(split_haichi):
    black_count = sum([x == '#' for x in split_haichi])
    white_count = len(split_haichi) - black_count
    return min(black_count, white_count)


a = []
for l in sys.stdin:
    a.append(l)

num = int(a[0])
haichi = a[1]
count_list = []

black_all_count = sum([x == '#' for x in haichi])
white_all_count = num - black_all_count
for i in range(num-1):
    if haichi[i] == '#':
        split_haichi_1 = haichi[:i+1]
        split_haichi_2 = haichi[i+1:]

        black_count_1 = sum([x == '#' for x in split_haichi_1])
        white_count_1 = len(split_haichi_1) - black_count_1

        black_count_2 = black_all_count - black_count_1
        white_count_2 = white_all_count - white_count_1

        count_list.append(min(black_count_1, white_count_1) + min(black_count_2, white_count_2))

print(min(count_list))


Fixed submission:
import sys
a = []
for l in sys.stdin:
    a.append(l)

zahyou = [int(x) for x in a[0].split()]
a, b, c = zahyou
if max(zahyou) == c or min(zahyou) == c:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
import sys

def count(split_haichi):
    black_count = sum([x == '#' for x in split_haichi])
    white_count = sum([x == '.' for x in split_haichi])
    return min(black_count, white_count)

a = []
for l in sys.stdin:
    a.append(l)

num = int(a[0])
haichi = a[1]
count_list = []
for i in range(num-1):
    split_haichi_1 = haichi[:i+1]
    split_haichi_2 = haichi[i+1:]
    count_1 = count(split_haichi_1)
    count_2 = count(split_haichi_2)
    count_list.append(count_1 + count_2)

print(min(count_list))


Fixed submission:
import sys
a = []
for l in sys.stdin:
    a.append(l)

zahyou = [int(x) for x in a[0].split()]
a, b, c = zahyou
if max(zahyou) == c or min(zahyou) == c:
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
import sys
a = []
for l in sys.stdin:
    a.append(l)

zahyou = [int(x) for x in a.split()]

if ((zahyou[0] >= zahyou[1]) and (zahyou[1] >= zahyou[2])) or ((zahyou[0] <= zahyou[1]) and (zahyou[1] <= zahyou[2])):
    print("No")
else:
    print("Yes")

Fixed submission:
import sys
a = []
for l in sys.stdin:
    a.append(l)

zahyou = [int(x) for x in a[0].split()]
a, b, c = zahyou
if max(zahyou) == c or min(zahyou) == c:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from functools import reduce
from operator import add, mul

from functools import lru_cache
@lru_cache(maxsize=None)  # メモ化したい関数の前につける
def fib(n):  # n 番目のフィボナッチ数を求める関数
    if n <= 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fib(n - 2) + fib(n - 1)


nm = [int(i) for i in stdin.readline().rstrip().split(" ")]
a = []
for i in range(nm[1]):
    a.append(int(stdin.readline().rstrip()))
result =[]
result.append(fib(a[0]))
for i in range(nm[1]-1):
    result.append(fib(a[i+1] - a[i] - 1))
result.append(fib(nm[0] - a[nm[1]-1]))
print(reduce(mul, result) % 1000000007)

Fixed submission:
from sys import stdin

abc = [int(i) for i in stdin.readline().rstrip().split(" ")]
s = sum(abc) 
m = max(abc)
print(s-m)
Buggy python submission (verdict: Runtime Error):
S = int(input())
r = 10**9

a = (S-1) % r
b = (S-1) // r
print("0 0 1 " + str(10 ** 9) + " " + str(a) + " " + str(b))
a = int(input())
xa = 0
ya = 0
xb = 10**9
yb = 1
xc = xb - a
yc = 1
print("{} {} {} {} {} {}".format(xa, ya, xb, yb, xc, yc))


Fixed submission:
a = int(input())
ax = 0
ay = 0
bx = 10 ** 9
by = 1
cy = (a + bx - 1) // bx
cx = cy * bx - a
print(ax, ay, bx, by, cx, cy)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = 10 ** 9
for i in range(a, b + 1):
    for j in range(a, b + 1):
        if i != j
            c = min(c, i * j % 2019)
            if c == 0:
                print()
                exit()
print(c)


Fixed submission:
a, b = map(int, input().split())
c = 2019

if b - a >= 2019:
    print(0)
else:
    for i in range(a, b):
        for j in range(a + 1 , b + 1):
            c = min(c, i * j % 2019)
    print(c)

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

for i in range(a, b):
  for j in range(a + 1 , b + 1):
    c = min(c, i * j % 2019)
    if c == 0:
    	print(c)
        exit()
print(c)


Fixed submission:
a, b = map(int, input().split())
c = 2019

if b - a >= 2019:
    print(0)
else:
    for i in range(a, b):
        for j in range(a + 1 , b + 1):
            c = min(c, i * j % 2019)
    print(c)
Buggy python submission (verdict: Runtime Error):
a = input()
a = a.replace(a[0], "")
a = a.replace(a[0], "")
if len(a) == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
a = input()
a = a.replace(a[0], "")
if len(a) == 0:
    print("No")
    exit()
a = a.replace(a[0], "")
if len(a) == 0:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
a = input()
a = a.replace(c[0], "")
a = a.replace(c[0], "")
if len(a) == 0:
    print("Yes")
else:
    print("No")
    

Fixed submission:
a = input()
a = a.replace(a[0], "")
if len(a) == 0:
    print("No")
    exit()
a = a.replace(a[0], "")
if len(a) == 0:
    print("Yes")
else:
    print("No")
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())
e = b - int(b / c) - int(b / d) + int(b / lcm(c, d))
f = (a - 1) - int((a - 1) / c) - int((a - 1) / d) + int((a - 1) / lcm(c, d))
print(e - f)


Fixed submission:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


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


a, b, c, d = map(int, input().split())
a = a - 1
e = b - b // c - b // d + b // lcm(c, d)
f = a - a // c - a // d + a // lcm(c, d)
print(e - f)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 1
e = 0
for i in range(a):
    e += c[i]
    if e <= b:
        d += 1
print(d)
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 1
e = 0
for i in range(a):
    e += c[i]
    if e <= b:
        d += 1
    else:
        break
print(d)


Fixed submission:
a, b = map(int, input().split())
d = 0
e = 1
for i in list(map(int, input().split())):
    d += i
    if d > b:
        break
    e += 1
print(e)
Buggy python submission (verdict: Runtime Error):
a

Fixed submission:
a, b, c, d = map(int, input().split())
if a / 2 == c and b / 2 == d:
    print(str(a * b / 2) + " " + "1")
else:
    print(str(a * b / 2) + " " + "0")
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
c = [int(input())for _ in range(b)]
d = [0] * (a+1)
d[0] = 1 if 0 not in c else 0
d[1] = 1 if 1 not in c else 0
for i in range(2, a+1):
    if i not in c:
        d[i] = (d[i-1] + d[i-2]) % 1000000007
    else:
        d[i] = 0
print(d[len(d)-1])


Fixed submission:
a, b = map(int, input().split())
d = [True] * (a+1)
for i in range(b):
    d[int(input())] = False
e = [0] * (a+1)
for i in range(0, a+1):
    if i < 2:
        if d[i]:
            e[i] = 1
        else:
            e[i] = 0
    elif not d[i] and not d[i-1]:
        print(0)
        exit()
    elif d[i]:
        e[i] = (e[i-2] + e[i-1]) % 1000000007
print(e[len(e)-1])

Buggy python submission (verdict: Runtime Error):
a

Fixed submission:
a, b = map(int, input().split())
d = [True] * (a+1)
for i in range(b):
    d[int(input())] = False
e = [0] * (a+1)
for i in range(0, a+1):
    if i < 2:
        if d[i]:
            e[i] = 1
        else:
            e[i] = 0
    elif not d[i] and not d[i-1]:
        print(0)
        exit()
    elif d[i]:
        e[i] = (e[i-2] + e[i-1]) % 1000000007
print(e[len(e)-1])
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
a, b = map(int, input().split())
c = list(map(int, input().split()))
heapq.heapify(c)
for i in range(b):
    d, e = map(int, input().split())
    for j in range(d):
        f = heapq.heappop(c)
        if f >= e:
            heapq.heappush(c, f)
            break
        else:
            heapq.heappush(c, e)
print(sum(c))


Fixed submission:
import heapq
a, b = map(int, input().split())
c = list(map(int, input().split()))
heapq.heapify(c)
d = []
for i in range(b):
    e, f = map(int, input().split())
    d.append([e, f])
d = sorted(d, key=lambda x: x[1], reverse=True)
for i in range(len(d)):
    g = heapq.heappop(c)
    if d[i][1] < g:
        heapq.heappush(c, g)
        break
    else:
        heapq.heappush(c, g)
        for j in range(d[i][0]):
            g = heapq.heappop(c)
            if g < d[i][1]:
                heapq.heappush(c, d[i][1])
            else:
                heapq.heappush(c, g)
                break
print(sum(c))
Buggy python submission (verdict: Runtime Error):
a = input()
b = int(a[:2])
c = int(a[2:])
if 0 < b <= 12 and a < c <= 12:
    print("AMBIGUOUS")
elif 0 < b <= 12 and c > 12:
    print("MMYY")
elif b > 12 and 0 < c <= 12:
    print("YYMM")
else:
    print("NA")


Fixed submission:
a = input()

if 1 <= int(a[:2]) <= 12 and 1 <= int(a[2:]) <= 12:
    print("AMBIGUOUS")
elif 1 <= int(a[:2]) <= 12:
    print("MMYY")
elif 1 <= int(a[2:]) <= 12:
    print("YYMM")
else:
    print("NA")
Buggy python submission (verdict: Runtime Error):
a

Fixed submission:
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a = int(input())
b = list(map(int, input().split()))
b.append(0)
b.insert(0, 0)
c = [0]*(len(b))
d = [0]*(len(b))
for i in range(1, len(b)):
    c[i] = (g_c_d(b[i], c[i-1]))
    d[-i-1] = (g_c_d(b[-i-1], d[-i]))
e = 0
for i in range(0, len(c)-2):
    e = max(g_c_d(c[i], d[i+2]), e)
print(e)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
c = input()
for i in range(b):
    d, e = map(int, input().split())
    f = c[d-1:e]
    print((len(f)-len(f.replace("AC", "")))//2)

Fixed submission:
a, b = map(int, input().split())
c = input()
d = [0] * a
e = 0
for i in range(1, a):
    if c[i] == "C" and c[i-1] == "A":
        e += 1
    d[i] = e
for i in range(b):
    f, g = map(int, input().split())
    print(d[g-1]-d[f-1])

Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
c = input()
for i in range(b):
    d, e = map(int, input().split())
    f = 0
    for j in range(d, e):
        if c[j-1] == "A" and c[j] == "C":
            f += 1
    print(f)


Fixed submission:
a, b = map(int, input().split())
c = input()
d = [0] * a
e = 0
for i in range(1, a):
    if c[i] == "C" and c[i-1] == "A":
        e += 1
    d[i] = e
for i in range(b):
    f, g = map(int, input().split())
    print(d[g-1]-d[f-1])

Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
c = input()

for i in range(b):
    d, e = map(int, input().split())
    f = c[d-1:e]
    print((len(f) - len(f.replace("AC", ""))) // 2)


Fixed submission:
a, b = map(int, input().split())
c = input()
d = [0] * a
e = 0
for i in range(1, a):
    if c[i] == "C" and c[i-1] == "A":
        e += 1
    d[i] = e
for i in range(b):
    f, g = map(int, input().split())
    print(d[g-1]-d[f-1])
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = list(map(int, input
s = 0
for i in range(44, -1, -1):
    if 2 ** i + s <= b
        if a > d[i] * 2:
            s += 2 ** i
for i in c:
    ans += i ^ s
print(ans)


Fixed submission:
a, b = map(int, input().split())
print(a / b)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [0] * 45
for i in c:
    e = bin(i)[2:]
    for j in range(len(e)):
        d[j] += 1 if e[-j-1] == "1" else 0
ans = 0
s = 0
for i in range(44, -1, -1):
    if 2 ** i + s <= b
        if a > d[i] * 2:
            s += 2 ** i
for i in c:
    ans += i ^ s
print(ans)


Fixed submission:
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [0] * 45
for i in c:
    e = bin(i)[2:]
    for j in range(len(e)):
        d[j] += 1 if e[-j-1] == "1" else 0
e = 0
for i in range(len(d)-1, -1, -1):
    if 2 ** i + e <= b:
        if d[i] <= len(c) // 2:
            e += 2 ** i
f = 0
for i in range(len(c)):
    f += e ^ c[i]
print(f)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [0] * 45
for i in c:
    e = bin(i)[2:]
    for j in range(len(e)):
        d[j] += 1 if e[-j-1] == "1" else 0
ans = 0
s = 0
for i in range(44, -1, -1):
    if 2 ** i + s <= b
        if a > d[i] * 2:
            s += 2 ** i
for i in c:
    ans += i ^ s
print(ans)


Fixed submission:
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [0] * 45
for i in c:
    e = bin(i)[2:]
    for j in range(len(e)):
        d[j] += 1 if e[-j-1] == "1" else 0
e = 0
for i in range(len(d)-1, -1, -1):
    if 2 ** i + e <= b:
        if d[i] <= len(c) // 2:
            e += 2 ** i
f = 0
for i in range(len(c)):
    f += e ^ c[i]
print(f)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = [a]
c = 0
while:
  c += 1
  if a % 2 == 0:
    a /= 2
    if b.contain(a):
      print(c)
      exit()
    else:
      b.append(a)
  else:
    a = a * 3 + 1
    if b.contain(a):
      print(c)
      exit()
    else:
      b.append(a)


Fixed submission:
a = int(input())
b = [a]
c = 1
while True:
  c += 1
  if a % 2 == 0:
    a /= 2
    if a in b:
      print(c)
      exit()
    else:
      b.append(a)
  else:
    a = a * 3 + 1
    if a in b:
      print(c)
      exit()
    else:
      b.append(a)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = [int(input()) for _ in range(a)]
b = sorted(b, key=lambda, x: x[0], reverse=True)
c = 1
for i in range(a):
  if i == 0:
    c += b[i] // 2
  else:
    c += b[i]
print(c)


Fixed submission:
a = int(input())
b = [int(input()) for _ in range(a)]
b = sorted(b, reverse=True)
c  = 0
for i in range(a):
    if i == 0:
        c += b[i] // 2
    else:
        c += b[i]
print(c)

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = [int(input()) for _ in range(a)]
b = sorted(b, key=lambda, x: x[0], reverse=True)
c = 0
for i in range(a):
  if i == 0:
    c += b[i] // 2
  else:
    c += b[i]
print(c)


Fixed submission:
a = int(input())
b = [int(input()) for _ in range(a)]
b = sorted(b, reverse=True)
c  = 0
for i in range(a):
    if i == 0:
        c += b[i] // 2
    else:
        c += b[i]
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
c = []
h = []
for i in range(b):
    d, e = map(int, input().split())
    c.append([e, d, 0])
    h.append([e, d, 0])
h.sort()
for i in range(a):
    g = 1
    for j in range(b):
        if h[j][1] == i + 1:
            h[j][2] = g
            g += 1
for i in range(b):
    for j in range(b):
        if c[i][0] == h[j][0] and c[i][1] == h[j][1]:
            print(("000000" + str(h[j][1]))[-6:] + ("000000" + str(h[j][2]))[-6:])
            break


Fixed submission:
a, b = map(int, input().split())
c = []
for i in range(b):
    d, e = map(int, input().split())
    c.append([i, d, e, 0])
c = sorted(c, key=lambda x: x[2], reverse=False)
d = [0] * a
for i in range(b):
    d[c[i][1]-1] += 1
    c[i][3] = d[c[i][1]-1]
c.sort()
for i in range(b):
    print(("000000" + str(c[i][1]))[-6:] + ("000000" + str(c[i][3]))[-6:])
Buggy python submission (verdict: Runtime Error):
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


def l_c_m(x, y):
    return x * y // g_c_d(x, y)


a, b = map(int, input().split())
c = input()
d = input()
f = l_c_m(a, b)
e = [""] * f
for i in range(0, f):
    if i * f // a > f - 1:
        break
    if e[i * f // a] == "":
        e[i * f // a] = c[i]
    elif e[i * f // a] != c[i]:
        print(-1)
        exit()
    if i * f // b > f - 1:
        break
    if e[i * f // b] == "":
        e[i * f // b] = d[i]
    elif e[i * f // b] != d[i]:
        print(-1)
        exit()
print(f)


Fixed submission:
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


def l_c_m(x, y):
    return x * y // g_c_d(x, y)


a, b = map(int, input().split())
c = input()
d = input()
lcm = l_c_m(a, b)
gcd = g_c_d(a, b)
for i in range(0, gcd):
    if c[i * a // gcd] != d[i * b // gcd]:
        print(-1)
        exit()
print(lcm)

Buggy python submission (verdict: Runtime Error):
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


def l_c_m(x, y):
    return x * y // g_c_d(x, y)


a, b = map(int, input().split())
c = input()
d = input()
f = l_c_m(a, b)
e = [""] * f
for i in range(0, 6):
    if i * f // a >= f - 1:
        break
    if e[i * f // a] == "":
        e[i * f // a] = c[i]
    elif e[i * f // a] != c[i]:
        print(-1)
        exit()
    if i * f // b >= f - 1:
        break
    if e[i * f // b] == "":
        e[i * f // b] = d[i]
    elif e[i * f // b] != d[i]:
        print(-1)
        exit()
print(f)


Fixed submission:
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


def l_c_m(x, y):
    return x * y // g_c_d(x, y)


a, b = map(int, input().split())
c = input()
d = input()
lcm = l_c_m(a, b)
gcd = g_c_d(a, b)
for i in range(0, gcd):
    if c[i * a // gcd] != d[i * b // gcd]:
        print(-1)
        exit()
print(lcm)