Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
bingo_size = 3
a = []
an = set()
for _ in range(3):
  a.append(list(map(int, input().split())))
  for i in a[_]:
    an.add(i)

n = int(input())
b = set()
for _ in range(n):
  bi = int(input())
  if bi in an:
    b.add(bi)

for hi in range(3):
  ok = True
  for _ in range(3):
    if a[hi][_] not in b:
      ok = false
      break
    if ok:
      print("Yes")
      sys.exit()

for wi in range(3):
  ok = True
  for _ in range(3):
    if a[_][wi] not in b:
      ok = False
      break
  if ok:
    print("Yes")
    sys.exit()

if all([a[0][0] in b, a[1][1] in b, a[2][2] in b]) or all([a[0][2] in b, a[1][1] in b, a[2][0] in b]):
           print("Yes")
           sys.exit()
           
print("No")   

Fixed submission:
import sys
bingo_size = 3
a = []
an = set()
for _ in range(3):
  a.append(list(map(int, input().split())))

n = int(input())
b = set()
for _ in range(n):
  bi = int(input())
  b.add(bi)

for hi in range(3):
  ok = True
  for _ in range(3):
    if a[hi][_] not in b:
      ok = False
      
  if ok:
    print("Yes")
    sys.exit()

for wi in range(3):
  ok = True
  for _ in range(3):
    if a[_][wi] not in b:
      ok = False
      
  if ok:
    print("Yes")
    sys.exit()

if all([a[0][0] in b, a[1][1] in b, a[2][2] in b]) or all([a[0][2] in b, a[1][1] in b, a[2][0] in b]):
           print("Yes")
           sys.exit()
           
print("No")

Buggy python submission (verdict: Runtime Error):
import sys
bingo_size = 3
a = []
an = set()
for _ in range(3):
  a.append(list(map(int, input().split())))
  for i in a[_]:
    an.add(i)

n = int(input())
b = set()
for _ in range(n):
  bi = int(input())
  if bi in an:
    b.add(bi)

for hi in range(3):
  ok = True
  for _ in range(3):
    if a[hi][_] not in b:
      ok = false
      break
    if ok:
      print("Yes")

for wi in range(3):
  ok = True
  for _ in range(3):
    if a[_][wi] not in b:
      ok = false
      break
  if ok:
    print("Yes")

if all([a[0][0] in b, a[1][1] in b, a[2][2] in b]) or all([a[0][2] in b, a[1][1] in b, a[2][0] in b]):
           print("Yes")
           
print("No")   

Fixed submission:
import sys
bingo_size = 3
a = []
an = set()
for _ in range(3):
  a.append(list(map(int, input().split())))

n = int(input())
b = set()
for _ in range(n):
  bi = int(input())
  b.add(bi)

for hi in range(3):
  ok = True
  for _ in range(3):
    if a[hi][_] not in b:
      ok = False
      
  if ok:
    print("Yes")
    sys.exit()

for wi in range(3):
  ok = True
  for _ in range(3):
    if a[_][wi] not in b:
      ok = False
      
  if ok:
    print("Yes")
    sys.exit()

if all([a[0][0] in b, a[1][1] in b, a[2][2] in b]) or all([a[0][2] in b, a[1][1] in b, a[2][0] in b]):
           print("Yes")
           sys.exit()
           
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))

def expectation(N):
    exp = 0
    for i in range(1, N+1):
        exp += i/N
    return exp

Ps = []
s = 0
for p in P:
    s += p
    Ps.append(s)
    
cmax = Ps[K-1]
max_sp = 0

for ix in range(1, N-K+1):
    csum = Ps[ix+K-1] - Ps[ix-1]
    if cmax < csum:
        max_sp = ix
        cmax = csum

ans = 0
for ix in range(max_sp, max_sp+K):
    ans += expectation(P[ix])

print(ans)

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

def expectation(N):
    # exp = 0
    # for i in range(1, N+1):
    #     exp += i/N
    # return exp
    return N/2+0.5

Ps = []
s = 0
for p in P:
    s += p
    Ps.append(s)
    
cmax = Ps[K-1]
max_sp = 0

for ix in range(1, N-K+1):
    csum = Ps[ix+K-1] - Ps[ix-1]
    if cmax < csum:
        max_sp = ix
        cmax = csum

ans = 0
for ix in range(max_sp, max_sp+K):
    ans += expectation(P[ix])

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

diff = [0] * N
neg = []
pos = []
for i in range(N):
    diff[i] = A[i] - B[i]
    if diff[i] < 0:
        neg.append(diff[i])
    else:
        pos.append(diff[i])

if sum(diff) < 0:
    print(-1)
    exit(0)

tobe_supplied = sum(neg)
pos.sort(reverse=True)

cnt = len(neg)

for p in pos:
    if tobe_supplied >= 0:
        break
    cnt += 1
    tobe_supplied += p    

print(cnt)

Fixed submission:
N = int(input())
P = []

for _ in range(N):
    x, l = map(int,input().split())
    P.append((x - l, x+l))

P.sort(key=lambda x: x[1])

ans = 0
last = -1e9
for ix in range(0, N):
    if last <=  P[ix][0]:
        ans += 1
        last = P[ix][1]

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

for i in range(N):
    if i < K:
        ans.append(S)
    else:
        ans.append(S+1)

print(" ".join(ans))

Fixed submission:
N, K, S=map(int, input().split())
A=[str(S)]*K
if S==10**9:
  B=["1"]*(N-K)
else:
  B=[str(S+1)]*(N-K)
ans=A+B
print(" ".join(ans))
Buggy python submission (verdict: Runtime Error):
K, X = map(int, input().split())
if 500*K >= X:
  print("Yes")
else;
  print("No")

Fixed submission:
K, X = map(int, input().split())
if 500*K >= X:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

mp_score = {"r": P, "s": R, "p": S}

lines = [""] * K
for ix in range(K):
    for t in range(len(T)):
        if t%K == ix:
            lines[ix] += T[t]

# print(lines)
ans = 0
for l in lines:
    before = ""
    for c in l:
        if before == c:
            before = ""

        else:
            ans += mp_score[c]
            before = c

print(ans)

Fixed submission:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

mp_score = {"r": P, "s": R, "p": S}

lines = [""] * K
for ix in range(len(T)):
    lines[ix%K] += T[ix]

ans = 0
for l in lines:
    before = ""
    for c in l:
        if before == c:
            before = ""

        else:
            ans += mp_score[c]
            before = c

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

t = set([1, 2, 3])
s = set([a,b])
ans = t - s
print(list(ans[0]))


Fixed submission:
a = int(input())
b = int(input())
 
t = set([1, 2, 3])
s = set([a,b])
ans = t - s
print(list(ans)[0])
Buggy python submission (verdict: Runtime Error):
S = input()
d = {"SUN": 7, "MON":6, "TUE":5, "WED":4, "THR":3, "FRI":2, "SAT":1}
print(d[S])

Fixed submission:
S = input()

d = {"SUN": 7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1}
print(d[S])

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

d = {"SUN": 7, "MON":6, "TUE":5, "WED":4, "THR":3, "FRI":2, "SAT":1}
print(d[S])

Fixed submission:
S = input()

d = {"SUN": 7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1}
print(d[S])
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
# for kx in range(1, max(D)+1):
for kx in range(2, len(tmp)+1):
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    # p = cd[kx-1]
    # v = cd[kx]
    # print("{}^{}".format(p, v))
    while v > 0:
        ans *= p
        ans %= M
        v -= 1
# print(cd)

# for kx in range(1, max(D)+1):
#     ans *= pow(cd[kx-1], cd[kx],M)
#     ans %= M

print(ans)

Fixed submission:
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1


for kx in range(1, max(D)+1):
    ans *= pow(cd[kx-1], cd[kx],M)
    ans %= M

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1

import math
for kx in range(1, max(D)+1):
    ans *= math.pow(cd[kx-1], cd[kx],M)
    ans %= M

print(ans)

Fixed submission:
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1


for kx in range(1, max(D)+1):
    ans *= pow(cd[kx-1], cd[kx],M)
    ans %= M

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

if D[1:].index(0):
    print(0)
    exit(0)

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
# for kx in range(2, len(tmp)):
#     __, p = tmp[kx-1]
#     _, v = tmp[kx]
#     while v > 0:
#         ans *= p%M
#         v -= 1
# print(cd)
for kx in range(1, len(tmp)-1):
    _, p = tmp[kx]
    __, v = tmp[kx+1]
    # ans *= p**v%M
    while v > 0:
        ans *= p%M
        v -= 1

print(ans%M)

Fixed submission:
N = int(input())
D = list(map(int, input().split()))
M = 998244353
from collections import Counter

if D[0] != 0:
    print(0)
    exit(0)

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1


for kx in range(1, max(D)+1):
    ans *= pow(cd[kx-1], cd[kx],M)
    ans %= M

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

# import bisect

L.sort()
# print(L)

ans = 0
for l1ix in range(N-1, -1, -1):
    for l2ix in range(l1ix - 1, -1, -1):
        # binsearch
        l = -1
        r = l2ix + 1

        while (r - l) > 1:
            mid = l + (r - l) // 2

            if L[mid] < (L[l1ix] + L[l2ix]) and L[l2ix] < L[mid] + L[l1ix] and L[l1ix] < L[mid] + L[l2ix]:
                #ok
                r = mid
            else:
                #ng
                l = mid
        
        l3ix = r
        # if l2ix != l3ix:
        #     print("1,2,3=", L[l1ix], L[l2ix], L[l3ix])
        
        anst = l2ix - l3ix
        ans += anst if anst > 0 else 0

print(ans)
        


"""
O(N^3)だから間に合わない．明らかに間に合うアルゴリズムを探す
ans = 0
for aix in range(N):
    for bix in range(aix + 1, N):
        for cix in range(bix + 1, N):
            if L[aix] < L[bix] + L[cix] and L[bix] < L[aix] + L[cix] and L[cix] < L[aix] + L[bix]:
                # print("ok:", aix,",", bix,",", cix)
                ans += 1

print(ans)
"""


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

import bisect

L.sort()
# print(L)

ans = 0
for i in range(0, N-1):
    for j in range(i+1, N-1):
        ix = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, ix - j - 1)

print(ans)

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

ans = 0
for aix in range(N):
    for bix in range(aix + 1, N):
        for cix in range(bix + 1, N):
            if L[aix] < L[bix] + L[cix] and L[bix] < L[aix] + L[cix] and L[cix] < L[aix] + L[bix]:
                # print("ok:", aix,",", bix,",", cix)
                ans += 1

print(ans)


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

import bisect

L.sort()
# print(L)

ans = 0
for i in range(0, N-1):
    for j in range(i+1, N-1):
        ix = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, ix - j - 1)

print(ans)

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

ans = 0
for aix in range(N):
    for bix in range(aix, N):
        for cix in range(cix, N):
            if L[aix] < L[bix] + L[cix] and L[bix] < L[aix] + L[cix] and L[cix] < L[aix] + L[bix]:
                ans += 1

print(ans)


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

import bisect

L.sort()
# print(L)

ans = 0
for i in range(0, N-1):
    for j in range(i+1, N-1):
        ix = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, ix - j - 1)

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


def make_divisors(n):

    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1

    return lower_divisors + upper_divisors[::-1]


def gcd(a, b):

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


da = make_divisors(A)
common_divisors = []

for d in da:
    if B % d == 0:
        common_divisors.append(d)

cd = set(common_divisors)
lim = common_divisors[-1]
for i in common_divisors[1:]:
    a = 2
    cur = a * i
    while cur <= lim:
        if cur in cd:
            cd.remove(cur)
        a += 1
        cur = a * i

print(len(cd))
        



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

import math

def is_prime(x):
    for i in range(2, int(math.sqrt(x))+1):
        if x % i == 0:
            return False

    return True


def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1

    return lower_divisors + upper_divisors[::-1]


def gcd(a, b):

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


da = make_divisors(A)
common_divisors = []

for d in da:
    if B % d == 0:
        common_divisors.append(d)

ans = [1 if is_prime(x) else 0 for x in common_divisors]
print(sum(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
rint(int(((N-1) * N)/2))

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

Buggy python submission (verdict: Runtime Error):
print((N-1)/2 * N)

Fixed submission:
N = int(input())
print(((N-1) * N)//2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

import sys
from collections import Counter
d = Counter(A)

if d[0] == N:
    print("Yes")
    sys.exit()

if d[0] == N // 3:
    for x in d.keys():
        if d[x] == 2 * N // 3:
            print("Yes")
            sys.exit()

third = N // 3
if len(d.keys() == 3):
    a, b, c = d.keys()
    if d[a] == d[b] and d[b] == d[c]:
        if a ^ b ^ c == 0:
            print("Yes")
            sys.exit()

"""
# O(N^3)
third = N // 3
# print(third)
cand = list(filter(lambda x: d[x] == third, A))
# print(cand)
for ix1 in range(len(cand)):
    for ix2 in range(ix1 + 1, len(cand)):
        for ix3 in range(ix2 + 1, len(cand)):
            if cand[ix1] ^ cand[ix2] ^ cand[ix3] == 0:
                print("Yes")
                sys.exit()
"""
print("No")

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

import sys
from collections import Counter
d = Counter(A)

if d[0] == N:
    print("Yes")
    sys.exit()

if d[0] == N // 3:
    for x in d.keys():
        if d[x] == 2 * N // 3:
            print("Yes")
            sys.exit()

third = N // 3
if len(d.keys()) == 3:
    a, b, c = d.keys()
    if d[a] == d[b] and d[b] == d[c]:
        if a ^ b ^ c == 0:
            print("Yes")
            sys.exit()

print("No")

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

import sys
from collections import Counter
d = Counter(A)

if d[0] == N:
    print("Yes")
    sys.exit()

if d[0] == N // 3:
    for x in d.keys():
        if d[x] == 2 * N // 3:
            print("Yes")
            sys.exit()

# print(d)
third = N // 3
# print(third)
cand = list(filter(lambda x: d[x] == third, A))
# print(cand)
for ix1 in range(len(cand)):
    for ix2 in range(ix1 + 1, len(cand)):
        for ix3 in range(ix2 + 1, len(cand)):
            if cand[ix1] ^ cand[ix2] ^ cand[ix3] == 0:
                print("Yes")
                sys.exit()

print("No")

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

import sys
from collections import Counter
d = Counter(A)

if d[0] == N:
    print("Yes")
    sys.exit()

if d[0] == N // 3:
    for x in d.keys():
        if d[x] == 2 * N // 3:
            print("Yes")
            sys.exit()

third = N // 3
if len(d.keys()) == 3:
    a, b, c = d.keys()
    if d[a] == d[b] and d[b] == d[c]:
        if a ^ b ^ c == 0:
            print("Yes")
            sys.exit()

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

P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append((x, y))

from collections import defaultdict

cnt = defaultdict(int)
for pi in range(N):
    for pj in range(pi+1, N):
        if pi == pj:
            continue
        # x
        dx = abs(P[pi][0] - P[pj][0])

        # y
        dy = abs(P[pi][1] - P[pj][1])

        cnt[(dx, dy)] += 1

ans = N-max(cnt.values())
print(ans)



Fixed submission:
N = int(input())

P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append((x, y))

from collections import defaultdict

if N == 1:
    print(1)
    exit(0)

cnt = defaultdict(int)
for pi in range(N):
    for pj in range(N):
        if pi == pj:
            continue
        # x
        dx = P[pi][0] - P[pj][0]

        # y
        dy = P[pi][1] - P[pj][1]

        cnt[(dx, dy)] += 1

ans = N-max(cnt.values())
print(ans)
Buggy python submission (verdict: Runtime Error):
R,G,B,N = list(map(int, input().split()))

ans = 0
for r in range(N//R+1):
    for g in range(tmp//G+1):
        check = (tmp - R*r - G*g)
        if check%B == 0 and check > 0:
            ans += 1

print(ans)

Fixed submission:
R,G,B,N = list(map(int, input().split()))
ans=0
for r in range(N//R+1):
    x = N-R*r
    for g in range(x//G+1):
        if (x-G*g)%B==0:
            ans+=1
print(ans)

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

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        check = (N - (R*r + G*g))/B
        if float.is_integer(check) and check >= 0:
            ans += 1
        # if check >= 0 and check%B == 0:
            # ans += 1
        # if check == 0:
        #     # print(r, g, check//B, check)
        #     ans += 1
        # elif check > 0 and check%B == 0:
        #         # print(r, g, check//B, check)
        #         ans += 1

print(ans)

Fixed submission:
R,G,B,N = list(map(int, input().split()))
ans=0
for r in range(N//R+1):
    x = N-R*r
    for g in range(x//G+1):
        if (x-G*g)%B==0:
            ans+=1
print(ans)

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

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        check = N - (R*r + G*g)
        if check >= 0 and check%B == 0:
            ans += 1
        # if check == 0:
        #     # print(r, g, check//B, check)
        #     ans += 1
        # elif check > 0 and check%B == 0:
        #         # print(r, g, check//B, check)
        #         ans += 1

print(ans)

Fixed submission:
R,G,B,N = list(map(int, input().split()))
ans=0
for r in range(N//R+1):
    x = N-R*r
    for g in range(x//G+1):
        if (x-G*g)%B==0:
            ans+=1
print(ans)

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

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        check = N - (R*r + G*g)
        if check == 0:
            # print(r, g, check//B, check)
            ans += 1
        elif check > 0 and check%B == 0:
                # print(r, g, check//B, check)
                ans += 1

print(ans)

Fixed submission:
R,G,B,N = list(map(int, input().split()))
ans=0
for r in range(N//R+1):
    x = N-R*r
    for g in range(x//G+1):
        if (x-G*g)%B==0:
            ans+=1
print(ans)

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

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        check = N - (R*r + G*g)
        if check == 0:
            # print(r, g, check//B, check)
            ans += 1
        elif check > 0:
            if check%B == 0:
                # print(r, g, check//B, check)
                ans += 1

print(ans)

Fixed submission:
R,G,B,N = list(map(int, input().split()))
ans=0
for r in range(N//R+1):
    x = N-R*r
    for g in range(x//G+1):
        if (x-G*g)%B==0:
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

"""
7<=|S|<=100
c ∈ {[a-z]}

keyaaence
keyence
"""

ref = "keyence"

if S == ref:
    print("YES")
    exit(0)

ri = 0
ci = 0

missmatch=[]

while ci < len(S):
    if ref[ri] == S[ci] and ri <= len(ref)-1:
        # match
        ri+=1
    else:
        missmatch.append(ci)

    ci += 1
if ri != len(ref):
    print("NO")
    exit(0)

ok = True
for i in range(len(missmatch)-1):
    if missmatch[i] + 1 != missmatch[i+1]:
        ok = False
# print(missmatch)
if ok:
    print("YES")
else:
    print("NO")


Fixed submission:
S = input()

def range_strip(S, i, j):
    return S[:i] + S[j:]

for i in range(len(S)):
    for j in range(i, len(S)):
        if range_strip(S,i,j) == "keyence":
            print("YES")
            exit(0)
print("NO")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()
T = input()

import sys

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

g = gcd(N, M)
sn = N/g
sm = M/g

ok = True
for k in range(0, g):
    a = k * sn
    b = k * sm
    if S[a] != T[b]:
        ok = False
        break

if ok:
    print(N*M/g)
else:
    print(-1)

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

import sys

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


g = gcd(N, M)
sn = N//g
sm = M//g

ok = True
for k in range(0, g):
    a = k * sn
    b = k * sm
    if S[a] != T[b]:
        ok = False
        break

if ok:
    print(N*M//g)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
from math import sqrt
N, M = map(int, input().split())

cand = []

for i in range(2, int(sqrt(M))+1):
    if M % i == 0:
        cand.append(i)
        cand.append(M//i)

cand.sort()

for j in cand:
    if N * j <= M:
        ans = j

print(ans)

Fixed submission:
from math import sqrt
N, M = map(int, input().split())

cand = []

for i in range(1, int(sqrt(M))+1):
    if M % i == 0:
        cand.append(i)
        u = M // i
        if u != i:
            cand.append(u)

cand.sort()

ans = 1
for j in cand:
    if N * j <= M:
        ans = max(ans, j)

print(ans)