Harryxun/stf_run huggingface dataset:
A,B,C,D,E,F = map(int,input().split())
M = []
S = []

# 100A,100B の水
for a in range(1 + F // 100):
    for b in range(1 + F // 100):
        if 100 * (a * A + b * B) <= F:
            M.append(100 * (a * A + b * B))

# c,d の砂糖
for c in range(1 + F // C):
    for d in range(1 + F // D):
        if c * C + d * D <= F:
            S.append(c * C + d * D)

M=list(set(M))
S=list(set(S))
M.sort()
S.sort()

x = 0
for m in M:
  for s in S:
    if m != 0 and m + s <= F:
        sol = 100 * s / m
        if sol > x and sol <= E:
            x = sol
            X, Y = m + s, s

print(X,Y)


### FIXED CODE ###

A,B,C,D,E,F = map(int,input().split())
W = []
S = []

# 100A,100B の水
for a in range(1 + F // 100):
    for b in range(1 + F // 100):
        water = 100 * (a * A + b * B)
        if 0 < water <= F:
            W.append(water)

# c,d の砂糖
for c in range(1 + F // C):
    for d in range(1 + F // D):
        sugar = c * C + d * D
        if sugar <= F:
            S.append(sugar)

W = list(set(W))
S = list(set(S))

x = -1
for w in W:
    for s in S:
        if w + s <= F:
            sol = 100 * s / w
            if x < sol <= E:
                x = sol
                X, Y = w + s, s

print(X,Y)
a,b=int(input().split())

print(-((-b+1)//(a-1)))

### FIXED CODE ###

a,b=input().split()

print(-((-int(b)+1)//(int(a)-1)))
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    went = [0] * N
    went[0] = 1
    Flag = True
    check = [0]
    cnt = 1
    now = 0
    while Flag and (cnt <= K):
        now = A[now] - 1
        if went[now] == 1:
            ind = check.index(now) - 1
            cnt = cnt - ind - 1
            Flag = False
        else:
            check.append(now)
            went[now] = 1
            cnt += 1
            continue
    if len(check) >= K:
        print(check[K] + 1)
    else:
        K = (K - ind) % cnt
        print(check[ind + K] + 1)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    went = [0] * N
    went[0] = 1
    Flag = True
    check = [0]
    cnt = 1
    now = 0
    while Flag and (cnt <= K + 1):
        now = A[now] - 1
        if went[now] == 1:
            ind = check.index(now)
            if ind == 0:
                cnt = len(check)
            else:
                cnt = len(check) - ind

            Flag = False
        else:
            check.append(now)
            went[now] = 1
            cnt += 1
            continue

    if len(check) > K:
        print(check[K] + 1)
    else:
        if ind == 0:
            K = K % cnt
            print(check[K] + 1)
        else:
            ind -= 1
            K = (K - ind - 1) % cnt
            print(check[ind + K + 1] + 1)


if __name__ == "__main__":
    main()
a = raw_input().split()
b = [i for i in a if len(i)==3 or len(i)==4]
c = [i for i in b if ord(i[0])-ord(i[1]) == 12]
s = [ord('t')-ord(c[0][0]),1] if c[0][0]<'t' else [ord(c[0][0])-ord('t'),0]
q=''
for g,i in enumerate(a):
    if g==0:pass
    else: q+=' '
    for j in i:
        if j=='.':
            q+='.'
        elif s[1] == 0:
            q+=chr(ord(j)-s[0])
        elif s[0] == 1:
            q+=chr(ord(j)+s[0])
print q 

### FIXED CODE ###

import sys
a=lambda x: [''.join([chr(97+(ord(i)-97+j)%26) if i.islower() else i for i in x]) for j in range(26)]
value=['this','that','the']
for s in sys.stdin:
    for i in a(s):
        if sum(map(i.count,value))>0:
            print(i[:-1])
# -*- coding: utf-8 -*-
from bisect import bisect_left
from sys import stdin
from heapq import heappush, heappop



readl = stdin.readline
def main():
  ## input
  N,Q = map(int, readl().rstrip().split())
  STX = list(map(int, readl().rstrip().split())) for _ in range(N)]
  Dn = [None]*(Q+1)
  for i in range(Q):
    Dn[i] = int(readl().rstrip())
  Dn[Q] = 10**10
  ans = []

  for s,t,x in sorted(STX,key=lambda x:x[2]):
    l = r = bisect_left(Dn,s-x)
    t -= x
    while Dn[r] < t:
      heappush(ans, (Dn[r],x))
      r += 1
    del Dn[l:r]

  for d in Dn[:-1]:
    heappush(ans, (d,-1))

  return ans,Q


if __name__ == "__main__":
  ans,n = main()
  for _ in range(n):
    print(heappop(ans)[1])    


### FIXED CODE ###

import sys
from bisect import bisect_left



N,Q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:N]:
  s, t, x = map(int, line.split())
  kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[N:]))

ans = [-1] * Q
skip = [-1] * Q
for x, s, t in kkk:
  ss = bisect_left(ddd, s - x)
  tt = bisect_left(ddd, t - x)
  while ss < tt:
    sk = skip[ss]
    if sk == -1:
      ans[ss] = x
      skip[ss] = tt
      ss += 1
    else:
      ss = sk

print('\n'.join(map(str, ans)))
def resolve():
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])
        if temp!=1:
            arr.append([temp, 1])
        if arr==[]:
            arr.append([n, 1])
        return arr

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    import copy

    gcddict = {}
    adiv = []
    for i in range(n):
        primes = factorization(a[i])
        adiv.append(primes)
        for j in range(len(primes)):
            if primes[j][0] in gcddict:
                gcddict[primes[j][0]] = max(gcddict[primes[j][0]], primes[j][1])
            else:
                gcddict[primes[j][0]] = primes[j][1]
    ans = 0
    for i in range(n):
        val = 1
        test = copy.deepcopy(gcddict)
        primes = adiv[i]
        for j in range(len(primes)):
            test[primes[j][0]] -= primes[j][1]
        for k in test.keys():
            val *= pow(k, test[k], mod)
        ans += val
    print(ans % mod)
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    c = [[0] * 10 for i in range(10)]
    for i in range(n+1):
        b = i % 10
        for j in range(6):
            if i//(10**(j+1)) == 0:
                a = i//(10**j)
                break
        c[a][b] += 1
    ans = 0
    for i in range(1,10):
        for j in range(1,10):
            ans += c[i][j] * c[j][i]
    print(ans)
resolve()
n,k,q=map(int,input().split())	
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
for word in listA:
    a[word]-=1
result=[]
for i in range(len(a)):
    if a[i]<=0:
        result.append('No')
    else:
        result.append('Yes')
print(result)

### FIXED CODE ###

import numpy as np
n,k,q=map(int,input().split())	
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(int(input()))
    except:
        break;
a=np.repeat(k-q,n)
for word in listA:
    a[word-1]+=1
result=[]
for i in range(len(a)):
    if a[i]<=0:
        print('No')
    else:
        print('Yes')
# a: 総数hiki， b: 足の数
a, b = map(int, input().split())

# かめiひき
ans = 'No'
for i in range(a+1):
  total = 4*i + 2*(a+1-i)
  if total == b:
    ans = 'Yes'
    break

print(ans)

### FIXED CODE ###

a_list = list(map(int, input().split()))
print(1 + a_list.index(0))
N = int(input())
S,T = map(int,input().split())
l=[]
for i in range(N):
  l.append(S[i])
  l.append(T[i])
print("".join(l))

### FIXED CODE ###

N = int(input())
S,T = map(str,input().split())
l=[]
for i in range(N):
  l.append(S[i])
  l.append(T[i])
print("".join(l))
# ARC076C - Reconciled?
def factorial_mod(x):
    MOD = 10 ** 9 + 7
    ret = 1
    for i in range(1, x + 1):
        ret = (ret * i) % MOD
    return ret


def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    dif = abs(n - m)
    if dif > 1:  # must be ...DDM...
        print(0)
    else:
        if dif == 0:  # start with either D or M (DM..., MD...)
            ans = (factorial_mod(n) * factorial_mod(m) * 2) % MOD
        else:  # sandwich (DMD or MDM)
            ans = (factorial(n) * factorial(m)) % MOD
        print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# ARC076C - Reconciled?
from math import factorial


def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    dif = abs(n - m)
    if abs(n - m) not in (0, 1):
        print(0)
    else:
        if dif == 0:
            ans = (factorial(n) * factorial(m) * 2) % MOD
        else:
            ans = (factorial(n) * factorial(m)) % MOD
        print(ans)


if __name__ == "__main__":
    main()
def solve(N, W, weight_values):
  dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
  dp[0][0] = 1

  for i in range(N + 1):
    i_weight, i_value = weight_values[i - 1]
    for w in range(i_weight, W + 1):
      dp[i][w] = max(dp[i - 1][w - i_weight] + i_value, dp[i - 1][w])

  print(dp[N][W])

  
def iln(): return list(map(int, input().split()))


N, W = iln()
w_v = []
for i in range(N):
  w_v = iln()
  
solve(N, W, w_v)


### FIXED CODE ###


def solve(N, heights):
  dp = [float('inf')] * N
  dp[0] = 0
  for i in range(N - 1):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(heights[i] - heights[i + 1]))
    if i + 2 < N:
      dp[i + 2] = min(dp[i + 2], dp[i] + abs(heights[i] - heights[i + 2]))

  print(dp[N-1])

def iin(): return int(input())
def iln(): return list(map(int, input().split()))

solve(iin(), iln())
n = int(input())
s = list(input())
c = 0
b = s.count('#')
for i in range(n):
 if s[i] == '#' and s[i + 1] == '.':
  c += 1
  s[i +1] = '#'

print(min(c,b))

### FIXED CODE ###

n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1
  
  ans = min(ans,num)

print(ans)
# -*- coding: utf-8 -*-
import math
import sys
input = sys.stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return set(divisors)


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table


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

    divisors = []
    max_divisor = math.gcd(a, b)

    divisors = make_divisors(max_divisor)
    _, table = sieve(max(divisors))
    result = divisors & set(table)

    size = len(result) + 1
    print(size)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
import fractions


def prime_factorization(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n = n // i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return list(set(table))


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

    gcd = fractions.gcd(a, b)
    table = prime_factorization(gcd)
    print(len(table) + 1)


if __name__ == "__main__":
    main()
#python D-Partition.py
"""
入力フォーマット
N M

出力:a_1+...+a_N=Mを満たす数列aについてmax(GCD(a_1,...,a_N))
"""
import math
line = list(map(int, input().split(" ")))
N = int(line[0])
M = int(line[1])

#TLE(実行時間制限超過)のコード
"""
for i in range(math.floor(M/N),0,-1):
	tmp = M-i*(N-1)
	if tmp%i==0:
		print(i)
		break
"""

#TLEを何とかしたコード（ポイント：素数判定と同じ要領で探索範囲をO(sqrt(M))にした
for i in range(sqrt(M)):
	tmp = M-(math.floor(M/N)-i)*(N-1)
	if tmp%(math.floor(M/N)-i)==0:
		print((math.floor(M/N)-i))
		break


### FIXED CODE ###

#python Programming_Education.py

n = int(input())

if n==1:
	print("Hello World")
else:
	a = int(input())
	b = int(input())

	print(a+b)
N = int(input())
if N == 1:
    print('Hello World')
else:
    a = input(input())
    b = input(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)
N = int(input())
S = input()

ans = ''

for x in range(S)
	num=(ord(x) + N)
  	if(num >=90):
    	num=64+num%90
    ans += chr(num)
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
n_s = ""
for i in range(len(s)):
    if ord(s[i])+n > 90:
        n_s+=chr(ord(s[i])+n-26)
    else:
        n_s+=chr(ord(s[i])+n)
    
print(n_s)
a,b=map(int,input().split())
if a>b:print("GREATER")
elif a<b:print("LESS")
else:print("EQUAL")

### FIXED CODE ###

a=int(input())
b=int(input())
if a>b:print("GREATER")
elif a<b:print("LESS")
else:print("EQUAL")
from statistics import mean
import itertools
import math

n = int(input())
pos = [list(map(float,input().split())) for i in range(n)]

pos_comb = itertools.combinations(pos,2)
dis_list = []
for i in pos_comb:
    dis_list.append(math.sqrt((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1])**2))

print(mean(dis_list)*(float(n)-1.0))

### FIXED CODE ###

from statistics import mean
import itertools
import math

n = int(input())
pos = [list(map(float,input().split())) for i in range(n)]

pos_comb = itertools.combinations(pos,2)
dis_list = []
for i in pos_comb:
    dis_list.append(math.sqrt((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1])**2))

print(mean(dis_list)*(float(n)-1.0))
S = input()

formar = int(S[:2])
latter = int(S[2:])

if has_month_potential(formar) and not has_month_potential(latter):
    print('MMYY')
elif not has_month_potential(formar) and has_month_potential(latter):
    print('YYMM')
elif has_month_potential(formar) and has_month_potential(latter):
    print('AMBIGUOUS')
elif not has_month_potential(formar) and not has_month_potential(latter):
    print('NA')

### FIXED CODE ###

def has_month_potential(num):
    return num >= 1 and num <= 12

S = input()

formar = int(S[:2])
latter = int(S[2:])

if has_month_potential(formar) and not has_month_potential(latter):
    print('MMYY')
elif not has_month_potential(formar) and has_month_potential(latter):
    print('YYMM')
elif has_month_potential(formar) and has_month_potential(latter):
    print('AMBIGUOUS')
elif not has_month_potential(formar) and not has_month_potential(latter):
    print('NA')
N = int(input())
S = input()
lst = []
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if S[i]+S[j]+S[k] in lst:
                continue
            else:
                lst.append(S[i]+S[j]+S[k])
            if len(lst) = 999:
                print(len(lst))
                quit()
print(len(lst))

### FIXED CODE ###

N = int(input())
S = input()
lst = []
count = 0
for i in range(1000):
    num = str(i).zfill(3)
    if num[0] in S:
        a1 = S.index(num[0])
        if num[1] in S[a1+1:]:
            a2 = S[a1+1:].index(num[1]) + a1+1
            if num[2] in S[a2+1:]:
                count += 1
print(count)
a,b,c=map(int, input.split())
print(map(str(a b c)))

### FIXED CODE ###

x,y,z=map(int,input().split())
print(str(z)+" "+str(x)+" "+str(y))
# ABC052B - Increment Decrement
def main():
    _, S = tuple(input() for _ in range(2))
    ans, x = [0], 0
    for i in S:
        x += 1 i == "I" else -1
        ans += [x]
    print(max(ans))


if __name__ == "__main__":
    main()

### FIXED CODE ###

# ABC052B - Increment Decrement
_ = int(input())
s = input()
x = 0
lst = [0]
for i in s:
    if i == "I":
        x += 1
    else:
        x -= 1
    lst.append(x)
print(max(lst))
N = int(input())

Lx = 2
Ly = 1

if N == 1:
    print(Ly)
else:
    for i in range(N-1):
        tmp = Lx + Ly
        Lx = Ly
        Ly = tmp

print(tmp)


### FIXED CODE ###

N = int(input())

Lx = 2
Ly = 1

if N == 1:
    print(Ly)
else:
    for i in range(N - 1):
        tmp = Lx + Ly
        Lx = Ly
        Ly = tmp
    print(Ly)
import bisect
X,N=map(int,input().split())
P=list(map(int,input().split()))
hako=set(P)
kari=[]
if X<P[0]:
    print(X)
    exit()
if X>P[-1]:
    print(X)
    exit()
for i in range(102):
    if i not in hako:
        kari.append(i)
#print(kari)
kari.sort()
tekitpu=kari[bisect.bisect_left(kari,X)]
aho=kari[bisect.bisect_left(kari,X)-1]
#print(tekitpu,aho)
if abs(tekitpu-X)<abs(X-aho):
    print(tekitpu)
else:
    print(aho)


### FIXED CODE ###

X,N=map(int,input().split())
P=list(map(int,input().split()))
hako=set(P)
#print(hako)
ans=[]
P.sort()
kari=[]
for i in range(102):
    if i not in hako:
        kari.append(i)
for i in range(len(kari)):
    ans.append([abs(X-kari[i]),kari[i]])
ans.sort()
print(ans[0][1])
A = []
for a in input():
    if a == '0' or a == '1':
        A.append(a)
    else:
        del A[-1]
print(''.join(A))


### FIXED CODE ###

A = []
for a in input():
    if a == '0' or a == '1':
        A.append(a)
    elif len(A) > 0:
        del A[-1]
print(''.join(A))
import numpy as np
a,b = map(int, input().split())

x=np.array([['.']*100]*100,dtype=str)

x[:,:50]='#'

v1=(a-1)//20
v2=(a-1)-v1
w1=(b-1)//20
w2=(b-1)-w1

for i in range(v1):
    x[2*i+1,1:40:2]='.'

x[-1,1:2*v2:2]='.'

for i in range(w1):
    x[2*i+1,51:90:2]='#'
x[-1,51:50+w2*2:2]='#'

for i in range(100):
    print(''.join(x[i]))

### FIXED CODE ###

import numpy as np
a,b = map(int, input().split())

x=np.array([['.']*100]*100,dtype=str)

x[:,:50]='#'

v1=(a-1)//20
v2=(a-1)-v1*20
w1=(b-1)//20
w2=(b-1)-w1*20

for i in range(v1):
    x[2*i+1,1:40:2]='.'

x[-1,1:2*v2:2]='.'

for i in range(w1):
    x[2*i+1,51:90:2]='#'
x[-1,51:50+w2*2:2]='#'
print(100,100)
for i in range(100):
    print(''.join(x[i]))
a=int(input())
print("ABC"if a<1200)
print("ARC"if a<2800)
print("AGC"if a>2799)

### FIXED CODE ###

a=int(input())
if a<1200:
  print("ABC")
elif a<2800:
  print("ARC")
else:
  print("AGC")
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

if len(nums) == 0:
  print(N)
  exit()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect_left(nums,N[i])
      j = j if j != -1 else 0
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

### FIXED CODE ###

import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)] if len(N[:i])>0 else [1]
      N = tmp_N + [nums[0] for _ in range(prv_len-i)]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      N[i:] = [nums[j]] + [nums[0] for _ in range(len(N)-i-1)]
  #print(i,N)
  i -= 1
print(''.join([str(n) for n in N]))
#print(N)
N = int(input().strip())
x = []
y = []
h = []
for i in range(0, N):
    xi, yi, hi= [int(a) for a in input().strip().split()]
    x.append(xi)
    y.append(yi)
    h.append(hi)

def calc_H():
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = -1
            for i in range(0, N):
                Hi = h[i] + abs(x[i]-Cx) + abs(y[i]-Cy)
                if H == -1:
                    H = Hi

                if h[i] == 0:
                    if H < Hi:
                        break
                elif H != Hi:
                    break

                if i == N-1:
                    return Cx, Cy, H

print(*calc_H())

### FIXED CODE ###

N = int(input().strip())
xyh = []
for i in range(0, N):
    xi, yi, hi= [int(a) for a in input().strip().split()]
    xyh.append((xi, yi, hi))

xyh.sort(key = lambda t: t[2], reverse = True)

def calc_H():
    for Cx in range(0, 101):
        for Cy in range(0, 101):
            H = -1
            for i in range(0, N):
                Hi = xyh[i][2] + abs(xyh[i][0]-Cx) + abs(xyh[i][1]-Cy)
                if H == -1:
                    H = Hi

                if xyh[i][2] == 0:
                    if H > Hi:
                        break
                elif H != Hi:
                    break

                if i == N-1:
                    return Cx, Cy, H

print(*calc_H())
B,BC,CA=map(int,input().split())
print(AB*BC//2)

### FIXED CODE ###

AB, BC, CA = map(int, input().split())
print(AB * BC // 2)
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, M = MAP()

S = input()
T = input()

L = N*M//gcd(N, M)
check = ["_"]*L
check[0] = S[0]

for i in range(N):
	check[L//N * i] = S[i]

for j in range(M):
	if check[L//M * j] != "_" and check[L//M * j] != T[j]:
		print(-1)
		break
else:
	print(L)

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, M = MAP()

S = input()
T = input()

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

G = gcd(N, M)

n = N//G
m = M//G

for i in range(G):
	if S[::n][i] != T[::m][i]:
		print(-1)
		break
else:
	print(N*M//G)
def min(a,i):
  for t in range(0, i):
    if a[0] > a[t]:
      a[0] = a[t]
  return a[0]

def max(a,i):
  for t in range(0, i):
    if a[0] < a[t]:
      a[0] = a[t]
  return a[0]

def sum(a,i):
  for t in range(1, i):
    a[0] += a[t]
  return a[0]

i = int(raw_input())
a = map(int, raw_input().split())
print "%d %d %d" % (min(a,i) max(a,i) sum(a,i))

### FIXED CODE ###

def min(a,i):
  x = a[0]
  for t in range(0, i):
    if x > a[t]:
      x = a[t]
  return x

def max(a,i):
  y = a[0]
  for t in range(0, i):
    if y < a[t]:
      y = a[t]
  return y

def sum(a,i):
  s = 0
  for t in range(0, i):
    s += a[t]
  return s

i = int(raw_input())
a = map(int, raw_input().split())
print "%d %d %d" % (min(a,i), max(a,i), sum(a,i))
N, C = map(int, input().split())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))

times = [0] * 2 * (10 ** 5 + 1)
channel = [[0] * 2 * (10 ** 5 + 1) for _ in range(C)]
for i in range(N):
    s, t, c = items[i]
    c -= 1
    channel[c][2 * s - 1] += 1
    channel[c][2 * t] -= 1

for c in range(C):
    for i in range(len(times) - 1):
        channel[c][i + 1] += channel[c][i]
        if channel[c][i + 1] >= 1:
            times[i + 1] += 1

print(max(times))


### FIXED CODE ###

N, A, B = map(int, input().split())

print(min(A*N, B))
a,b,c=map(int,input().split())
print((a-b)%c)


### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
print((a-b)%c)