Harryxun/stf_run huggingface dataset:
def gcd(n,m):
    if m == 0:
        return n
    else:
        x = max(n,m)%min(n,m)
        while x != 0:
            return gcd(m,x)
        else:
            return m

import math
import copy

l = list(map(int,input().split()))
A = l[0]
B = l[1]
C = l[2]
D = l[3]

E = C * D //math.gcd(C,D)
# print(gcd(C,D))
# print(math.gcd(C,D))

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)


### FIXED CODE ###

from fractions import gcd 

l = list(map(int,input().split()))
A = l[0]
B = l[1]
C = l[2]
D = l[3]

E = C * D //gcd(C,D)

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)
#ABCA - Security
a = int(input())
s = list(a)
count = 0
for i in range(3):
    if s[i] != s[i+1]:
        count += 1
if count == 3:
    print("Good")
else:
    print("Bad")

### FIXED CODE ###

#ABCA - Security
a = str(input())
s = list(a)
count = 0
for i in range(3):
    if s[i] != s[i+1]:
        count += 1
if count == 3:
    print("Good")
else:
    print("Bad")
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  x=reversed_num(number.pop())+1
  if len(number)==0:
    break
  y=bisect.bisect_left(number,x)
  if x>number[-1]:
    y-=1
  if number[y] ==x:
    number[y]+=0.5
    count+=1
print(count)

### FIXED CODE ###

import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if len(number)==0:
    break
  if k==int(k):
    x=reversed_num(k)+1
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]-=0.5
      count+=1
print(count)
N, K = tuple(map(int, input().split()))

def new_link_n(i, j):
    s = len(link[i] + link[j])
    for i_link in link[i]:
        if i_link in link[j]:
            s -= 1
        else:
            for j_link in link[j]:
                if i_link in link[j_link]:
                    s -= 1
                    break
    for j_link in link[j]:
        if j_link in link[i]:
            s -= 1
        else:
            for i_link in link[i]:
                if j_link in link[i_link]:
                    s -= 1
                    break
    return s

# Kを減らす
def make_link1(M, s):
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if j in link[i]:
                continue
            n = new_link_n(i, j)
            if n <= 0 and s + n >= K:
                link[i].append(j)
                link[j].append(i)
                s += n
                M += 1
                if s == K:
                    return M
                return make_link1(M, s)

# Kを増やす
def make_link2(M, s):
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if j in link[i]:
                continue
            n = new_link_n(i, j)
            if n >= 0 and s + n <= K:
                link[i].append(j)
                link[j].append(i)
                s += n
                M += 1
                if s == K:
                    return M
                return make_link2(M, s)

        
if K > sum([i for i in range(1, N-1)]):
    print(-1)
else:
    link = {i: [] for i in range(1, N+1)}
    for i in range(1, N):
        link[i].append(i + 1)
        link[i + 1].append(i)
    M = N - 1
    now_k = N - 2
    if now_k == K:
        pass
    elif now_k > K:
        M = make_link1(M, now_k)
    else:
        M = make_link2(M, now_k)
    print(M)
    for i in range(1, N+1):
        for j in link[i]:
            if i < j:
                print(i, j)

### FIXED CODE ###

N, K = tuple(map(int, input().split()))

def make_link(M, s):
    for i in range(2, N+1):
        for j in range(i+1, N+1):
            link[i].append(j)
            M += 1
            s -= 1
            if s == K:
                return M

max_link = (N - 1) * (N - 2) / 2
if K > max_link:
    print(-1)
else:
    link = {i: [] for i in range(1, N+1)}
    for i in range(2, N+1):
        link[1].append(i)
    M = N - 1
    if max_link == K:
        pass
    else:
        M = make_link(M, max_link)
    print(M)
    for i in range(1, N+1):
        for j in link[i]:
            print(i, j)
n = int(input())
x = list(reversed(sorted(map(int,input().split()))))
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)

### FIXED CODE ###

n = int(input())
x = set(input().split())
if len(x)==3:
    print('Three')
else:
    print('Four')
ans_list = []
for i in range(2, 10):
    ans_list.append(2 ** i)
for i in range(2, 7):
    ans_list.append(3 ** i)
for i in range(2, 5):
    ans_list.append(5 ** i)
for i in range(2, 4):
    ans_list.append(7 ** i)
num = [11, 13, 17, 19, 23, 29, 31]
for i in num:
    ans_list.append(i ** 2)
X = int(input())
for i in range(X, 0, -1):
    if i in ans_list:
        ans = i
        break
print(ans)

### FIXED CODE ###

# ABC097-B
ans_list = [1]
for i in range(2, 10):
    ans_list.append(2 ** i)
for i in range(2, 7):
    ans_list.append(3 ** i)
for i in range(2, 5):
    ans_list.append(5 ** i)    
for i in range(2, 4):
    ans_list.append(6 ** i)
    ans_list.append(7 ** i)
    ans_list.append(10 ** i)
num = [11,12, 13, 14, 15, 17, 18, 19, 20, 21, 22,  23,24, 25, 26, 27, 28,  29, 30,  31]
for i in num:
    ans_list.append(i ** 2)
X = int(input())
for i in range(X, 0, -1):
    if i in ans_list:
        ans = i
        break
print(ans)
import sys, os

f = lambda:list(map(int,input().split()))
a = ["dream", "dreamer", "erase", "eraser"]
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

t = input().strip()


def dfs(somes):
    if somes == t:
        return True
    
    if len(somes) >= len(t):
        return False

    for i in a:
        if len(somes) + len(i) <= len(t)  and i == t[len(somes):len(somes) + len(i)]:
            if dfs(somes+i):
                return True
    
    return False

def solve():
    s = ""
    if dfs(s):
        print("YES")
    else:
        print("NO")

solve()


### FIXED CODE ###

import sys, os

f = lambda:list(map(int,input().split()))
a = ["dream", "dreamer", "erase", "eraser"]
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

t = input().strip()
t = t[::-1]

def solve():
    s = ""
    for i in range(len(a)):
        a[i] = a[i][::-1]


    end = 0
    lent = len(t)
    while(len(s)<len(t)):
        ok = False
        for i in a:
            if len(s) + len(i) <= lent and i == t[len(s): len(s) + len(i)]:
                s += i
                ok = True

        if ok == False:
            print("NO")
            return
    
    print("YES")

solve()
n=input()
if n==1:
  print('Hello World')
else:
  a=input()
  b=input()
  print(a+b)

### FIXED CODE ###

n=int(input())
if n==1:
  print('Hello World')
else:
  a=int(input())
  b=int(input())
  print(a+b)
s,K = input(),int(input())

subList = []
N = len(s)
repNum = 0

while N - repNum >= 1:
        for i in range(repNum+1):
                subList.append(s[i:N-repNum+i])
        repNum += 1
subListUniq = list(set(subList))
subListUniq.sort()
print(subListUniq[K-1])

### FIXED CODE ###

s = input()
K = int(input())

substr = set()
for i in range(len(s)):
    for j in range(i+1, i+K+1):
        substr.add(s[i:j])

print(sorted(substr)[K-1])
from collections import deque
from bisect import bisect_left, bisect_right
from itertools import accumulate


n,m,k = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

al_sums = accumulate(al)
bl_sums = accumulate(bl)

ans = 0
for i in range(0,n+1):
    if i == 0: 
        a_sum = 0
    else:
        a_sum = al_sums[i-1]
    if a_sum > k: 
        continue
    cnt = bisect_right(bl_sums, k-a_sum)
    curr_ans = i+cnt
    ans = max(ans,curr_ans)

print(ans)

### FIXED CODE ###

from collections import deque
from bisect import bisect_left, bisect_right

n,m,k = map(int, input().split())

al = list(map(int, input().split()))
bl = list(map(int, input().split()))

al_sums = [0]*(n+1)
bl_sums = [0]*(m)

curr_sum = 0
for i,a in enumerate(al):
    curr_sum += a
    al_sums[i+1] = curr_sum

curr_sum = 0
for i,b in enumerate(bl):
    curr_sum += b
    bl_sums[i] = curr_sum

# print(al_sums)
# print(bl_sums)


ans = 0
for i in range(n+1):
    a_sum = al_sums[i]
    if a_sum > k: continue
    cnt = bisect_right(bl_sums, k-a_sum)
    curr_ans = i+cnt
    # print(i,curr_ans, k-a_sum)
    ans = max(ans,curr_ans)

print(ans)
a=int(input())
b=int(input())
if(a<=9&b<=9):
  print(a*b)
else:
  print(-1)

### FIXED CODE ###

a,b=map(int,input().split())
if a <= 9 and b <= 9:
  print(a*b)
else:
  print(-1)
a,b,c=map(int,input(),split())
if 2*((a*b)**0.5)<c**2-a-b:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a,b,c=map(int,input().split())
if c>=a+b and 4*a*b<(c-a-b)**2:
  print('Yes')
else:
  print('No')
a,b,c=map(int,input().split())
print("YES" b-a=c-a else "NO")

### FIXED CODE ###

a,b,c=map(int,input().split())
print("YES" if b-a==c-b else "NO")
a = [[j for j in map(int,input().split())] for i in range(3)]
n = int(input())
b = [[int(j) for j in input()] for i in range(n)]

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j] == b[k]:
                a[i][j] = 0

if sum(a[0]) == 0 or sum(a[1]) == 0 or sum(a[2] == 0):
    print('Yes')
elif a[0][0] + a[1][1] + a[2][2] or a[0][2] + a[1][1] + a[3][0]:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import numpy as np
a = [[j for j in map(int,input().split())] for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j] == b[k]:
                a[i][j] = 0
a = np.array(a)
if sum(a[0,:]) == 0 or sum(a[1,:]) == 0 or sum(a[2,:]) == 0:
    print('Yes')
elif sum(a[:,0]) == 0 or sum(a[:,1]) == 0 or sum(a[:,2]) == 0:
    print('Yes')
elif (a[0][0] + a[1][1] + a[2][2]) == 0 or (a[0][2] + a[1][1] + a[2][0]) == 0:
    print('Yes')
else:
    print('No')
A,B,C=map(int,input().split())
printf("Yes" if A+B>=C else "No")

### FIXED CODE ###

A,B,C=map(int,input().split())
print("Yes" if A+B>=C else "No")
import numpy as np
import re

def find_AC(S):
  ret = []
  for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
      ret.append(i)
  return re

N, Q = [int(x) for x in input().split()]
S = input()
result = find_AC(S)
#pos = np.array([res.start()+1 for res in result])
pos = [res.start()+1 for res in result]

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  ans = 0
  for p in pos:
    if p>=l and p<=r-1:
      ans += 1
  print(ans)


### FIXED CODE ###

import numpy as np
def find_AC(S):
  ret = [0]*len(S)
  for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
      ret[i+1] = 1
  return ret

N, Q = [int(x) for x in input().split()]
S = input()

cum = np.cumsum(find_AC(S))

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  ans = cum[r-1] - cum[l-1]
  print(ans)
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())

    a.sort()
    notdiv = [True] * n
    if a[0] == a[1]:
        notdiv[0] = False
    if a[-1] == a[-2]:
        notdiv[-1] = False
    for j1 in range(1, n - 1):
        if a[j1-1] == a[j1] or a[j1] == a[j1+1]:
            notdiv[j1] = False
    for i1, ae in enumerate(a):
        if notdiv[i1]:
            for i2, ae2 in enumerate(a[i1+1:]):
                if notdiv[i1 + i2 + 1]:
                    notdiv[i1 + i2 + 1] = ae2 % ae != 0
    r = sum(notdiv)
    print(r)
if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))

    a.sort()
    tf = [0] * (a[-1] + 1)
    for ea in a:
        tf[ea] = 1
    for i1 in range(n - 1):
        if a[i1] == a[i1 + 1]:
            tf[a[i1]] = 0

        for i2 in range(2, a[-1]//a[i1] + 1):
            tf[a[i1] * i2] = 0
    r = sum(tf)
    print(r)


if __name__ == '__main__':
    main()
K = int(input())
S = input()
if len(S) <= K:
    print(s)
else:
    s = ""
    for i in range(K):
        s += S[i]
    s += "..."
    print(s)

### FIXED CODE ###

K = int(input())
S = input()
if len(S) <= K:
    print(S)
else:
    s = ""
    for i in range(K):
        s += S[i]
    s += "..."
    print(s)
r,g,b=input().split()
sum=100*r+10*g+b
if sum%4==0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

i = list(map(int, input().split()))
s=i[1]*10+i[2]
if s%4==0:
  print("YES")
else :
  print("NO")
N = int(input())
V=list(map(int, input().split()))
C= list(map(int, input().split()))
X = 0
for i in range(N):
  if(V[i]-C[i]>0):
    X += V[i] -C[i]
print(X)

### FIXED CODE ###

A,B,T=map(int, input().split())
t_max = int((T+0.5)/A)
print(t_max*B)
N, K = map(int, input().split())
A = list(map(int, input().split()))

k = [(K+1)&(1<<i) for i in range(40)]

c = [0]*40
for a in A:
	for i in range(40):
		if a&(1<<i):
			c[i] += 1

m = [0]*40
for i in range(40):
	if 2*c[i]<N:
		m[i] = (1<<i)*(N-c[i])
	else:
		m[i] = (1<<i)*c[i]

x = sum(A)
for i in reversed(range(40)):
	if k[i] != 0:
		x = max(x, sum(m[:i]+[(1<<i)*(N-c[i])]+k[i+1:]))

print(x)

### FIXED CODE ###

T, X = map(int, input().split())
print(T/X)
def gcd(a, b):
    if (a == b):
        return a
    elif (a == 0):
        return b
    elif (b == 0):
        return a
    elif (a < b):
        return gcd(a, b - a)
    elif (b < a):
        return gcd(b, a - b)


n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
ans = 0

for e in a:
    if (len(a) <= 2):
        ans = a[0]
    else:
        rep = 0
        a.remove(e)

        for i in range((len(a) - 1)):
            rep = gcd(a[i + 1], a[i])
            if (rep <= ans):
                break
            else:
                ans = rep

        a.append(e)

print(ans)


### FIXED CODE ###

from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
left = [0] * (n + 1)
right = [0] * (n + 1)
middle = [0] * (n + 1)

for i in range(0, n - 1):
    left[i + 1] = gcd(left[i], a[i])

for i in range(n - 1, 0, -1):
    right[i] = gcd(right[i + 1], a[i])

for i in range(n):
    middle[i] = gcd(left[i], right[i + 1])

print(max(middle))
n=int(input())
k =int(input()) 
count=0
for i in range(n):
  x=int(input())
  if x>=k:
    count=count+1
print(count)

### FIXED CODE ###

n,k = [int(x) for x in input().split()]
cnt=0
list  = input().split()
for num in list:
    if int(num)>=k: cnt=cnt+1
print(cnt)
def main():
    x, y = map(int, input().split())

    if x < y:
        x_ = y
        y_ = x

        x = y_
        y = x_
    
    if (x+y) % 3 != 0:
        print(0)

    else:
        n = (x+y)//3
        r = x//2

        #a = len(list(itertools.combinations(range(n), r)))
        #a = comb(n, r, exact=True)
        #a = comb_1(n, r)
        def cmb(n, r, mod):
            if ( r<0 or r>n ):
                return 0
            r = min(r, n-r)
            return g1[n] * g2[r] * g2[n-r] % mod

        mod = 10**9+7 #出力の制限
        N = 10**4
        g1 = [1, 1] # 元テーブル
        g2 = [1, 1] #逆元テーブル
        inverse = [0, 1] #逆元テーブル計算用テーブル

        for i in range( 2, N + 1 ):
            g1.append( ( g1[-1] * i ) % mod )
            inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
            g2.append( (g2[-1] * inverse[-1]) % mod )

        a = cmb(n,r,mod)

        print(a)

if __name__ == '__main__':
    main()



### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )



x, y = map(int, input().split())

if (2*y-x)%3 == 0 and (2*x-y)%3 == 0:
    m = (2*y-x)//3
    n = (2*x-y)//3

    if n >= 0 or m >= 0:
        print( str(int(cmb(n+m,n, mod) % (10e9+7)) ))
    else:
        print(0)
else:
    print(0)
n = int(input())
flag = 1

n_1 = (n-(n//10)*10)
n_10 = (n-(n//100)*100 - n_1)//10
n_100 = (n - n_1 - n_10*10)//100

if(n_1!=7 && n_10!=7 && n_100!=7):
  flag = 0

if flag == 0 :
  print("NO")
else:
  print("YES")

### FIXED CODE ###

import sys

n = input()
for i in range(3):
    if(n[i] == "7"):
        print("Yes")
        sys.exit()

print("No")
N,P=map(int,input().split())
S=input()
L=[]
M=0
for i in range(len(S)):
    L.append((M*10+int(S[i]))%P)
    M=L[-1]
#print(L)
if P==5:
    n=0
    ans=0
    for i in range(len(S)):
        if L[i]==0 or L[i]==5:
            ans+=n
            n+=1
    if n>0:
        ans+=n
elif P==2:
    n=0
    ans=0
    for i in range(len(S)):
        if L[i]%2==0:
            ans+=n
            n+=1
    if n>0:
        ans+=n
else:    
    D={}
    ans=0
    for i in range(len(L)):
        if L[i] not in D:
            D[L[i]]=1
        else:
            ans+=D[L[i]]
            D[L[i]]+=1
    if D[0]>0:
        ans+=D[0]
print(ans)

### FIXED CODE ###

N,P=map(int,input().split())
S=input()

if 10%P==0:
    ans=0
    for i in range(N):
        if int(S[i])%P==0:
            ans+=(i+1)
    print(ans)
else:
    S=S[::-1]
    D={}
    D[0]=1
    Amari=0
    for i in range(N):
        I=((Amari)+(pow(10,i,P)*int(S[i])))%P
        Amari=I
        if I not in D:
            D[I]=1
        else:
            D[I]+=1
    ans=0
    for k,v in D.items():
        ans+=v*(v-1)//2
    print(ans)
    #print(D)
i = 1
while True:
    x = int(input().strip())
    if x == 0:
        break
    else:
        print ('Case' {}: {}).format(i,x)
        i += 1

### FIXED CODE ###

i = 1
while True:
    x = int(input().strip())
    if x == 0:
        break
    else:
        print ("Case {}: {}".format(i,x))
        i += 1
if __name__ == "__main__":
    
    n = int(input())

    for o in range(1, n+1):
        for x in range(int(n**0.5), 100):
            isFound = False
            isOver = False
            for y in range(1, x+1):
                for z in range(1, y+1):
                    m = x**2+y**2+z**2+x*y+y*z+z*x
                    if m == o:
                        isFound = True
                        if x==y and y==z: print(1)
                        elif x==y or y==z or z==x: print(3)
                        else: print(6)
                        break
                    elif m > o:
                        isOver = True
                        break
                if isFound or isOver: break
            if isFound: break
        if not isFound: print(0)

### FIXED CODE ###

if __name__ == "__main__":
    
    n = int(input())

    """for o in range(1, n+1):
        s = 1
        if o > 6:
            s = -1 + int((o-2)**0.5)
        for x in range(s, 100):
            isFound = False
            for y in range(1, x+1):
                for z in range(1, y+1):
                    m = x**2+y**2+z**2+x*y+y*z+z*x
                    if m == o:
                        isFound = True
                        if x==y and y==z: print(1)
                        elif x==y or y==z or z==x: print(3)
                        else: print(6)
                        break
                    elif m > o:
                        break
                if isFound: break
            if isFound: break
        if not isFound: print(0)"""

    ans = [0 for _ in range(10001)]
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                m = x**2+y**2+z**2+x*y+y*z+z*x
                if m > 10000: break
                ans[m] += 1

    for i in range(n):
        print(ans[i+1])
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

from collections import deque
sys.setrecursionlimit(10**6)

N, M = mi()
x = li2(M)

adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

flag = [0]*N
ans = deque([])

def dfs(x):
    if flag[x]:
        return None
    else:
        flag[x] = 1
        for a in adj[x]:
            dfs(a)
        global ans
        ans.appendleft(x)

for i in range(N):
    dfs(i)

dp = [0]*N
for a in ans:
    for b in adj[a]:
        dp[b] = max(dp[b], dp[a] + 1)

print(max(dp))

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))

dp = [0]*N

dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] =  min(dp[i-2]+abs(H[i]-H[i-2]), dp[i-1]+abs(H[i]-H[i-1]))

print(dp[N-1])
A=input()
B=input()

print(int(A)*int(B))

### FIXED CODE ###

A,B = map(int,input().split())
print(A*B)
from scipy.special import comb

N,M = map(int,input().split())

if N == 1:
    c1 = 0
else:
    c1 = comb(N, 2, exact=True)

if M == 1:
    c2 = 0
else:
    c2 = comb(M, 2, exact=True)

c3 = c1 + c2
print(c3)

### FIXED CODE ###

import itertools

N,M = map(int,input().split())

if N == 1:
    c1 = 0
else:
    c1 = len(list(itertools.combinations(range(N), 2)))

if M == 1:
    c2 = 0
else:
    c2 = len(list(itertools.combinations(range(M), 2)))

c3 = c1 + c2
print(c3)
a,b,c=map(int.input())
if a=b=c:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a,b,c=map(int,input().split())
if a==b and b==c and c==a:
    print("Yes")
else:
    print("No")
n=int(input())
h = list(map(int,input().split()))
ans=-1
while h[-1]>=0:
    flag=0
    for i in range(n-1):
        if h[i]>h[i+1]:
            h[i]-=1
            flag=1
            break
        h[i]=h[i]-1
    if flag==0:
        h[i+1]-=1
    ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
h = list(map(int,input().split()))
ans=-1
if n==1:
    ans=h[0]
    h[0]=-1
while h[-1]>=0:
    flag=0
    for i in range(n-1):
        if h[i]>h[i+1]:
            h[i]-=1
            flag=1
            break
        h[i]=h[i]-1
    if flag==0:
        h[i+1]-=1
    ans+=1
print(ans)
S = input()
Q = int(input())
for i in range(Q):
  Query_i = list(map(str, input().split()))
  if Query_i[0]=='1':
    S = S[::-1]
  elif Query_i[1] = '1':
    S = Query_i[2] + S
  else:
    S = S + Query_i[2]

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())
flip = False # False: left side is the head
for i in range(Q):
  Query_i = list(map(str, input().split()))
  if Query_i[0]=='1':
    flip = not flip
  elif Query_i[1] == '1' and not flip:
    S.appendleft(Query_i[2])
  elif Query_i[1] == '1' and flip:
    S.append(Query_i[2])
  elif Query_i[1] == '2' and not flip:
    S.append(Query_i[2])
  elif Query_i[1] == '2' and flip:
    S.appendleft(Query_i[2])
if flip:
  S.reverse()
print(''.join(S))
x = list(map(int,input().split()))
y = x.sort()
print(y[0], y[1], y[2])

### FIXED CODE ###

x = list(map(int,input().split()))
x.sort()
print(x[0],x[1],x[2])
from fractions import gcd

n, m = [int(i) for i in input().split()]
S = input()
T = input()

g = n * m // gcd(n, m)

L = [''] * g
if S[0] != T[0]:
    print(-1)
    exit()

try:
    for i, s in zip(range(0, g, g//n), S):
        L[i] = s

    for i, t in zip(range(0, g, g//m), T):
        L[i] = t
        
    A = []
    B = []

    for i in range(0, g, g//n):
        A.append(L[i])

    for i in range(0, g, g//m):
        B.append(L[i])

    if ''.join(A) == S and ''.join(B) == T:
        print(g)
    else:
        print(-1)

except:
    print(-1)

### FIXED CODE ###

from fractions import gcd

n, m = [int(i) for i in input().split()]
S = input()
T = input()

g = n * m // gcd(n, m)

SA = set()
SB = set()

for i in range(0, g, g//n):
    SA.add(i)

for i in range(0, g, g//m):
    SB.add(i)

SC = SA & SB

for s in SC:
    if S[s//(g//n)] != T[s//(g//m)]:
        print(-1)
        exit()

print(g)