Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
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()))

C.sort(reverse=True)
tmp = []
ans = []

for i in range(X):
	for j in range(Y):
		tmp.append(A[i]+B[j])

tmp.sort(reverse=True)
del tmp[min(K, X*Y):]

for i in range(len(tmp)):
	for j in range(min(Z, K)):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])


Fixed submission:
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()))

C.sort(reverse=True)
tmp = []
ans = []

for i in range(X):
	for j in range(Y):
		tmp.append(A[i]+B[j])

tmp.sort(reverse=True)
del tmp[min(K, X*Y):]

for i in range(len(tmp)):
	for j in range(min(Z, K)):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
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()))

C.sort(reverse=True)
tmp = []
ans = []

for i in range(X):
	for j in range(Y):
		tmp.append(A[i]+B[j])
tmp.sort(reverse=True)

for i in range(min(X*Y, K)):
	for j in range(min(Z, K)):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])


Fixed submission:
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()))

C.sort(reverse=True)
tmp = []
ans = []

for i in range(X):
	for j in range(Y):
		tmp.append(A[i]+B[j])

tmp.sort(reverse=True)
del tmp[min(K, X*Y):]

for i in range(len(tmp)):
	for j in range(min(Z, K)):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
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()))

C.sort(reverse=True)
tmp = []
ans = []

for i in range(X):
	for j in range(Y):
		tmp.append(A[i]+B[j])
tmp.sort(reverse=True)

for i in range(min(X*Y, K)):
	for j in range(Z):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])


Fixed submission:
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()))

C.sort(reverse=True)
tmp = []
ans = []

for i in range(X):
	for j in range(Y):
		tmp.append(A[i]+B[j])

tmp.sort(reverse=True)
del tmp[min(K, X*Y):]

for i in range(len(tmp)):
	for j in range(min(Z, K)):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = input()
T = []
D = []
for _ in range(Q):
	t, d = input().split()
	T.append(t)
	D.append(d)


ans = 0
left = 0
right = N-1
for i in range(Q-1,-1,-1):
	if D[i] == 'R':
		if T[i] == s[right]:
			right -= 1
		if left > 0 and s[left-1]==T[i]:
			left -= 1

	else:
		if T[i] == s[left]:
			left += 1
		if right < N-1 and s[right+1]==T[i]:
			right += 1
	# print(s[left:right+1])
print(max(0,right-left+1))


Fixed submission:
N, Q = map(int, input().split())
s = input()
T = []
D = []
for _ in range(Q):
	t, d = input().split()
	T.append(t)
	D.append(d)


ans = 0
left = 0
right = N-1
for i in range(Q-1,-1,-1):
	if D[i] == 'R':
		if T[i] == s[right]:
			right -= 1
			if right == 0:
				print(0)
				exit()
		if left > 0 and s[left-1]==T[i]:
			left -= 1

	else:
		if T[i] == s[left]:
			left += 1
			if left == N-1:
				print(0)
				exit()
		if right < N-1 and s[right+1]==T[i]:
			right += 1
	# print(s[left:right+1])
print(max(0,right-left+1))

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = input()
T = []
D = []
for _ in range(Q):
	t, d = input().split()
	T.append(t)
	D.append(d)


ans = 0
left = 0
right = N-1
for i in range(Q-1,-1,-1):
	if D[i] == 'R':
		if T[i] == s[right]:
			right -= 1
		if left > 0 and s[left-1]==T[i]:
			left -= 1

	else:
		if T[i] == s[left]:
			left += 1
		if right < N-1 and s[right+1]==T[i]:
			right += 1
	# print(s[left:right+1])
print(right-left+1)


Fixed submission:
N, Q = map(int, input().split())
s = input()
T = []
D = []
for _ in range(Q):
	t, d = input().split()
	T.append(t)
	D.append(d)


ans = 0
left = 0
right = N-1
for i in range(Q-1,-1,-1):
	if D[i] == 'R':
		if T[i] == s[right]:
			right -= 1
			if right == 0:
				print(0)
				exit()
		if left > 0 and s[left-1]==T[i]:
			left -= 1

	else:
		if T[i] == s[left]:
			left += 1
			if left == N-1:
				print(0)
				exit()
		if right < N-1 and s[right+1]==T[i]:
			right += 1
	# print(s[left:right+1])
print(max(0,right-left+1))

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
s = input()
T = []
D = []
for _ in range(Q):
	t, d = input().split()
	T.append(t)
	D.append(d)


ans = 0
left = 0
right = N-1
for i in range(Q-1,-1,-1):
	# print(D[i])
	if D[i] == 'R':
		if T[i] == s[right]:
			right -= 1
		if left > 0 and s[left-1]==T[i]:
			left -= 1

	else:
		if T[i] == s[left]:
			left += 1
		if right < N-1 and s[right+1]==T[i]:
			right += 1
	print(s[left:right+1])
print(right-left+1)


Fixed submission:
N, Q = map(int, input().split())
s = input()
T = []
D = []
for _ in range(Q):
	t, d = input().split()
	T.append(t)
	D.append(d)


ans = 0
left = 0
right = N-1
for i in range(Q-1,-1,-1):
	if D[i] == 'R':
		if T[i] == s[right]:
			right -= 1
			if right == 0:
				print(0)
				exit()
		if left > 0 and s[left-1]==T[i]:
			left -= 1

	else:
		if T[i] == s[left]:
			left += 1
			if left == N-1:
				print(0)
				exit()
		if right < N-1 and s[right+1]==T[i]:
			right += 1
	# print(s[left:right+1])
print(max(0,right-left+1))
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
l = [0]*100
s = ''
for i in range(A,B+1,1):
    bi = bin(i)[2:]
    # print(bi)
    for j in range(1,len(bi)+1):
        if bi[-j] == '1':
            l[j] = (l[j]+1)%2
for i in range(len(l)):
    s = s + str(l[-i])
print(int(s, 2))


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

def XOR(A):
    # 0からAまでの排他的論理和を求める
    if A%4 == 0:
        return A
    elif A%4 == 2:
        return A+1
    elif A%4 == 1:
        return 1
    else:
        return 0

fA = XOR(A-1)
fB = XOR(B)
print(fB^fA)

Buggy python submission (verdict: Time Limit Exceeded):
# import numpy as np
A, B = map(int, input().split())

# ans = A
# for i in range(A+1,B+1,1):
#     ans = ans^i
# print(ans)
# counter = 0

# list = np.zeros(50)
# for i in range(A,B+1,1):
#     list += np.array(list(map(int, str(i))).reverse())
# for i in range(len(list)):
#     list[i] = list[i]%2
# list.reverse()
# print(list)

l = [0]*100
s = ''
for i in range(A,B+1,1):
    bi = bin(i)[2:]
    # print(bi)
    for j in range(1,len(bi)+1):
        if bi[-j] == '1':
            l[j] = (l[j]+1)%2

for i in range(len(l)):
    s = s + str(l[-i])
print(int(s, 2))


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

def XOR(A):
    # 0からAまでの排他的論理和を求める
    if A%4 == 0:
        return A
    elif A%4 == 2:
        return A+1
    elif A%4 == 1:
        return 1
    else:
        return 0

fA = XOR(A-1)
fB = XOR(B)
print(fB^fA)

Buggy python submission (verdict: Runtime Error):
import numpy as np
A, B = map(int, input().split())

# ans = A
# for i in range(A+1,B+1,1):
#     ans = ans^i
# print(ans)
# counter = 0

# list = np.zeros(50)
# for i in range(A,B+1,1):
#     list += np.array(list(map(int, str(i))).reverse())
# for i in range(len(list)):
#     list[i] = list[i]%2
# list.reverse()
# print(list)

l = [0]*100
s = ''
for i in range(A,B+1,1):
    bi = bin(i)[2:]
    # print(bi)
    for j in range(1,len(bi)+1):
        if bi[-j] == '1':
            l[j] = (l[j]+1)%2

for i in range(len(l)):
    s = s + str(l[-i])
print(int(s, 2))


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

def XOR(A):
    # 0からAまでの排他的論理和を求める
    if A%4 == 0:
        return A
    elif A%4 == 2:
        return A+1
    elif A%4 == 1:
        return 1
    else:
        return 0

fA = XOR(A-1)
fB = XOR(B)
print(fB^fA)

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

ans = A
for i in range(A+1,B+1,1):
    ans = ans^i
print(ans)


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

def XOR(A):
    # 0からAまでの排他的論理和を求める
    if A%4 == 0:
        return A
    elif A%4 == 2:
        return A+1
    elif A%4 == 1:
        return 1
    else:
        return 0

fA = XOR(A-1)
fB = XOR(B)
print(fB^fA)

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

ans = A
for i in range(A+1,B+1,1):
    ans = ans^i
print(ans)


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

def XOR(A):
    # 0からAまでの排他的論理和を求める
    if A%4 == 0:
        return A
    elif A%4 == 2:
        return A+1
    elif A%4 == 1:
        return 1
    else:
        return 0

fA = XOR(A-1)
fB = XOR(B)
print(fB^fA)
Buggy python submission (verdict: Runtime Error):
import sys
from sys import stdin

def f(num):
  d = []
  if num != 1:
    for i in range(1,num):
      if num % i == 0:
    	  d.append(i)
  else:
      d = [1]
  return d

A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = f(A)
b = f(B)
d = set(a)&set(b)
d = list(d)
print(d[C-1])

Fixed submission:
from sys import stdin

def f(num):
  d = []
  if num != 1:
    for i in range(1,num):
      if num % i == 0:
    	  d.append(i)
      d.append(num)
  else:
      d = [1]
  return d

A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
a = f(A)
b = f(B)
d = set(a)&set(b)
d = sorted(list(d),reverse=True)
print(d[C-1])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
S = list(S)
count_p = 0
count = 0

mark = 1
if len(S) <= 1:
    print(0)
    mark = 0
while mark:
    i = 0
    while i < len(S)-1:
        if int(S[i])+int(S[i+1]) == 1:
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2
        else:
            i += 1
    if count == count_p:
        print(count)
        break
    else:
        count_p = count
        S = [e for e in S if e!='2']


Fixed submission:
S = list(input())
a = 0
b = 0
for i in range(len(S)):
  if int(S[i]):
    a += 1
  else:
    b += 1
if a < b:
  print(a*2)
else:
  print(b*2)

Buggy python submission (verdict: Time Limit Exceeded):
# from sys import stdin
# S = stdin.readline().rstrip().split()
S = input()
S = list(S)
# print(S)
count_p = 0
count = 0

mark = 1
if len(S) <= 1:
    print(0)
    mark = 0
while mark:
    i = 0
    while i < len(S)-1:
        if S[i] == '0' and S[i+1] == '1':
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2
        elif S[i] == '1' and S[i+1] == '0':
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2
        else:
            i += 1
        # print(S)
    if count == count_p:
        print(count)
        break
    else:
        count_p = count
        A = []
        for i in range(len(S)):
            if S[i] != '2':
                A.append(S[i])
        S = A
        # print(S)
        # if len(S) == 2:
        #     if S[0] == '0'
        #      and (S == ['0', '1'] or ['1', '0']):
        #     count += 2
        #     print(count)
        #     break


Fixed submission:
S = list(input())
a = 0
b = 0
for i in range(len(S)):
  if int(S[i]):
    a += 1
  else:
    b += 1
if a < b:
  print(a*2)
else:
  print(b*2)
Buggy python submission (verdict: Runtime Error):
s = input().replace('/','')
if s[4:5] == 1:
  print('TBD')
else:
  if s[5:6] > 4:
    print('TBD')
  else:
    print('Heisei')


Fixed submission:
s = input().replace('/','')
if s[4:5] == '1':
  print('TBD')
else:
  if int(s[5:6]) > 4:
    print('TBD')
  else:
    print('Heisei')

Buggy python submission (verdict: Runtime Error):
s = input().replace('/','')
if s[4:5] == 1:
  return TBD
else:
  if s[5:6] > 4:
    return TBD
  else:
    return Heisei


Fixed submission:
s = input().replace('/','')
if s[4:5] == '1':
  print('TBD')
else:
  if int(s[5:6]) > 4:
    print('TBD')
  else:
    print('Heisei')
Buggy python submission (verdict: Runtime Error):
N = int(input())
sum = 0
for i in range N:
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)


Fixed submission:
N = int(input())
sum = 0
for i in range (N):
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())
sum = 0
for i in N:
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)


Fixed submission:
N = int(input())
sum = 0
for i in range (N):
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)

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

N = int(input())
sum = 0
for i in N:
  X = input().split()
  if x[1] == 'JPY':
    sum += float(x[1])
  else:
  	sum += float(x)*380000
print(sum)


Fixed submission:
N = int(input())
sum = 0
for i in range (N):
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)

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

N = int(input())
sum = 0
for i in N:
  x,u = stdin.readline().rstrip().split()
  if u == 'JPY':
    sum += int(x)
  else:
  	sum += float(x)*380000
print(sum)


Fixed submission:
N = int(input())
sum = 0
for i in range (N):
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)

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

N = int(input())
sum = 0
for i in N:
  x,u = stdin.readline().rstrip().split()
  if u == 'JPY':
    sum += int(x)
  else:
  	sum += float(x)*38000
print(sum)


Fixed submission:
N = int(input())
sum = 0
for i in range (N):
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())
sum = 0
for i in N:
  x,u = stdin.readline().rstrip().split()
  if u == 'JPY':
    sum += int(x)
  else:
  	sum += float(x)*38000
print(sum)


Fixed submission:
N = int(input())
sum = 0
for i in range (N):
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)

Buggy python submission (verdict: Runtime Error):
N = input()
sum = 0
for i in N:
  x,u = stdin.readline().rstrip().split()
  if u == 'JPY':
    sum += int(x)
  else:
  	sum += float(x)*38000
print(sum)

Fixed submission:
N = int(input())
sum = 0
for i in range (N):
  X = input().split()
  if X[1] == 'JPY':
    sum += float(X[0])
  else:
  	sum += float(X[0])*380000
print(sum)
Buggy python submission (verdict: Runtime Error):
A,B = int(input().split())
if (B%A==0):
  print(A+B)
else:
  print(B-A)

Fixed submission:
from sys import stdin
A, B = [int(x) for x in stdin.readline().rstrip().split()]
if (B%A==0):
  print(A+B)
else:
  print(B-A)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
l = []
for i in range(N):
    l.append(stdin.readline().rstrip().split())
k = l[0]
for i in range(N):
    k = k&l[i]
print(len(k))

Fixed submission:
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
l = []
m = []
for i in range(N):
    l.append(stdin.readline().rstrip().split())
    l[i].pop(0)
k = l[N-1]
for i in range(N-1):
    k = set(k)&set(l[i])
print(len(k))
Buggy python submission (verdict: Runtime Error):
string = input().replace('','/')
print(eval(string))


Fixed submission:
string = input().replace(' ','/')
print(eval(string))
Buggy python submission (verdict: Runtime Error):
L = map(int, input().split())
print(L[0]*L[1]/2)

Fixed submission:
L = list(map(int,input().split()))
print(int(L[0]*L[1]/2))
Buggy python submission (verdict: Runtime Error):
l = []
l.append(int(input()))
i = 0
while True:
  if s&2:
    l.append(3*l[i]+1)
  else:
    l.append(l[i]/2)
  i += 1
  for j in range(j,i):
    if l[j] == l[i]:
      break
print(i)

Fixed submission:
l = []
l.append(int(input()))
i = 0
key = 1
while key:
  if l[i]%2:
    l.append(3*l[i]+1)
  else:
    l.append(l[i]/2)
  i += 1
  for j in range(i-1):
    if l[j] == l[i]:
      key = 0
      print(i+1)
      break
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
ans = 0
# print(S)
cl1 = []
cl2 = []
while True:
	for i in range(len(S)-1):
		if S[i] == 'B' and S[i+1] == 'W' and i not in cl1:
			S[i] = 'W'
			S[i+1] = 'B'
			ans += 1
			cl1.append(i)
		elif S[i] == 'W' and S[i+1] == 'B' and i not in cl1:
			S[i] = 'B'
			S[i+1] = 'W'
			ans += 1
			cl1.append(i)
		else:
			pass
		# print(S)
	if cl1 == cl2:
		break
	else:
		cl1, cl2 = cl2, cl1
		cl1 = []
print(ans)


Fixed submission:
S = list(input())
move = 0
ans = 0
for i in range(len(S)):
	if S[i] == 'B':
		move += 1
	else:
		ans += move
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
tmp = 1
beki = []
while tmp < 2*10**9:
	tmp *= 2
	beki.append(tmp)

ans = 0
i = 0
while i < len(A)-1:
	j = i+1
	while j < len(A):
		# print(i, j, len(A), A[i], A[j])
		if A[i]+A[j] in beki:
			ans += 1
			A.pop(j)
			i += 1
			j = i+1
		else:
			j += 1
	i += 1

print(ans)


Fixed submission:
import bisect

def binum(num):
	number_len = len(bin(num))-2
	f = 2**number_len -1
	return (num^f)+1

N = int(input())
A = list(map(int, input().split()))
A.sort()
cnt = 0

while len(A) > 0:
	k = A.pop()
	if len(A) == 0:
		break
	if int(k) != k:
		continue
	x = binum(k)
	if x > A[-1]:
		continue
	if A[bisect.bisect_left(A,x)] == x:
		A[bisect.bisect_left(A,x)] -= 0.5
		cnt += 1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
tmp = 1
beki = []
while tmp < 2*10**9:
	tmp *= 2
	beki.append(tmp)

ans = 0
for i in range(N):
	for j in range(i+1, N):
		if A[i]+A[j] in beki:
			ans += 1
			A[j] = 10**10
			break
print(ans)


Fixed submission:
import bisect

def binum(num):
	number_len = len(bin(num))-2
	f = 2**number_len -1
	return (num^f)+1

N = int(input())
A = list(map(int, input().split()))
A.sort()
cnt = 0

while len(A) > 0:
	k = A.pop()
	if len(A) == 0:
		break
	if int(k) != k:
		continue
	x = binum(k)
	if x > A[-1]:
		continue
	if A[bisect.bisect_left(A,x)] == x:
		A[bisect.bisect_left(A,x)] -= 0.5
		cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()
T = input()

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def lcm(m, n):
	return int(m*n/gcd(m,n))


L = lcm(N, M)
X = {}


for i in range(0,N):
	X[i*L//N] = S[i]
	# X[i*L//N] = S[i]
for i in range(0,M):
	if T[i] in X.values():
		if X[i*L//M] != T[i]:
			print(-1)
			exit()
	else:
		pass
print(L)


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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def lcm(m, n):
	return int(m*n/gcd(m,n))


L = lcm(N, M)
X = {}


for i in range(0,N):
	X[i*L//N] = S[i]
# print(X)
for i in range(0,M):
	if X.get(i*L//M) != None:
		if X[i*L//M] != T[i]:
			print(-1)
			exit()
	else:
		pass
print(L)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()
T = input()

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def lcm(m, n):
	return int(m*n/gcd(m,n))
L = lcm(N, M)
X = ['0'] * L

for i in range(0,N):
	X[i*L//N] = S[i]
for i in range(0,M):
	if X[i*L//M] != '0':
		if X[i*L//M] != T[i]:
			print(-1)
			exit()
	else:
		pass
print(lcm(N, M))


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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def lcm(m, n):
	return int(m*n/gcd(m,n))


L = lcm(N, M)
X = {}


for i in range(0,N):
	X[i*L//N] = S[i]
# print(X)
for i in range(0,M):
	if X.get(i*L//M) != None:
		if X[i*L//M] != T[i]:
			print(-1)
			exit()
	else:
		pass
print(L)
Buggy python submission (verdict: Runtime Error):
N = int(input())
x = [0]*N
y = [0]*N
h = [0]*N

for i in range(N):
	x[i], y[i], h[i] = map(int, input().split())
for cx in range(101):
	for cy in range(101):
		H = abs(x[0]-cx)+abs(y[0]-cy)+h[0]
		for i in range(N):
			# if H != abs(x[i]-cx)+abs(y[i]-cy)+h[i]:
			if h[i] != max(H-abs(x[i]-cx)-abs(y[i]-cy), 0):
				break
			if i == N-1:
				ans = [cx, cy, H]
				break
print(ans[0],ans[1],ans[2])


Fixed submission:
N = int(input())
p = [0, 0, 0]*N

p = [list(map(int, input().split())) for _ in range(N)]
p = sorted(p, key=lambda x:-x[2])
for cx in range(101):
	for cy in range(101):
		H = abs(p[0][0]-cx)+abs(p[0][1]-cy)+p[0][2]
		for i in range(N):
			# if H != abs(x[i]-cx)+abs(y[i]-cy)+h[i]:
			if p[i][2] != max(H-abs(p[i][0]-cx)-abs(p[i][1]-cy), 0):
				break
			if i == N-1:
				ans = [cx, cy, H]
				break
print(ans[0],ans[1],ans[2])

Buggy python submission (verdict: Runtime Error):
N = int(input())
x = [0]*N
y = [0]*N
h = [0]*N

for i in range(N):
	x[i], y[i], h[i] = map(int, input().split())
for cx in range(101):
	for cy in range(101):
		H = abs(x[0]-cx)+abs(y[0]-cy)+h[0]
		for i in range(N):
			if H != abs(x[i]-cx)+abs(y[i]-cy)+h[i]:
				break
			if i == N-1:
				ans = [cx, cy, H]
				break
print(ans[0],ans[1],ans[2])


Fixed submission:
N = int(input())
p = [0, 0, 0]*N

p = [list(map(int, input().split())) for _ in range(N)]
p = sorted(p, key=lambda x:-x[2])
for cx in range(101):
	for cy in range(101):
		H = abs(p[0][0]-cx)+abs(p[0][1]-cy)+p[0][2]
		for i in range(N):
			# if H != abs(x[i]-cx)+abs(y[i]-cy)+h[i]:
			if p[i][2] != max(H-abs(p[i][0]-cx)-abs(p[i][1]-cy), 0):
				break
			if i == N-1:
				ans = [cx, cy, H]
				break
print(ans[0],ans[1],ans[2])