Harryxun/stf_run huggingface dataset:
w,h,x,y=map(int,input().split())
if w%x==0 and h%y==0:
    print(x*h) 
    print(1)
elif w%x==0:
    print(x*h)
    print(0)
elif w%x!=0:
    print(y*w)
    print(0)
else:
    print(w*h/2)
    print(0)

### FIXED CODE ###

x,a=map(int,input().split())
print(0 if x<a else 10)
from collections import defaultdict
d = defaultdict(int)
for _ in range(int(input())):
    d[input()] += 1
for _ in range(int(input())):
    d[input()] -= 1
print(max(d.values(),0))

### FIXED CODE ###


from collections import defaultdict
d = defaultdict(int)
for _ in range(int(input())):
    d[input()] += 1
for _ in range(int(input())):
    d[input()] -= 1
print(max(max(d.values()),0))
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
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([])
ans = []

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

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

#print(ans)

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

print(max(dp))

### FIXED CODE ###

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
'''
N, M = mi()
x = li2(M)

#dp = dp2(0, 2, N)
dp = [[0, []] for i1 in range(N+1)]


for i in range(M):
    dp[x[i][1]][0] = max(dp[x[i][1]][0], dp[x[i][0]][0] + 1)
    dp[x[i][0]][1].append(x[i][1])
    if dp[x[i][1]][1] != []:
        for a in dp[x[i][1]][1]:
            dp[a][0] = max(dp[x[i][1]][0] + 1, dp[a][0])

print(dp)
print(max([row[0] for row in dp])) 
'''
from collections import deque
N, M = mi()
x = li2(M)

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

zeros = deque([])
ans = []
for i in range(N):
    if h[i] == 0:
        zeros.append(i)
        ans.append(i)

while(zeros != deque()):
    a = zeros.popleft()
    if(adj[a]):
        for b in adj[a]:
            h[b] -= 1
            if h[b] == 0:
                zeros.append(b)
                ans.append(b)

#print(ans)

dp = [0]*N
#print(ans)
#print(adj)
for a in ans:
    #print(dp)
    if adj[a]:
        for b in adj[a]:
            dp[b] = max(dp[a] + 1, dp[b])
#print(dp)
print(dp[ans[-1]])
mod = 1000000007

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(s, t):
    if   t == 0     : return 1
    elif t == 1     : return x % mod
    elif t % 2 == 0 : return power(s, t/2)**2 % mod
    else            : return power(s, t/2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))
    
def cmb(a,b):
    p = 1
    q = 1
    for i in range(1,b+1):
        p = mul(p,a-i)
    for j in range(1,b+1):
        q = mul(q,j)
    return div(p,q)

x,y,z = map(int,input().split(" "))
ans = 0

for i in range(1,x+1):
    if i == y or i == z:
        continue
    else:
        ans += cmb(x,i)

print(ans)

### FIXED CODE ###

#xCy=x!/y!(x-y)!
def com(x,y):
    bunb = 1
    buns = 1
    for i in range(y):
        buns = buns * (x-i) % mod
        bunb = bunb * (i+1) % mod

    bunb_inv = pow(bunb,mod-2,mod)
    d = (buns * bunb_inv) % mod
    return buns*pow(bunb,mod-2,mod)
    
n,a,b = map(int,input().split())
mod = 10**9 + 7

ans = pow(2,n,mod) - 1
ans -= com(n,a) + com(n,b)

print(ans%mod)
def dfs(v, p, ans):
    if p!=-1: ans[v] += ans[p]
    for g in G[v]:
        if g==p: continue
        dfs(g, v, ans)
    return ans

n, q = map(int, input().split())
ans = [0]*n
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b = list(map(lambda x: x-1, map(int, input().split())))
    G[a].append(b)
    G[b].append(a)

for i in range(q):
    p,x = map(int, input().split())
    ans[p-1] += x

ans = dfs(0, -1, ans)

print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n, q = map(int, input().split())
G = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(lambda x: x-1, map(int, input().split()))
    G[a].append(b)
    G[b].append(a)

ans = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x

def dfs(v, pre=-1):  
    for nx in G[v]:
        if nx==pre:
            continue
        ans[nx] += ans[v]
        dfs(nx,v)
dfs(0)
print(*ans)
import copy
 
# 二分探索
def binearSearch(n, S, t):
     
    left = 0
    right = n
    
    while left < right:
        mid = (left + right) / 2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        else:        
            left = mid + 1
    return NOT_FOUND
 
if __name__ == '__main__':
     
    # 入力
    n = int(input())　# 数列Sに含まれる整数の個数
    S = list(map(int,input().split())) # 整数を含む数列
    q = int(input()) # 数列Tに含まれる異なる整数の個数
    T = list(map(int,input().split())) # 異なる整数を含む数列
     
    # 初期化
    C = 0　# Tに含まれる整数の中でSに含まれるものの個数
     
    # 数列T内の整数を1つずつチェック
    for i in range(q):
        isExist = linearSearch(n, copy.deepcopy(S), T[i])
         
        # 存在してたらカウント
        if isExist :
            C = C + 1
    # 出力
    print(C)


### FIXED CODE ###

import copy

NOT_FOUND = False

# 二分探索
def binarySearch(n, S, t):
     
    left = 0
    right = n
    key = t
    while left < right:
        mid = (left + right) // 2
        if S[mid] == key:
            return True
        elif key < S[mid]:
            right = mid
        else:        
            left = mid + 1
    return NOT_FOUND
 
if __name__ == '__main__':
     
    # 入力
    n = int(input()) # 数列Sに含まれる整数の個数
    S = list(map(int,input().split())) # 整数を含む数列
    q = int(input()) # 数列Tに含まれる異なる整数の個数
    T = list(map(int,input().split())) # 異なる整数を含む数列
     
    # 初期化
    C = 0 # Tに含まれる整数の中でSに含まれるものの個数
     
    # 数列T内の整数を1つずつチェック
    for i in range(q):
        isExist = binarySearch(n, S, T[i])
         
        # 存在してたらカウント
        if isExist :
            C = C + 1
    # 出力
    print(C)
#142
import pandas as pd
N = int(input())
S = list(map(int,input().split()))
df = pd.DataFrame()
for i, j in enumerate(S,1):
    df_tem = pd.DataFrame([i, j]).T
    df = pd.concat([df, df_tem], axis=0)
df.columns = ['x', 'y']
df = df.sort_values(by='y')

print(' '.join(list(map(str,df['x'].tolist()))))

### FIXED CODE ###

#142
import numpy as np
N = int(input())
S = list(map(int,input().split()))

l = []
for i, j in enumerate(S,1):
    l_tem = [i,j]
    l += l_tem
l = np.array(l).reshape(N,2)
l = list(l[np.argsort(l[:,1])][:,0])

print(' '.join(list(map(str,l))))
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n, m, k = map(int, input().split())
    ns = list(map(int, input().rstrip().split()))
    ms = list(map(int, input().rstrip().split()))
    # 全部Aの場合上からなんこ取れるかを見つつ、Bを入れて押し出していく
    sum = 0
    last_flg = False
    for (i, v) in enumerate(ns):
        if sum + v > k:
            break
        else:
            sum += v
        if i == len(ns) - 1:
            last_flg = True

    if last_flg:
        i += 1
    ans_now = i
    ans = ans_now
    i -= 1
    for v in ms:
        break_flg = False
        if sum + v > k:
            while sum + v > k:
                sum -= ns[i]
                i -= 1
                ans_now -= 1
                if i == 0:
                    break_flg = True
                    break
            if break_flg:
                break
            sum += v
            ans_now += 1
        else:
            sum += v
            ans_now += 1
        ans = max(ans, ans_now)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    _n, _m, k = map(int, input().split())
    ns = list(map(int, input().rstrip().split()))
    ms = list(map(int, input().rstrip().split()))
    sum = 0
    count = 0
    for v in ns:
        if sum + v > k:
            break
        else:
            sum += v
            count += 1

    ans_now = count
    ans = ans_now
    i = count - 1
    for v in ms:
        if sum + v > k:
            while sum + v > k:
                if i < 0:
                    break
                sum -= ns[i]
                i -= 1
                ans_now -= 1
            if sum + v > k:
                break
            sum += v
            ans_now += 1
        else:
            sum += v
            ans_now += 1
        ans = max(ans, ans_now)
    print(ans)


if __name__ == '__main__':
    main()
c11, c12, c13 = list(raw_input())
c21, c22, c23 = list(raw_input())
result = c11 == c23 and \
    c12 == c22 and \
    c13 == c21

ans = "YES" if result else "NO"
print ans

### FIXED CODE ###

c11, c12, c13 = list(input())
c21, c22, c23 = list(input())
result = c11 == c23 and \
    c12 == c22 and \
    c13 == c21

ans = "YES" if result else "NO"
print(ans)
import math
from collections import deque


def main():
    s = list(input())
    k = int(input())
    lst = []
    cnt = 1
    flg = 0
    ans = 0
    prev = s[0]
    for i in range(1, len(s)):
        if prev == s[i]:
            cnt += 1
        else:
            lst.append(cnt)
            cnt = 1
            prev = s[i]
            flg = 1
    lst.append(cnt)
    if len(lst) == 1:
        ans = s * k // 2
    else:
        # ans += sum(list(map(lambda x: x // 2, lst[1:len(lst)-1]))) * k
        for l in lst[1: len(lst) - 1]:
            ans += l // 2 * k
        if s[-1] == s[0]:
            ans += (lst[0] + lst[-1]) // 2 * (k - 1)
            ans += lst[0] // 2 + lst[-1] // 2
        else:
            ans += (lst[0] // 2 + lst[-1] // 2) * k
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###



def main():
    s = list(input())
    k = int(input())
    lst = []
    cnt = 1
    flg = 0
    ans = 0
    prev = s[0]
    for i in range(1, len(s)):
        if prev == s[i]:
            cnt += 1
        else:
            lst.append(cnt)
            cnt = 1
            prev = s[i]
            flg = 1
    lst.append(cnt)
    if len(lst) == 1:
        ans = len(s) * k // 2
    else:
        ans += sum(list(map(lambda x: x // 2, lst[1:len(lst)-1]))) * k
        # for l in lst[1: len(lst) - 1]:
        #     ans += l // 2 * k
        if s[-1] == s[0]:
            ans += (lst[0] + lst[-1]) // 2 * (k - 1)
            ans += lst[0] // 2 + lst[-1] // 2
        else:
            ans += (lst[0] // 2 + lst[-1] // 2) * k
    print(ans)


if __name__ == "__main__":
    main()
ef resolve():
    n=int(input())
    ans=0

    for i in range(n+1):
        if i%3!=0 and i%5!=0:
            ans+=i
    print(ans)
if __name__ == "__main__":
    resolve()

### FIXED CODE ###

def resolve():
    n=int(input())
    ans=0

    for i in range(n+1):
        if i%3!=0 and i%5!=0:
            ans+=i
    print(ans)
if __name__ == "__main__":
    resolve()
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#N, K, C = map(int, readline().split())  int
#S = read().rstrip().decode()  string
# N =int(read())
#print(C,A,B)

x=read()
if ''7' in x:
	print("Yes")
else:
	print("No")

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#N, K, C = map(int, readline().split())  int
#S = read().rstrip().decode()  string
# N =int(read())
#print(C,A,B)

x=read().rstrip().decode()

if '7' in x:
	print("Yes")
else:
	print("No")
import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    print("No") if S == "AAA" or S == "BBB" else print("Yes")


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    print("No") if S == "AAA" or S == "BBB" else print("Yes")


if __name__ == '__main__':
    main()
N = int(input())
s = input()
t = input()

count = 0
for i in range(len(s)):
    if t[i] == s[-i-1]:
        count += 1
    else:
        break

if s = t:
    print(len(s))
else:
    print(len(s)+len(t)-count)

### FIXED CODE ###

N = int(input())
s = input()
t = input()

count = 0
for i in range(len(s)):
    if t[:i+1] in s[-i-1:]:
        count = i+1
    else:
        pass

print(len(s)+len(t)-count)
N,M,X,Y = map(int, input().split())
x = [int(_) for _ in input().split()]
y = list(map(int, input().split()))
maxX = max(x)
minY = min(y)

print(maxX,maxY)
for i in range(Y+1):
    if X < i <= Y and maxX < i and minY >= i:
        print("No War")
        break
    elif i == Y:
        print("War")
        break

### FIXED CODE ###

N,M,X,Y = map(int, input().split())
x = [int(_) for _ in input().split()]
y = list(map(int, input().split()))
maxX = max(x)
minY = min(y)
flag = True
for i in range(Y+1):
    if X < i <= Y and maxX < i and minY >= i:
        print("No War")
        flag = False
        break
if flag:
    print("War")
n = int(input())


a = list(range(1, n))

print(sum(a))


### FIXED CODE ###

n = int(input())


a = (1+n-1)*(n-1)//2
print(a)
INFTY = 100000000
n = int( raw_input() )
graph = {}
for i in range(n):
  In = map( int, raw_input().split('') )
  a = In[0]
  b = In[1]
  graph[a] = {}
  for j in range(b):
    c = In[2+j*2+1]
    d = In[2+j*2]
    graph[a][d] = c
 
da = {}
visited = {}
for i in range(n):
  da[i] = INFTY
  visited[i] = False
s = 0
da[s] = 0
visited[s] = True
 
while True:
  for i in range(n):
    if not visited[i] and i in graph[s] and da[i] > da[s] + graph[s][i]:
      da[i] = da[s] + graph[s][i]
  cost = INFTY
  node = -1
  for i in range(n):
    if not visited[i] and da[i] < cost:
      cost = da[i]
      node = i
  if cost == INFTY: 
    break
  visited[node] = True
  s = node
  
for i in range(n):
  print i,da[i]

### FIXED CODE ###

INFTY = 100000000
n = int( raw_input() )
graph = {}
for i in range(n):
  In = map( int , raw_input().split(' ') )
  u = In[0]
  k = In[1]
  graph[u] = {}
  for j in range(k):
    v = In[2+j*2]
    c = In[2+j*2+1]
    graph[u][v] = c
 
da = {}
visited = {}
for i in range(n):
  da[i] = INFTY
  visited[i] = False
s = 0
da[s] = 0
visited[s] = True
 
while True:
  for i in range(n):
    if not visited[i] and i in graph[s] and da[i] > da[s] + graph[s][i]:
      da[i] = da[s] + graph[s][i]
  cost = INFTY
  node = -1
  for i in range(n):
    if not visited[i] and da[i] < cost:
      cost = da[i]
      node = i
  if cost == INFTY: 
    break
  visited[node] = True
  s = node
  
for i in range(n):
  print i,da[i]
n = int(input())
print(2 * n,end = "\n")

### FIXED CODE ###

a,b = map(int,input().split())
print((a-1) * (b-1))
inputa = int(input())
inputb = input()
flag = 0
res = ""

for c in inputb:
  if c == "o":
    if flag % 2 == 0:
      res += "S"
    else:
      res += "W"
  else:
    res += "S"
    flag += 1

if inputb[0] == "o":
  if flag % 2 != 0:
    print(-1)
  else:
    print(res)
elif inputb[0] == "x":
  if flag % 2 != 1:
    print(-1)
  else:
    print(res)
else:
  print(res)

### FIXED CODE ###

N = int(input())
print(N*800 - N//15*200)
"""
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z
"""


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return int(a * b / gcd(a, b))


n = int(input())
# つまり全t[i]で割り切れる値を出せということ
# 最小公倍数を出せばよい
sum = int(input())
for i in range(1, n):
    t = int(input())
    # print("sum:{} t:{} lcm:{}".format(sum, t, lcm(sum, t)))
    sum = lcm(sum, t)
print(sum)
"""
# 入力 : 自然数     ex) 12
# 出力 : 約数リスト ex) [2, 2, 3]
def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    first = True
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n = n / i
                if i == div and not first:
                    alreadyExist = True
                else:
                    alreadyExist = False
                first = False
                div = i
                if n == 1:
                    s = 1
                if alreadyExist:
                    L[-1][1] += 1
                else:
                    L.append([i, 1])
                break
    return L


n = int(input())
t = [0 for i in range(n)]
fact = []
for i in range(n):
    # print(i)
    t[i] = int(input())
    if i == 0:
        fact = factorization(t[i])
    else:
        tmpFact = factorization(t[i])
        for _tmpFact in tmpFact:
            for _fact in fact:
                if _fact[0] == _tmpFact[0]:
                    _fact[1] = max(_fact[1], _tmpFact[1])
                    break
                elif _fact[0] == fact[-1][0]:
                    fact.append(_tmpFact)
# つまり全t[i]で割り切れる値を出せということ
# 最小公倍数を出せばよい
sum = 1
for _fact in fact:
    sum *= _fact[0]**_fact[1]
print(sum)
"""


### FIXED CODE ###

def gcd(a, b):
    while b > 0:
        tmp = a
        a = b
        b = tmp % b
    return a


def lcm(a, b):
    tmp = gcd(a, b)
    return (a//tmp) * b


n = int(input())
t = [0 for i in range(n)]
for i in range(n):
    t[i] = int(input())
t = sorted(t)
_sum = t[0]
for i in range(1, n):
    # print("sum:{} t:{} lcm:{}".format(sum, t, lcm(sum, t)))
    _sum = lcm(_sum, t[i])
    # print(sum)
print(_sum)
def gcd(a,b):
    while b > 0:
        a, b = b, a%b
    return a

def gcd_list(lst):
    a = gcd(lst[0],lst[1])
    i=2
    while a > 0 and i<len(lst):
        a = gcd(a, lst[i])
        if a == 1:
            return 1
            break
        i+=1
    return a
    
n, k = (int(i) for i in input().split())
a = list(int(i) for i in input().split())  
maxA=max(a)

if maxA >= k and k%gcd_list(a) == 0:
    print("POSSIBLE")
elif k in a:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

def gcd(a,b):
    while b > 0:
        a, b = b, a%b
    return a

def gcd_list(lst):
    g = lst[0]
    for i in range(1,len(lst)):
        g = gcd(g,lst[i])
    return g
    
n, k = (int(i) for i in input().split())
a = list(int(i) for i in input().split())  

maxA=max(a)

if (k <= maxA and k%gcd_list(a) == 0) or (k in a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
h,w=map(int,input().split())
l=[[0]*w]*h
m=[""]*h
for k in range(h):
  m[k]=input()
l[0][0]=1
for k in range(h):
  for j in range(w):
    if m[k][j]=="#":
      l[k][j]=0
    else:
      if k==0:
        if j!=0:
          l[k][j]=l[0][j-1]
      elif j==0:
        if k!=0:
          l[k][j]=l[k-1][j]
      else:
        l[k][j]=l[k-1][j]+l[k][j-1]
print(l[h][w]%1000000007)

### FIXED CODE ###

h,w=map(int,input().split())
l=[[0]*w]*h
m=[""]*h
for k in range(h):
  m[k]=input()
l[0][0]=1
for k in range(h):
  for j in range(w):
    if m[k][j]=="#":
      l[k][j]=0
    else:
      if k==0:
        if j!=0:
          l[k][j]=l[0][j-1]
      elif j==0:
        if k!=0:
          l[k][j]=l[k-1][j]
      else:
        l[k][j]=l[k-1][j]+l[k][j-1]
print(l[h-1][w-1]%1000000007)
input()
A=list(map(int,input().split()))
ans=0
while all(a%2==0 for a in A):
    A=[a/2 for a in A]
    ans+=1
print(ans)


### FIXED CODE ###

print(input().count("1"))
#include <stdio.h>
int main(void){
    long long int N, M;
    scanf("%lld %lld", &N, &M);
    long long int ans = (N+M/2)/2;
    printf("%lld\n", ans);
    return 0;
}

### FIXED CODE ###

# -*- coding:utf-8 -*-
N, M = map(int, input().split())
if M > 0:
    if N*2 <= M:
        print((N+M//2)//2)
    else:
        print(M//2)
else:
    print(0)
l = lsit(map(int, input().split(' ')))
s = lsit(map(int, input().split(' ')))

print(int((l[1]-s[1])*(l[0]-s[0])))

### FIXED CODE ###


l = list(map(int, input().split(' ')))
s = list(map(int, input().split(' ')))

print(int((l[1]-s[1])*(l[0]-s[0])))
total_price=0
C2=C*2

if C2<=A and C2<=B:
    total_price=C2*max(X,Y)

elif C2<=(A+B):
    if X>=Y:
        total_price=C2*Y
        X=X-Y
        Y=0
        total_price=total_price+A*X
    else:
        total_price=C2*X
        X=0
        Y=Y-X
        total_price=total_price+B*Y
        
else:
    total_price=A*X+B*Y
print(total_price)


### FIXED CODE ###

A, B, C, X, Y = map(int,input().split())
pattern1 = X*A + Y *B
pattern2 = X*(C*2) + B*(max(0,Y-X))
pattern3 = A*(max(0,X-Y)) + Y*(C*2)
print(min(pattern1,pattern2,pattern3))
import math

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

if S[0] != T[0]:
    print(-1)
    exit()

gcd = math.gcd(len(S), len(T))
lcm = len(S)*len(T) // gcd

if len(S) == len(T):
    if S == T:
        print(len(S))
    else:
        print(-1)
    exit()

for i in range(lcm):
    if N*i == M*i:
        if S[N*i] != T[M*i]:
            print(-1)
            exit()
print(lcm)


### FIXED CODE ###

import bisect

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

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


if S[0] != T[0]:
    print(-1)
    exit()

if len(S) == len(T):
    if S == T:
        print(len(S))
    else:
        print(-1)
    exit()

gcd1 = gcd(len(S), len(T))
lcm = len(S)*len(T) // gcd1

SS = []
TT = []
i = 0
j = 0
while i < N:
    SS.append(i*lcm//N + 1)
    i += 1
while j < M:
    TT.append(j*lcm//M + 1)
    j += 1

ind = 0
ind_max = j-1

for i,v in enumerate(SS):
    ind = bisect.bisect_left(TT, v,ind, j)
    if ind == j:
        break
#    print(ind)
    if TT[ind] == v:
        if S[i] == T[ind]:
            continue
        else:
            print(-1)
            exit()
print(lcm)
h,w = map(int,input().split())
S = [map(int,input().split()) for _ in range(h)]
for i,j in range():
  if S[i][j] == 'snuke':
    print((i)*w+j+1)
    break


### FIXED CODE ###

H, W = map(int, input().split())
S = [list(input().split()) for i in range(H)]

h = w = 0
for i in range(H):
    if 'snuke' in S[i]:
        h = i
        w = S[i].index('snuke')
        break
print(chr(ord('A') + w) + str(h + 1))
N = int(input())
dp = [None for _ in range(N)]
for i in range(N):
  p = int(input())
  if 0 <= p - 2 and dp[p - 2] == None:
    dp[p - 1] = 1
  else:
    dp[p - 1] = dp[p - 2] + 1
print(N - max(dp))

### FIXED CODE ###

N = int(input())
dp = [None for _ in range(N)]
for i in range(N):
  p = int(input())
  if dp[p - 2] == None or p == 1:
    dp[p - 1] = 1
  else:
    dp[p - 1] = dp[p - 2] + 1
print(N - max(dp))
N = int(raw_inpit())
T, A = map(int, raw_input().split())
Hs = list(map(int, raw_input().split()))

Ts = list(map(lambda x: T-x * 0.006), Hs)

i = 0
v = 0
for _i, _T in enumerate(Ts):
    if abs(_T-T) < v:
        v = abs(_T-T)
        i = _i

print(i)


### FIXED CODE ###

N = int(input())
T, A = map(int, input().split())
Hs = list(map(int, input().split()))

Ts = list(map(lambda x: T-x * 0.006, Hs))

i = 0
v = None
for _i, _T in enumerate(Ts):
    if v is None or abs(_T-A) < v:
        v = abs(_T-A)
        i = _i

print(i+1)