Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]
#print(S)
dpyoko = [[1]*(W) for i in range(H)]
for j in range(W):
    for i in range(H):
        if S[i][j] == '#':
            dpyoko[i][j] = 0
        else:
            if j != 0:
                dpyoko[i][j] += dpyoko[i][j-1]
dptate = [[1]*(W) for i in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            dptate[i][j] = 0
        else:
            if i != 0:
                dptate[i][j] += dptate[i-1][j]
#print(dpyoko)
#print(dptate)
for j in range(W-1,-1,-1):
    for i in range(H):
        if dpyoko[i][j] == 0:
            continue
        if j == W-1:
            continue
        dpyoko[i][j] = max(dpyoko[i][j],dpyoko[i][j+1])
#print(dpyoko)
for i in range(H-1,-1,-1):
    for j in range(W):
        if dptate[i][j] == 0:
            continue
        if i == H-1:
            continue
        dptate[i][j] = max(dptate[i][j],dptate[i+1][j])
#print(dptate)
dp = [[0]*(W) for i in range(H)]
res = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        dp[i][j] = dptate[i][j]+dpyoko[i][j]-1 
        if res < dp[i][j]:
            res = dp[i][j]
print(res)       


Fixed submission:
H,W = map(int,input().split())
S = [list(input()) for i in range(H)]
#print(S)
dpyoko = [[1]*(W) for i in range(H)]
for j in range(W):
    for i in range(H):
        if S[i][j] == '#':
            dpyoko[i][j] = 0
        else:
            if j != 0:
                dpyoko[i][j] += dpyoko[i][j-1]
dptate = [[1]*(W) for i in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            dptate[i][j] = 0
        else:
            if i != 0:
                dptate[i][j] += dptate[i-1][j]
for j in range(W-1,-1,-1):
    for i in range(H):
        if dpyoko[i][j] == 0:
            continue
        if j == W-1:
            continue
        dpyoko[i][j] = max(dpyoko[i][j],dpyoko[i][j+1])
for i in range(H-1,-1,-1):
    for j in range(W):
        if dptate[i][j] == 0:
            continue
        if i == H-1:
            continue
        dptate[i][j] = max(dptate[i][j],dptate[i+1][j])
dp = [[0]*(W) for i in range(H)]
res = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        dp[i][j] = dptate[i][j]+dpyoko[i][j]-1 
        if res < dp[i][j]:
            res = dp[i][j]
print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
SPN = []
for i in range(n):
    s,p = input().split()
    SPN.append([s,int(p),i+1])
SPN = sorted(sorted(SPN, key=lambda x:x[1], reverse=1), lambda x:x[0])
for s,p,n in SPN:
    print(n)


Fixed submission:
n = int(input())
SQ  = []
for i in range(n):
    s,q = input().split()
    SQ.append([s,q,i+1])
SQ.append(['zzzzzzzzzzzzzz',0,i+2])
X = sorted(SQ)
res = []
city = X[0][0]
for i in range(n+1):
    if X[i][0] == city:
        res.append([int(X[i][1]),X[i][2]])
    else:
        res.sort(reverse=True)
        for r in res:
            print(r[1])
        res = [[int(X[i][1]),X[i][2]]]
        city = X[i][0]
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
Q = []
m = min(n,k)
res = 0
for i in range(m+1):
    for j in range(m-i+1):
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for k in range(min(i+j+1,m-i-j)):
            if Q[k] < 0:
                s -= Q[k]   
        res = max(res,s)
        Q = []
print(res)

Fixed submission:
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
Q = []
m = min(n,k)
res = []
for i in range(m+1):
    for j in range(m-i+1):
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for p in range(min(len(Q),k-len(Q))):
            if Q[p] < 0:
                s -= Q[p]   
        res.append(s)
        Q = []
print(max(res))

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
Q = []
m = min(n,k)
res = 0
for i in range(m+1):
    for j in range(m-i+1):
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for k in range(min(i+j+1,m-i-j+1)):
            if Q[k] < 0:
                s -= Q[k]   
        res = max(res,s)
        Q = []
print(res)

Fixed submission:
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
Q = []
m = min(n,k)
res = []
for i in range(m+1):
    for j in range(m-i+1):
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for p in range(min(len(Q),k-len(Q))):
            if Q[p] < 0:
                s -= Q[p]   
        res.append(s)
        Q = []
print(max(res))
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = [[] for i in range(n)]
for i in range(n-1):
	a,b,x = map(int,input().split())
	a -= 1
	b -= 1
	x = x%2
	d[a].append([b,x])
	d[b].append([a,x])
color = [0]*n
used = set()
def dfs(v):
	for e,l in d[v]:
		if e not in used:
			used.add(e)
			if l == 1:
				color[e] = 1
			dfs(e)
dfs(0)
for c in color:
	print(c)

Fixed submission:
n = int(input())
edges = [set() for _ in range(n)]
for i in range(n-1):
    u,v,w = [int(i)-1 for i in input().split()] 
    edges[u].add((v,w+1))
    edges[v].add((u,w+1))
ans = [-1]*n
q = [(0,0,-1)]
while q:
    v,d,p = q.pop()
    if d%2 == 0:
        ans[v] = 0
    else:
        ans[v] = 1
    for u,w in edges[v]:
        if u == p:
            continue
        q.append((u,d+w,v))
for i in range(n):
    print(ans[i])

Buggy python submission (verdict: Runtime Error):
n = int(input())
d = [[] for i in range(n)]
for i in range(n-1):
	a,b,x = map(int,input().split())
	a -= 1
	b -= 1
	x = x%2
	d[a].append([b,x])
	d[b].append([a,x])
print(d)
color = [0]*n
used = set()
def dfs(v):
	for e,l in d[v]:
		#print(e)
		if e not in used:
			used.add(e)
			if l == 1:
				color[e] = 1
			dfs(e)
dfs(0)
for c in color:
	print(c)

Fixed submission:
n = int(input())
edges = [set() for _ in range(n)]
for i in range(n-1):
    u,v,w = [int(i)-1 for i in input().split()] 
    edges[u].add((v,w+1))
    edges[v].add((u,w+1))
ans = [-1]*n
q = [(0,0,-1)]
while q:
    v,d,p = q.pop()
    if d%2 == 0:
        ans[v] = 0
    else:
        ans[v] = 1
    for u,w in edges[v]:
        if u == p:
            continue
        q.append((u,d+w,v))
for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]

class UnionFind:
    def __init__(self,N):
        self.root = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
    def root(self,a):
        if self.root[a] == a:
            return a
        else:
            self.root[a] = self.root(self.root[a])
            return self.root[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.root[ra] = rb
        else:
            self.root[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

uf = UnionFind(N)
for x,y,z in src:
    x,y = x-1,y-1
    uf.unite(x,y)
print(N - uf.count)


Fixed submission:
def find(x):
    if root[x] == x:
        return x
    else:
        root[x] = find(root[x])
        return root[x]

def same(x,y):
    return find(x) == find(y)

def unite(x,y):
    x = find(x)
    y = find(y)
    if rank[x] == rank[y]:
        root[y] = x
        rank[x] += 1
    elif rank[x] > rank[y]:
        root[y] = x
    elif rank[x] < rank[y]:
        root[x] = y
    
n,m = map(int, input().split())
root = [i for i in range(n)]
rank = [0 for i in range(n)]

for i in range(m):
    x, y, z = [int(i)-1 for i in input().split()]
    if not same(x,y):
        unite(x,y)
    
for i in range(n):
    find(i)

print(len(list(set(root))))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n = int(input())
A = list(map(int,input().split()))
res = 0
for i in range(n):
    B = A[:i]+A[i+1:]
    GCD = B[0]
    for b in B:
        GCD = gcd(GCD,b)
    if res < GCD:
        res = GCD
print(res)

Fixed submission:
from fractions import gcd
n = int(input())
A = list(map(int,input().split()))
X = [0 for i in range(n)]
Y = [0 for i in range(n)]
for i in range(1,n):
    X[i] = gcd(X[i-1],A[i-1])
for i in range(n-1)[::-1]:
    Y[i] = gcd(Y[i+1],A[i+1])
#print(X)
#print(Y)
Z = [gcd(X[i],Y[i]) for i in range(n)]
print(max(Z))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

n,k = map(int,input().split())
S = input()+'!'

get = [0]
tmp = 1
for i in range(1,n+1):
    if S[i] == S[i-1]:
        tmp += 1
    else:
        get.append(tmp)
        tmp = 1

get = get + [0]

for i in range(1,len(get)):
    get[i] += get[i-1]

res = 0
if S[0] == '0':
    for i in range(len(get)-2*k):
        if i%2 == 0:
            ans = get[i+2*k]-get[i]
        else:
            ans = get[min(i+2*k+1,len(get))]-get[i]
        if res <= ans:
            res = ans
else:
    for i in range(len(get)-2*k):
        if i%2 == 0:
            ans = get[min(len(get),i+2*k+1)]-get[i]
        else:
            ans = get[i+2*k]-get[i]
        if res <= ans:
            res = ans

print(res)

Fixed submission:
n,k = map(int,input().split())
S = input()+'!'
A = [0]
tmp = 1
for i in range(1,n+1):
    if S[i] == S[i-1]:
        tmp += 1
    else:
        A.append(tmp)
        tmp = 1
for i in range(1,len(A)):
    A[i] += A[i-1]
#print(A)
res = 0
if S[0] == '0':
    for i in range(len(A)):
        if i%2 == 0:
            ans = A[min(i+2*k,len(A)-1)]-A[i]
        else:
            ans = A[min(i+2*k+1,len(A)-1)]-A[i]
        if res <= ans:
            res = ans
else:
    for i in range(len(A)):
        if i%2 == 0:
            ans = A[min(len(A)-1,i+2*k+1)]-A[i]
        else:
            ans = A[min(i+2*k,len(A)-1)]-A[i]
        if res <= ans:
            res = ans

print(res)
Buggy python submission (verdict: Runtime Error):
A = [input() for i in range(5)]
k = int(input())
if A[-1]-A[0] <= k:
	print('Yay!')
else:
	print(':(')
	

Fixed submission:
A = [int(input()) for i in range(5)]
A.sort()
k = int(input())
if A[-1]-A[0] <= k:
	print("Yay!")
else:
	print(":(")
Buggy python submission (verdict: Runtime Error):
import math,itertools,fractions,heapq,collections,re,bisect,sys,functools

sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
dy = [-1,0,1,0]
dx = [0,1,0,-1]
ddy = [-1,-1,0,1,1,1,0,-1]
ddx = [0,1,1,1,0,-1,-1,-1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

#######################################################################

x,y,z,k = LI()
A = sorted(LI(),reverse=True)
B = sorted(LI(),reverse=True)
C = sorted(LI(),reverse=True)

ab = []
for a in A:
    for b in B:
            ab.append(a+b)
ab.sort(reverse=True)
res = []
for i in range(k):
    for c in C:
        res.append(ab[i]+c)
res.sort(reverse=True)

for i in range(k):
    print(res[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()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
res = []
for p in range(x):
	for q in range(y):
		if (p+1)*(q+1) > k:
			break
		for r in range(z):
			if (p+1)*(q+1)*(r+1) > k:
				break
			res.append(A[p]+B[q]+C[r])
res.sort(reverse=True)
for i in res[:k]:
	print(i)
Buggy python submission (verdict: Runtime Error):
S = input()
X = 'ATCG'
res = []
cnt = 0
for s in S:
    if s in X:
        cnt += 1
        res.append(cnt)
    else:
        cnt = 0
print(max(res))

Fixed submission:
S = input()+'Z'
X = 'ATCG'
res = [0]
count = 0
for i in S:
    if i in X:
        count += 1
    else:
        res.append(count)
        count = 0
print(max(res))

Buggy python submission (verdict: Runtime Error):
S = input()
A = ['A','T','C','G']
res = []
count = 0
for i in S:
    if i in A:
        count += 1
    else:
        res.append(count)
        count = 0
print(max(res))


Fixed submission:
S = input()+'Z'
X = 'ATCG'
res = [0]
count = 0
for i in S:
    if i in X:
        count += 1
    else:
        res.append(count)
        count = 0
print(max(res))
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n+1):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
SUM = [0]*(10**5+1)
for i in range(1,n+1):
    SUM[i] += SUM[i-1]+N[i]
for i in range(q):
    l,r = map(int,input().split())
    print(SUM[r-1]-SUM[l-1])

Fixed submission:
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
SUM = [0]*(10**5+1)
for i in range(1,n):
    SUM[i] += SUM[i-1]+N[i]
for i in range(q):
    l,r = map(int,input().split())
    print(SUM[r-1]-SUM[l-1])

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n+1):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
for i in range(q):
    l,r = map(int,input().split())
    print(sum(N[:r])-sum(N[:l]))

Fixed submission:
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
SUM = [0]*(10**5+1)
for i in range(1,n):
    SUM[i] += SUM[i-1]+N[i]
for i in range(q):
    l,r = map(int,input().split())
    print(SUM[r-1]-SUM[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())
    A = S[:l].count('AC')
    B = S[:r].count('AC')
    print(B-A)


Fixed submission:
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
SUM = [0]*(10**5+1)
for i in range(1,n):
    SUM[i] += SUM[i-1]+N[i]
for i in range(q):
    l,r = map(int,input().split())
    print(SUM[r-1]-SUM[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())
    A = S[l-1:r]
    print(A.count('AC'))

Fixed submission:
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
SUM = [0]*(10**5+1)
for i in range(1,n):
    SUM[i] += SUM[i-1]+N[i]
for i in range(q):
    l,r = map(int,input().split())
    print(SUM[r-1]-SUM[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
n = N
B = list(map(int,input().split()))
B = B[::-1]
A = []
flag = 0
while N > 0:
    for m,b in enumerate(B):
        if (N-m == b):
            A.append(b)
            B.pop(m)
            flag = 1
            N -= 1
            break
#print(A)
if len(A) == n:
    for a in A[::-1]:
        print(a)
else:
    print(-1)

Fixed submission:
N = int(input())
n = N
B = list(map(int,input().split()))
B = B[::-1]
A = []
for i in range(N):
    for m,b in enumerate(B):
        if (N-m == b):
            A.append(b)
            B.pop(m)
            N -= 1
            break
if len(A) == n:
    for a in A[::-1]:
        print(a)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(N)])
res = 0
for a,b in range(N):
    M -= b
    res += a*b
    if M < 0:
        res += a*M
        break
print(res)

Fixed submission:
n,m = map(int,input().split())
ab = []
for i in range(n):
        ab.append([int(j) for j in input().split()])
ab.sort()
cnt = 0
ans = 0
for i in ab:
    cnt += i[1]
    ans += i[0]*i[1]
    if cnt >= m:
        ans -= i[0]*(cnt-m)
        print(ans)
        exit()

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
AB = [(int(i) for i in input().split()) for j in range(n)]
AB.sort()
res = 0
for a,b in AB:
	m -= b
	if m >= 0:
		res += a*b
	else:
		m += b
		res += a*m
		break
print(res)


Fixed submission:
n,m = map(int,input().split())
ab = []
for i in range(n):
        ab.append([int(j) for j in input().split()])
ab.sort()
cnt = 0
ans = 0
for i in ab:
    cnt += i[1]
    ans += i[0]*i[1]
    if cnt >= m:
        ans -= i[0]*(cnt-m)
        print(ans)
        exit()
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]

def f(S,T):
    res = INF
    s = bisect.bisect_left(S,x)
    for i in range(2):
    	for j in range(2):
            t = bisect.bisect_left(T,S[s-i])
            ans= abs(x-S[s-i])+abs(S[s-i]-T[t-j])
            if ans < res:
                res = ans
    return res

for i in range(q):
    x = int(input())
    print(min(f(S,T),f(T,S)))


Fixed submission:
from bisect import bisect_left
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]

def f(S,T):
    res = 10**30 
    s = bisect_left(S,x)

    ans = 0
    t = bisect_left(T,S[s-1])
    ans += abs(x-S[s-1])+min(abs(S[s-1]-T[t-1]),abs(S[s-1]-T[t]))
    if ans <= res:
        res = ans
    
    ans = 0
    t = bisect_left(T,S[s])
    ans += abs(x-S[s])+min(abs(S[s]-T[t-1]),abs(S[s]-T[t]))
    if ans <= res:
        res = ans

    return res


for i in range(q):
    x = int(input())
    print(min(f(S,T),f(T,S)))
Buggy python submission (verdict: Runtime Error):
n = int(input())+1
a = int(input())
b = int(input())
print((n-a)*(n-b))

Fixed submission:
import sys,math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

n,k = map(int,input().split())
if math.ceil(n/2) >= k:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp = [10**10]*n
dp[0] = 0
for i in range(n):
	for j in range(1,k+1):
		if i+j < n:
			dp[i+j] = min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp = [10**10]*n
dp[0] = 0
for i in range(n):
	for j in range(1,k+1):
		if i+j < n:
			dp[i+j] = min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
H_list = list(map(int,input().split()))
temp_list = [t-h*0.006 for h in H_list ]
ans_list = [abs(a-x) for x in temp_list]
ans = min(ans_list)
print(ans_list.index(ans)+1)   

Fixed submission:
x,y = map(int,input().split())
print(x + y // 2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
H_list = list(map(int,input().split()))
t_list = [t-h*0.006 for h in H_list ]
a_list = [abs(a-x) for x in temp_list]
print(a_list.index(min(a_list))+1)   

Fixed submission:
n = int(input())
t,a = map(int,input().split())
H_list = list(map(int,input().split()))
temp_list = [t-h*0.006 for h in H_list ]
ans_list = [abs(a-x) for x in temp_list]
ans = min(ans_list)
print(ans_list.index(ans)+1)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
L = N*M//gcd(N,M)
res = [0]*(L)
cnt1 = 0
for s in S:
    res[cnt1*L//N] = s
    cnt1 += 1
cnt2 = 0
for t in T:
    if res[cnt2*L//M] == 0 or res[cnt2*L//M] == t:
        res[cnt2*L//M] = t
        cnt2 += 1
    else:
        print(-1)
        exit()
print(L) 

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
G = gcd(N,M)
if S[::N//G] == T[::M//G]:
    print(N*M//G)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
L = N*M//gcd(N,M)
res = ['!']*(10**10)
cnt1 = 0
for s in S:
    if cnt1*L//N > L:
        print(-1)
        exit()
    res[cnt1*L//N] = s
    cnt1 += 1
cnt2 = 0
for t in T:
    if cnt2*L//M > L:
        print(-1)
        exit()
    if res[cnt2*L//M] == '!' or res[cnt2*L//M] == t:
        res[cnt2*L//M] = t
        cnt2 += 1
    else:
        print(-1)
        exit()
print(L) 

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
G = gcd(N,M)
if S[::N//G] == T[::M//G]:
    print(N*M//G)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
L = N*M//gcd(N,M)
res = ['!']*(L+100)
cnt1 = 0
for s in S:
    if cnt1*L//N > L:
        print(-1)
        exit()
    res[cnt1*L//N] = s
    cnt1 += 1
cnt2 = 0
for t in T:
    if cnt2*L//M > L:
        print(-1)
        exit()
    if res[cnt2*L//M] == '!' or res[cnt2*L//M] == t:
        res[cnt2*L//M] = t
        cnt2 += 1
    else:
        print(-1)
        exit()
print(L) 

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
G = gcd(N,M)
if S[::N//G] == T[::M//G]:
    print(N*M//G)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
L = N*M//gcd(N,M)
res = ['!']*(L+100)
cnt1 = 0
for s in S:
    res[cnt1*L//N] = s
    cnt1 += 1
cnt2 = 0
for t in T:
    if res[cnt2*L//M] == '!' or res[cnt2*L//M] == t:
        res[cnt2*L//M] = t
        cnt2 += 1
    else:
        print(-1)
        exit()
print(L) 

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
G = gcd(N,M)
if S[::N//G] == T[::M//G]:
    print(N*M//G)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
L = N*M//gcd(N,M)
res = ['!']*(L+1)
cnt1 = 0
for s in S:
    res[cnt1*L//N] = s
    cnt1 += 1
cnt2 = 0
for t in T:
    if res[cnt2*L//M] == '!' or res[cnt2*L//M] == t:
        res[cnt2*L//M] = t
        cnt2 += 1
    else:
        print(-1)
        exit()
print(L) 

Fixed submission:
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
G = gcd(N,M)
if S[::N//G] == T[::M//G]:
    print(N*M//G)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
V = list(map(int,input().split()))
a = [0]*10000000
b = [0]*10000000
v1=[]
v2=[]

if len(set(V)) == 1:
    print(n//2)

else:
    for i in range(n):
        if i%2 == 0:
            a[V[i]-1] += 1
            v1.append(V[i])
        else:
            b[V[i]-1] += 1
            v2.append(V[i])

    max1 = 0
    max2 = 0

    for j in range(len(a)):
        if max1 < a[j]:
            max1 = a[j]
            c1 = j
    for k in range(len(b)):
        if max2 < b[k]:
            max2=b[k]
            c2=k

    if c1 != c2:
        print(n-max1-max2)
    else:
        a.sort()
        b.sort()
        print(min(n-max1-b[-2],n-max2-a[-2]))


Fixed submission:
from collections import Counter

n = int(input())
S = list(map(int,input().split()))

Odd = Counter(S[::2]).most_common()+([(0,0)])
Even = Counter(S[1::2]).most_common()+([(0,0)])

if Odd[0][0] != Even[0][0]:
	print(n-Odd[0][1]-Even[0][1])
else:
	print(min(n-Odd[1][1]-Even[0][1],n-Odd[0][1]-Even[1][1]))