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

n = int(input())
A = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    A2 = A.copy()
    del A2[i]
    x = A2[0]
    for i in range(1, n - 1):
        x = math.gcd(x, A2[i])
    ans = max(ans, x)
    
print(ans)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

B = A.copy()
for i in range(N - 1):
    B[i + 1] = gcd(B[i], B[i + 1])

C = A.copy()
C.reverse()
for i in range(N - 1):
    C[i + 1] = gcd(C[i], C[i + 1])
C.reverse()

ans = 0
for i in range(N):
    if i == 0:
        tmp = C[i + 1]
    elif i == N - 1:
        tmp = B[i - 1]
    else:
        tmp = gcd(B[i - 1], C[i + 1])
    ans = max(ans, tmp)
    
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

if N == 2:
    print(max(A))

else:
    if gcd(A[0], A[1]) > gcd(A[1], A[2]):
        x = 2
    elif gcd(A[0], A[1]) < gcd(A[1], A[2]):
        x = 0
    elif gcd(A[0], A[2]) > gcd(A[1], A[2]):
        x = 1
    elif gcd(A[0], A[2]) < gcd(A[1], A[2]):
        x = 0
    else:
        A2 = A.copy()
        for i in range(2, N - 1):
            A2[i + 1] = gcd(A2[i], A2[i + 1])
            if A2[i] > A2[i + 1]:
                x = i + 1
                break

    del A[x]
    for i in range(N - 2):
        A[i + 1] = gcd(A[i], A[i + 1])
    print(A[-1])

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

B = A.copy()
for i in range(N - 1):
    B[i + 1] = gcd(B[i], B[i + 1])

C = A.copy()
C.reverse()
for i in range(N - 1):
    C[i + 1] = gcd(C[i], C[i + 1])
C.reverse()

ans = 0
for i in range(N):
    if i == 0:
        tmp = C[i + 1]
    elif i == N - 1:
        tmp = B[i - 1]
    else:
        tmp = gcd(B[i - 1], C[i + 1])
    ans = max(ans, tmp)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()

one = []
cnt = 0
for i, s in enumerate(S):
    if s == '1':
        cnt += 1
        if i == N - 1:
            one.append(cnt)
    elif s == '0':
        if cnt > 0:
            one.append(cnt)
            cnt = 0
            
zero = []
cnt = 0
for i, s in enumerate(S):
    if s == '0':
        cnt += 1
        if i == N - 1:
            zero.append(cnt)
    elif s == '1':
        if cnt > 0:
            zero.append(cnt)
            cnt = 0
            
if len(one) <= len(zero):
    one = [0] + one + [0]
    
for i in range(len(one) - 1):
    one[i + 1] = one[i] + one[i + 1]
one = [0] + one
    
for i in range(len(zero) - 1):
    zero[i + 1] = zero[i] + zero[i + 1]
zero = [0] + zero
    
ans = -1
for i in range(len(one) - (K + 1) + 1):
    tmp = one[i + K] - one[i - 1] + zero[i + K - 1] - zero[i - 1]
    ans = max(ans, tmp)
    # print(tmp)
    
if len(zero) - 1 <= K:
    print(len(S))
else:
    print(ans)

Fixed submission:
N,K = map(int,input().split())
S = input()
 
zeros = []
ones = [0]
# Sが0始まりの時は、それを挟むための1が必要なので、予め入れておく
# 1始まりの時は、これに+= 1するので問題なし
 
prev = '1'
for c in S:
    if c == '1':
        if prev == '0':
            ones.append(1)
        else:
            ones[-1] += 1
    else: #c == '0'
        if prev == '1':
            zeros.append(1)
        else:
            zeros[-1] += 1
    prev = c
ones.append(0)
# Sが0終わりの時は、それを挟むための1が必要なので、最後に付け加えておく
# 1終わりの時は不要だが、maxをとるので0を入れておいても影響はない

tmp = sum(zeros[0:K]) + sum(ones[0:K+1])
#　初期値として、最初の区間の和を計算しておけば、
# あとは先頭と最後尾を+-するだけで累積和を求められる
ans = tmp
for i in range(0,len(zeros)-K):
    tmp += zeros[i+K] - zeros[i] + ones[i+K+1] - ones[i]
    ans = max(tmp,ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
A = []
B = []
for i in range(5):
    x = input()
    if int(x[-1]) != 0:
        A.append(10 - int(x[-1]))
    B.append(int(x))

print(sum(A) + sum(B) - max(A))

Fixed submission:
A = []
B = []
for i in range(5):
    x = input()
    if int(x[-1]) != 0:
        A.append(10 - int(x[-1]))
    B.append(int(x))

if A == []:
    print(sum(A) + sum(B))
else:
    print(sum(A) + sum(B) - max(A))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
s = input()
A = [1] * (N + 2)

for i in range(Q):
    t, d = input().split()
    for i, x in enumerate(s):
        if t == x:
            if d == 'L':
                A[i] += A[i + 1]
                A[i + 1] = 0
            else:
                A[i + 2] += A[i + 1]
                A[i + 1] = 0
                
print(sum(A[1 : -1]))

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

X = []
for i in range(Q):
    t, d = input().split()
    if d == 'L':
        X.append([t, -1])
    else:
        X.append([t, 1])
        
def check(m):
    i = m
    for x in X:
        if x[0] == s[i]:
            i += x[1]
            if i < 0:
                return -1
            if i >= N:
                return 1
    return 0

L, R = -1, N
while R - L > 1:
    M = (L + R) // 2
    if check(M) < 0:
        L = M
    else:
        R = M  
A = L

L, R = -1, N
while R - L > 1:
    M = (L + R) // 2
    if check(M) > 0:
        R = M
    else:
        L = M
B = R

print(B - A - 1)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()

A = []
for i in range(Q):
    l, r = map(int, input().split())
    A.append(S[l - 1 : r])
    
for a in A:
    print(a.count('AC'))

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

dp = [0] * (N + 1)
for i in range(N):
    if S[i : i + 2] == 'AC':
        dp[i + 1] += 1
        
for i in range(1, N + 1):
    dp[i] += dp[i - 1]
    
for i in range(Q):
    l, r = map(int, input().split())
    print(dp[r - 1] - dp[l - 1])

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

for i in range(Q):
    l, r = map(int, input().split())
    print(S[l - 1 : r].count('AC'))

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

dp = [0] * (N + 1)
for i in range(N):
    if S[i : i + 2] == 'AC':
        dp[i + 1] += 1
        
for i in range(1, N + 1):
    dp[i] += dp[i - 1]
    
for i in range(Q):
    l, r = map(int, input().split())
    print(dp[r - 1] - dp[l - 1])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
mod = 10 ** 9 + 7
n = int(input())
C = [int(input()) for i in range(n)]

for i in range(n - 1, 0, -1):
    if C[i] == C[i - 1]:
        del C[i]

D = [0] * n
for i in range(2, n):
    D[i] = D[i - 1] + i - 1
        
ans = 1
for i in Counter(C).values():
    ans += D[i]
    
print(ans % mod)

Fixed submission:
from collections import defaultdict
 
mod = 10 ** 9 + 7
n = int(input())
C = [int(input()) for i in range(n)]
 
for i in range(n - 1, 0, -1):
    if C[i] == C[i - 1]:
        del C[i]
        #重複部分を圧縮したCを作成
        
D = defaultdict(int)
ans = 1
for c in C:
    ans += D[c]
    D[c] = ans
    #print(D, ans)

print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
ans = a
for i in range(a + 1, b + 1):
    ans ^= i
    
print(ans)

Fixed submission:
a, b = map(int,input().split())
 
def f(n) :
    if n % 4 == 0 :
        return n
    elif n % 4 == 1 :
        return 1
    elif n % 4 == 2 :
        return n + 1
    else :
        return 0

print(f(a - 1) ^ f(b))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
a, b, q = map(int, input().split())
inf = float('inf')
S = [- inf] + [int(input()) for i in range(a)] + [inf]
T = [- inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
    x = int(input())
    s_idx = bisect.bisect_left(S, x)
    s1, s2 = S[s_idx - 1], S[s_idx]
    
    t_idx = bisect.bisect_left(T, x)
    t1, t2 = T[t_idx - 1], T[t_idx]
    
    ans = inf
    for i in s1, s2, t1, t2:
        for j in s1, s2, t1, t2:
            if i != j:
                tmp = abs(x - i) + abs(i - j)
                ans = min(ans, tmp)
                
    print(ans)

Fixed submission:
import bisect
 
a, b, q = map(int, input().split())
INF = 10 ** 12
S = [-INF] + [int(input()) for i in range(a)] + [INF]
T = [-INF] + [int(input()) for i in range(b)] + [INF]

for i in range(q):
    x = int(input())
    sid = bisect.bisect_left(S, x)
    tid = bisect.bisect_left(T, x)
    ans = INF
    for s in (S[sid - 1], S[sid]):
        for t in (T[tid - 1], T[tid]):
            ans = min(ans, abs(x - s) +abs(s - t))
            ans = min(ans, abs(x - t) + abs(t - s))
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]
while True:
    if len(A) == 1:
        print(A[0])
        break
    A[A.index(max(A))] %= min(A)
    if 0 in A:
        A.remove(0)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

for i in range(n - 1):
    A[i + 1] = gcd(A[i], A[i + 1])
    
print(A[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]
while True:
    if len(A) == 1:
        print(A[0])
        break
    A[A.index(max(A))] %= min(A)
    A = list(set(A))
    if 0 in A:
        A.remove(0)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

for i in range(n - 1):
    A[i + 1] = gcd(A[i], A[i + 1])
    
print(A[-1])
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = [int(i) for i in input().split()]

tmp = 0
for i in range(n):
    tmp += int(bin(A[i])[2:])
    
cand = ''
for i in str(tmp):
    if int(i) >= n / 2:
        cand += '0'
    else:
        cand += '1'
        
if int(cand, 2) > k:
    cand = str(k)
else:
    while True:
        cand = '1' + cand
        if int(cand, 2) <= k:
            pass
        else:
            cand = cand[1:]
            break
    
ans = 0
for i in range(n):
    ans += int(cand, 2) ^ A[i]
    
print(ans)

Fixed submission:
N, K = map(int, input().split())
Ai = list(map(int, input().split()))
 
D = 40
Bi = []
for a in Ai:
    b = bin(a)[2:]
    b = ("0" * (D - len(b))) + b
    Bi.append(b)
 
result = ""
for i in range(D):
    count = 0 # 1の個数
    for i, b in enumerate(Bi):
        if b[0] == '1':
            count += 1
        Bi[i] = b[1:]
    if count >= N / 2:
        result += "0"
    else:
        result += "1"
    #count = count // 2
x = 0
for i in range(D):
    if result[0] == '1':
        a = pow(2, D - i - 1)
        if x + a <= K:
            x += a
    result = result[1:]
 
ans = 0
for a in Ai:
    ans += (a ^ x)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def f1(x):
    A = []
    if x == 0:
        return 0
    while x > 0:
        A.append(str(x % 2))
        x //= 2
    A.reverse()
    return ''.join(A)

def f2(x, a):
    bx = int(f1(x))
    ba = int(f1(a))
    xor = str(bx + ba).replace('2', '0')
    ans = 0
    for i in range(len(xor) - 1, -1, -1):
        ans += int(xor[::-1][i]) * 2 ** i
    return ans

n, k = map(int, input().split())
A = [int(i) for i in input().split()]

ans = 0
for i in range(k + 1):
    tmp = 0
    for j in range(n):
        tmp += f2(i, A[j])
    ans = max(ans, tmp)
    
print(ans)

Fixed submission:
N, K = map(int, input().split())
Ai = list(map(int, input().split()))
 
D = 40
Bi = []
for a in Ai:
    b = bin(a)[2:]
    b = ("0" * (D - len(b))) + b
    Bi.append(b)
 
result = ""
for i in range(D):
    count = 0 # 1の個数
    for i, b in enumerate(Bi):
        if b[0] == '1':
            count += 1
        Bi[i] = b[1:]
    if count >= N / 2:
        result += "0"
    else:
        result += "1"
    #count = count // 2
x = 0
for i in range(D):
    if result[0] == '1':
        a = pow(2, D - i - 1)
        if x + a <= K:
            x += a
    result = result[1:]
 
ans = 0
for a in Ai:
    ans += (a ^ x)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
INF = float('inf')
dp = [INF] * n

dp[0] = 0
for i in range(1, N):
    for k in range(1, K + 1):
        start = max(i - k, 0)
        dp[i] = min(dp[i], dp[start] + abs(A[i] - A[start]))
    
print(dp[-1])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
H = np.array(list(map(int, input().split())))
dp = np.zeros(n, dtype = int)

for i in range(1, n):
    s = max(i - k, 0)
    dp[i] = min(dp[s : i] + abs(H[i] - H[s : i]))
    
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = [int(i) for i in input().split()]

inf = float('inf')
dp = [inf] * N
dp[0] = 0

for i in range(1, N):
    for k in range(1, K + 1):
        dp[i] = min(dp[i], dp[i - k] + abs(H[i] - H[i - k]))
    
print(dp[-1])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
H = np.array(list(map(int, input().split())))
dp = np.zeros(n, dtype = int)

for i in range(1, n):
    s = max(i - k, 0)
    dp[i] = min(dp[s : i] + abs(H[i] - H[s : i]))
    
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if k > n:
    k = n
A = [int(i) for i in input().split()]
INF = 10 ** 12
dp = [INF] * n

dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))
    
print(dp[-1])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
H = np.array(list(map(int, input().split())))
dp = np.zeros(n, dtype = int)

for i in range(1, n):
    s = max(i - k, 0)
    dp[i] = min(dp[s : i] + abs(H[i] - H[s : i]))
    
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if k > n:
    k = n
A = [int(i) for i in input().split()]
INF = 10 ** 12
dp = [INF] * n

dp[0] = 0
for i in range(1, n):
    for j in range(k + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))
    
print(dp[-1])

Fixed submission:
import numpy as np

n, k = map(int, input().split())
H = np.array(list(map(int, input().split())))
dp = np.zeros(n, dtype = int)

for i in range(1, n):
    s = max(i - k, 0)
    dp[i] = min(dp[s : i] + abs(H[i] - H[s : i]))
    
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 8)

N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)
    
dp = [[-1] *(W + 1) for i in range(N + 1)]
    
def dfs(i, W):
    if dp[i][W] != -1:
        return dp[i][W]
    if i == N:
        ans = 0
    elif w[i] > W:
        ans = dfs(i + 1, W)
    else:
        ans = max(dfs(i + 1, W), dfs(i + 1, W - w[i]) + v[i])
    dp[i][W] = ans
    return ans

print(dfs(0, W))

Fixed submission:
N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)
    
dp = [[0] *(W + 1) for i in range(N + 1)]

for i in range(N):
    for j in range(W + 1):
        if j < w[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])
            
print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
        
G = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    
dp = [-1] * (N)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    
    res = 0
    for g in G[v]:
        res = max(res, dfs(g) + 1)
        
    dp[v] = res
    return res

ans = 0
for i in range(N):
    ans = max(ans, dfs(i))
        
print(ans)

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

N, M = map(int, input().split())
        
G = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    
dp = [-1] * (N)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    
    res = 0
    for g in G[v]:
        res = max(res, dfs(g) + 1)
        
    dp[v] = res
    return res

ans = 0
for i in range(N):
    ans = max(ans, dfs(i))
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, p = map(int, input().split())

p2 = int(p ** (1 / n))

for i in range(p2 + 1, 0, -1):
    if p % (i ** n) == 0:
        print(i)
        break

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

p2 = round(p ** (1 / n))

for i in range(p2, 0, -1):
    if p % (i ** n) == 0:
        print(i)
        break

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

p2 = int(p ** (1 / n)) + 1

for i in range(p2, 0, -1):
    if p % (i ** n) == 0:
        print(i)
        break

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

p2 = round(p ** (1 / n))

for i in range(p2, 0, -1):
    if p % (i ** n) == 0:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
count = 0
flag = 1

while flag == 1:
    flag = 0
    for i in range(len(S)-1):
        if S[i] == 'B' and S[i+1] == 'W':
            S[i], S[i+1] = S[i+1], S[i]
            count += 1
            flag = 1
        
print(count)

Fixed submission:
S = list(input())
posi = 0
count = 0

for i in range(len(S)):
    if S[i] == 'W':
        count += i - posi
        posi += 1

print(count)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = []
D = []

for i in range(n):
    A.append(int(input()))

A.sort(reverse=True)
    
for i in range(k):
    diff = A[i] - A[i + k -1]
    D.append(diff)
    
print(min(D))

Fixed submission:
n, k = map(int, input().split())
hs = []
diff = []

for i in range(n):
    h = int(input())
    hs.append(h)

hs.sort()

for i in range(n - k + 1):
    diff.append(hs[i + k - 1] - hs[i])
    
print(min(diff))
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
ans = 'p'

for i in range(n):
    ans = 'b{}p{}b'.format(ans, ans)

print(ans[-x:].count('p'))

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

a, p = [1], [1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)
    
def f(n, x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])
    
print(f(n, x))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())/2
print(a+b)

Fixed submission:
a, b = map(int, input().split())
print(int(a + b/2))
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10 ** 9 + 7
h, w, k = map(int, input().split())

def dfs(i, j):
    cnt = 0
    if i == h + 1:
        if j == k:
            return 1
        else:
            return 0
    if j == 1:
        cnt += dfs(i + 1, j) 
        cnt += dfs(i + 1, j + 1)
    elif j == w:
        cnt +=  dfs(i + 1, j) 
        cnt += dfs(i + 1, j - 1)
    else:
        cnt += dfs(i + 1, j)
        cnt += dfs(i + 1, j + 1) 
        cnt += dfs(i + 1, j - 1)        
    return cnt

if w == 1:
    print(1)
else:
    print(dfs(0, 0) % mod)

Fixed submission:
mod = 10 ** 9 + 7
H, W, K = map(int, input().split())
dp = [[0] * W for i in range(H + 1)]

dp[0][0] = 1
for i in range(H):
    for j in range(W):
        for k in range(1 << (W - 1)):
            ok = True
            if '11' in bin(k):
                ok = False
            if ok:
                if j >= 1 and ((k >> (j - 1)) & 1):
                    dp[i + 1][j - 1] += dp[i][j]
                    dp[i + 1][j - 1] %= mod
                    #print(1, i, bin(k), j, dp)
                    
                elif j <= W -2 and ((k >> j) & 1):
                    dp[i + 1][j + 1] += dp[i][j]
                    dp[i + 1][j + 1] %= mod
                    #print(2, i, bin(k), j, dp)
                    
                else:
                    dp[i + 1][j] += dp[i][j]
                    dp[i + 1][j] %= mod
                    #print(3, i, bin(k), j, dp)
            
print(dp[H][K - 1])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
S = input()
T = input()

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

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

l = lcm(n, m)
memoS = [0] * (l + 1)
memoT = [0] * (l + 1)

numS = [1]
numT = [1]

for i in range(1, n):
    num = i * l // n + 1
    numS.append(num)

for i in range(1, m):
    num = i * l // m + 1
    numT.append(num)
    
dictS = {}
dictT = {}

for i in range(n):
    dictS[numS[i]] = S[i]
    memoS[numS[i]] = 3

for i in range(m):
    dictT[numT[i]] = T[i]
    memoT[numT[i]] = 1

ans = l
for i in range(l):
    if memoS[i] - memoT[i] == 2:
        if dictS[i] != dictT[i]:
            ans = -1
            break
                
print(ans)

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)

n, m = map(int, input().split())
S = input()
T = input()

l = lcm(n, m)
        
if S[::n // gcd(n, m)] == T[::m // gcd(n, m)]:
    print(l)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
S = input()
T = input()

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

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

l = lcm(n, m)
numS = [1]
numT = [1]

for i in range(1, n):
    num = i * l // n + 1
    numS.append(num)

for i in range(1, m):
    num = i * l // m + 1
    numT.append(num)
    
dictS = {}
dictT = {}

for i in range(n):
    dictS[numS[i]] = S[i]

for i in range(m):
    dictT[numT[i]] = T[i]
    
ans = l
for i in dictS:
    for j in dictT:
        if i == j:
            if dictS[i] != dictT[j]:
                ans = -1
                
print(ans)

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)

n, m = map(int, input().split())
S = input()
T = input()

l = lcm(n, m)
        
if S[::n // gcd(n, m)] == T[::m // gcd(n, m)]:
    print(l)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

ans = 0
for i in range(1, m//n+1):
    if m % i == 0:
        ans = max(ans, i)
        if m // i > i and m // i <= m // n:
            ans = max(ans, m // i)
            
print(ans)

Fixed submission:
n, m = map(int, input().split())
a = m // n
ans = 0

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = m // n

for i in range(a, 0, -1):
    if m % i == 0:
        ans = i
        break
        
print(ans)

Fixed submission:
n, m = map(int, input().split())
a = m // n
ans = 0

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = m // n

for i in range(2, a + 1):
    if m % i == 0:
        ans = i
        
print(ans)

Fixed submission:
n, m = map(int, input().split())
a = m // n
ans = 0

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
a = M // N
x = 1

for i in range(1, a + 1):
    if M % i == 0:
        x = i

print(x)

Fixed submission:
n, m = map(int, input().split())
a = m // n
ans = 0

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)