Harryxun/stf_run huggingface dataset:
n,m= map(int,input().split())
c = [True]*(n+1)
for _ in range(m):
    c[int(input())] = False
d = [0]*(n+1)
if c[1] : d[1] = 1
if c[2] : d[2] = d[1] + 1
for i in range(3,n+1):
    if c[i] :
        d[i] = ( d[i-1] + d[i-2] ) % 1000000007
print(d[n])

### FIXED CODE ###

# DP
mod = 1000000007
 
n, m = map(int, input().split())
b_list = [True] * (n+1)
dp = [0 for _ in range(n+1)]
for i in range(m):
    b_list[int(input())] = False
 
dp[0] = 1
for i in range(n):
    for j in range(i+1, min(n, i+2)+1):
        if b_list[j] == True:
            dp[j] += dp[i]
            dp[j] %= mod
# print(b_list)
# print(dp)
print(dp[n])
N,K=map(int,input(),split())
if N%K==0:
	print(0)
else:
	print(1)


### FIXED CODE ###

N, K=map(int, input(). split())
if N%K==0:
	print(0)
else:
	print(1)
def solve(n, s, k):
    return "".join([("*" if s[i] != s[k] else s[i]) for i in range(n)])

n = int(input())
s = input()
k = int(input())
print(solve(n, s, k))

### FIXED CODE ###

def solve(n, s, k):
    return "".join([("*" if s[i] != s[k-1] else s[i]) for i in range(n)])

n = int(input())
s = input()
k = int(input())
print(solve(n, s, k))
import collections
n=int(input())
s=[input() for _ in range(n)]
c=collections.Counter(s)
l=c.most_common()
k=l[0][1]
for i in range(n):
    if l[i][1]==k:print(l[i][0])
    else:exit()

### FIXED CODE ###

import collections
n=int(input())
s=[input() for _ in range(n)]
c=collections.Counter(s)
l=c.most_common()
k=l[0][1]
l1=[]
for i in range(len(l)):
    if l[i][1]==k:l1.append(l[i][0])
    else:break
l1.sort()
for i in range(len(l1)):
    print(l1[i])
from fractions import gcd

MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lcm = 1
for i in A:
    lcm = (lcm*i)//gcd(lcm,i)
lcm %= MOD
for i in A:
    ans += lcm//i
    ans %= MOD
print(ans)


### FIXED CODE ###

def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)

def func(x):
    if x <= 1:
        return []
    for i in range(2,int(x**0.5)+1):
        if x%i == 0:
            count = 0
            while x%i==0:
                x //= i
                count += 1
            return [[i,count]]+func(x)
    return [[x,1]]
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
lcm = [0]*(10**6)
for i in A:
    for a,b in func(i):
        lcm[a] = max(lcm[a],b)
L = 1
for i in range(2,10**6):
    L *= pow(i,lcm[i],MOD)
    L %= MOD
ans = 0
for i in A:
    ans += L*pow(i,MOD-2,MOD)
    ans %= MOD
print(ans)
N = int(input())
t = [0]*100000
x = [0]*100000
y = [0]*100000

for n in range(N):
    t[n+1], x[n+1], y[n+1] = map(int, input().split())

ans = True
for n in range(N):
    dt   = t[n+1] - t[n]
    dist = (x[n+1] - x[n]) + (y[n+1] - y[n])
    if dt < dist:
        ans = False
    if dt % 2 != dist % 2:
        ans = False
if ans:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import math
N = int(input())
T = [0]*110000
X = [0]*110000
Y = [0]*110000

for n in range(N):
    T[n+1], X[n+1], Y[n+1] = map(int, input().split())

res = True
for n in range(N):
    dt   = T[n+1] - T[n]
    dist = abs(X[n+1] - X[n]) + abs(Y[n+1] - Y[n])
    if dt < dist:
        res = False
    if dt % 2 != dist % 2:
        res = False

if res:
    print('Yes')
else:
    print('No')
N = int(input())
a = []
a = list(map(int,input().split()))
 
b = [0]*N
for i in reversed(range(N)):
    j = i + 1
    buf = b[i::j]
    if (sum(buf) % 2) != a[i]:
        b[i] = 1
print(sum(b))
bb = [i+1 for i in range(N) if b[i] == 1]
if sum(b) != 0:
    print(' '.join(map(str, bb)))

### FIXED CODE ###

r = int(input())

print(3 * r ** 2)
s = input()
a = s.split()
count = 0
j = len(s)
for i in range(j):
  if a[i] != a[j-i-1]:
    count += 1 
print(count)

### FIXED CODE ###

s = input()
n = len(s)
count = 0
for i in range(n//2):
  if s[i] != s[n - 1 - i]:
    count += 1 
print(count)
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:
    if um-lm<5:
        break

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)



### FIXED CODE ###

import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)
n=int(input())
a=[int(input()) for i in n]
print(sum(a)-max(a)/2)

### FIXED CODE ###

n=range(int(input()))
a=[int(input()) for i in n]
print(sum(a)-max(a)//2)
A,B,C,D,E=map(int,input().split())
    if A == 0:
        print(1)
    elif B == 0:
        print(2)
    elif C == 0:
        print(3)
    elif D == 0:
        print(4)
    else E == 0:
        print(5)

### FIXED CODE ###

A,B,C,D,E=map(int,input().split())

if A == 0:
    print(1)
elif B == 0:
    print(2)
elif C == 0:
    print(3)
elif D == 0:
    print(4)
else:
    print(5)
A,B=map(int,input().spliy())
if (A+B)%2==0:
  print((A+B)//2)
else:
  print('IMPOSSIBLE')


### FIXED CODE ###

A,B=map(int,input().split())
if (A+B)%2==0:
  print((A+B)//2)
else:
  print('IMPOSSIBLE')
s = list(input())
for i in range(len(s)):
  if i % 2 == 0:
    if not s[i] in "RUD":
      print ("No") 
      exit() 
  else: 
    if nit s[i] in "LUD":
      print("No")
      exit()
print("Yes"

### FIXED CODE ###

s = list(input())
for i in range(len(s)):
  if i % 2 == 0:
    if not s[i] in "RUD":
      print ("No") 
      exit() 
  else: 
    if not s[i] in "LUD":
      print("No")
      exit()
print("Yes")
import sys;

def init(n_):
    length = 1;
    while(length < n_):
        length*=2
    length2 = (2*length-2)
    if(length2 == 0):
        length2 = 1
    element=[0]*length2
    for i in range(length2):
        element[i] = 0
    return element,length

def update(k,a,element):
    k+=n-1
    if(n == 1):
        k = 0
    element[k]+=a
    while(k > 0):
        k = (int)((k-1)/2)
        element[k] = element[k*2+1]+element[k*2+2]

def findmin(a, b):
    return findquery(a,b+1,0,0,n)

def findquery(a, b, k, l, r):
    if(r <= a or b <= l):
        return 0
    if(a <= l and r <= b):
        return element[k]

    vl = findquery(a,b,k*2+1,l,(int)((l+r)/2+0.5))
    vr = findquery(a,b,k*2+2,(int)((l+r)/2),r)
    return vl+vr

n,q = map(int, input().split());

element,n = init(n)

for i in range(q):
    query,key,value = map(int, input().split());
    if(query == 0):
        update(key,value,element)
    else :
        if(n==1):
            key = 0
        print(findmin(key,value))


### FIXED CODE ###

import sys;

def init(n_):
    length = 1;
    while(length < n_):
        length*=2
    element = [0]*(2*length-1)
    for i in range(2*length-1):
        element[i] = 0
    return element,length

def update(k,a,element):
    k+=n-1
    element[k]+=a
    while(k > 0):
        k = (int)((k-1)/2)
        element[k] = element[k*2+1]+element[k*2+2]

def findmin(a, b):
    return findquery(a,b+1,0,0,n)

def findquery(a, b, k, l, r):
    if(r <= a or b <= l):
        return 0
    if(a <= l and r <= b):
        return element[k]

    vl = findquery(a,b,k*2+1,l,(int)((l+r)/2+0.5))
    vr = findquery(a,b,k*2+2,(int)((l+r)/2),r)
    return vl+vr

n,q = map(int, input().split());

element,n = init(n)

for i in range(q):
    query,key,value = map(int, input().split());
    if(query == 0):
        update(key-1,value,element)
    else :
        print(findmin(key-1,value-1))
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
flag=0
for i in range(N):
  if x[i]=>Y:
    flag+=1
for i in range(M):
  if y[i]=<X:
    flag+=1
if X>Y:
  flag+=1
if flag>0:
  print("War")
else:
  if min(y)>max(x):
    print("No War")
  else:
    print("War")

### FIXED CODE ###

N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
flag=0
for i in range(N):
  if x[i]>=Y:
    flag+=1
for i in range(M):
  if y[i]<=X:
    flag+=1
if X>Y:
  flag+=1
if flag>0:
  print("War")
else:
  if min(y)>max(x):
    print("No War")
  else:
    print("War")
import numpy

L, R = map(int, input().split())
l, r = L % 2019, R % 2019

if l > r or (R - L) >= 2019:
    print(0)
else:
    print(numpy.min([(i * j) % 2019 for i in range(l, r)　for j in range(i + 1, r + 1)]))

### FIXED CODE ###

import numpy

L, R = map(int, input().split())
l, r = L % 2019, R % 2019

if l > r or (R - L) >= 2019:
    print(0)
else:
    print(numpy.min([(i * j) % 2019 for i in range(l, r) for j in range(i + 1, r + 1)]))
N=int(input())
MOD=10**9+7
MAX=N+1
powerls=[0 for i in range(MAX)]
powerls[0]=1
powerls[1]=base                     
def powermod(ind):
  if powerls[ind]!=0:
    return powerls[ind]
  elif ind%2==0:
    p=(powermod(base,ind//2)**2)%MOD
    powerls[ind]=p
    return p
  else:
    p=((powermod(base,ind//2)**2)*base)%MOD     
    powerls[ind]=p
    return p

print((powermod(10,N)-2*powermod(9,N)+powermod(8,N))%MOD)


### FIXED CODE ###

N=int(input())
MOD=10**9+7
MAX=N+1
def powermod(base,ind):
  if ind==1:
    return base
  elif ind%2==0:
    return (powermod(base,ind//2)**2)%MOD
  else:
    return ((powermod(base,ind//2)**2)*base)%MOD

print((powermod(10,N)-2*powermod(9,N)+powermod(8,N))%MOD)
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
#if len(set(a)) == 1:
 # print(n//2)
 # sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
#print(K_a1)
K_a2 = c2.most_common()[0][0]
#print(K_a2)
F_a1 = c1.most_common(1)[0][1]
F_a2 = c2.most_common(1)[0][1]
if K_a1 == K_a2:
  if  c1.most_common(2)[0][1] >= c2.most_common(2)[0][1]:
    F_a2 = c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
   # print(F_a1)
print((l_a1 - F_a1)+(l_a2 - F_a2))

### FIXED CODE ###

import collections
import sys
n = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1:
  print(n//2)
  sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
K_a2 = c2.most_common()[0][0]
F_a1 = c1.most_common()[0][1]
F_a2 = c2.most_common()[0][1]
if K_a1 == K_a2:
  if  F_a1 > F_a2:
    F_a2 = c2.most_common()[1][1]
  elif F_a1 == F_a2:
    if  c1.most_common()[1][1] >  c2.most_common()[1][1]:
      F_a1 =  c1.most_common()[1][1]
    else:
      F_a2 =  c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
print((l_a1 - F_a1)+(l_a2 - F_a2))
a,b = map(int,list(input().split(" ")))
n = int(input())
c = [0 for i in range(1002)]
ans = 0
c[a]+=1
c[b]-=1
for i in range(n):
      s,f = map(int,list(input().split(" ")))
      c[s]+=1
      c[f]-=1
for i in range(1002):
      c[i+1] += c[i]
      if(c[i]>1):
            ans = 1
print(ans)


### FIXED CODE ###

a,b = map(int,list(input().split(" ")))
n = int(input())
c = [0 for i in range(1002)]
ans = 0
c[a]+=1
c[b]-=1
for i in range(n):
      s,f = map(int,list(input().split(" ")))
      c[s]+=1
      c[f]-=1
for i in range(1001):
      c[i+1] += c[i]
      if(c[i]>1):
            ans = 1
print(ans)
import sys

input = sys.stdin.readline

s = input()
dp = [[0]*13 for _ in range(len(s))]
if s[0] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(s[0])] = 1
for k in range(len(s)-1):
    if s[k+1] == '?':
        for i in range(13):
            for j in range(10):
                dp[k+1][((i*10%13)+j)%13] += dp[k][i]
                dp[k+1][((i*10%13)+j)%13] %= (10**9+7)
    else:
        for i in range(13):
            dp[k+1][((i*10%13)+int(s[k+1]))%13] += dp[k][i]
            dp[k+1][((i*10%13)+int(s[k+1]))%13] %= (10**9+7)
print(dp[-1][5])


### FIXED CODE ###

s = input()
dp = [[0]*13 for _ in range(len(s))]
if s[0] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(s[0])] = 1
for k in range(len(s)-1):
    if s[k+1] == '?':
        for i in range(13):
            for j in range(10):
                dp[k+1][((i*10%13)+j)%13] += dp[k][i]
                dp[k+1][((i*10%13)+j)%13] %= (10**9+7)
    else:
        for i in range(13):
            dp[k+1][((i*10%13)+int(s[k+1]))%13] += dp[k][i]
            dp[k+1][((i*10%13)+int(s[k+1]))%13] %= (10**9+7)
print(dp[-1][5])
N = int(input())
S = input()
n = N // 2
if S[:n] == S[n:]:
    print('Yes')
else:s
    print('No')


### FIXED CODE ###

N = int(input())
S = input()
n = N // 2
if S[:n] == S[n:]:
    print('Yes')
else:
    print('No')
S = list(input())
for i in range(len(S)):
  if i % 2 == 0:
   	if s[i] == "R" or "U" or "D":
      continue
   	else:
      print("No")
      break
  else:
    if s[i] == "L" or "U" or "D":
      continue
    else:
      print("No")
      break
  print("Yes")

### FIXED CODE ###

S = list(input())
for i in range(len(S)):
	if i % 2 == 0:
		if (S[i] == "R") or(S[i] ==  "U") or(S[i] ==  "D"):
			continue
		else:
			print("No")
			exit()
	else:
		if (S[i] == "L") or(S[i] ==  "U") or(S[i] ==  "D"):
			continue
		else:
			print("No")
			exit()
print("Yes")
n,x = map(int,input().split())

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

dis = 0
i = 0

while True:
    dis += l[i]
    
    if dis > x:
        break
    i += 1

print(i+1)

    
    

### FIXED CODE ###

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

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

cnt = 1
dis = 0

for i in l:
    dis += i
    if dis > x:
        break
    cnt += 1

print(cnt)
if x = 0:
  print(1)
else:
  print(0)

### FIXED CODE ###

s = int(input()) 
if s == 0:
  print(1)
else:
  print(0)
from math import gcd
a, b = map(int,input().split())
print(a * b // gcd(a,b))

### FIXED CODE ###

from fractions import gcd
a, b = map(int,input().split())
print(a * b // gcd(a,b))
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])
ans, num = 1, []

if len(pla) == 0 and k % 2 == 1:
    for i in mia[:k]:
        ans = ans * i % mod
    print(ans)
    exit()

for _ in range(k):
    if len(mia) > 0 and len(pla) > 0:
        if abs(mia[-1]) <= pla[-1]:
            tmp = pla.pop()
        elif abs(mia[-1]) > pla[-1]:
            tmp = mia.pop()
    elif len(mia) == 0:
        tmp = pla.pop()
    elif len(pla) == 0:
        tmp = mia.pop()
    num.append(tmp)

cnt = sum(i < 0 for i in num)
for i in num:
    ans = ans * i % mod

if cnt % 2 == 1:
    if len(mia) > 0:
        for i in num[::-1]:
            if i >= 0:
                a, b = i, mia.pop()
                break
        if len(pla) == 0:
            ans *= b * pow(a, mod - 2, mod)
    if len(pla) > 0:
        for i in num[::-1]:
            if i < 0:
                c, d = i, pla.pop()
                break
        if len(mia) == 0:
            ans *= d * pow(c, mod - 2, mod)
    if len(mia) > 0 and len(pla) > 0:
        if a * d >= b * c:
            ans *= d * pow(c, mod - 2, mod)
        if a * d < b * c:
            ans *= b * pow(a, mod - 2, mod)
    ans %= mod
print(ans)


### FIXED CODE ###

#with open('random_pm00.txt') as f:
    #n, k = map(int, f.readline().split())
    #a = list(map(int, f.readline().split()))
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

mia, pla = [], []
for ai in a:
    if ai < 0:
        mia.append(ai)
    elif ai >= 0:
        pla.append(ai)
mia.sort(reverse=True)
pla.sort()

cnt = 1
if len(pla) == 0 and k % 2 == 1:
    for i in mia[:k]:
        cnt = cnt * i % mod
else:
    while k > 0:
        if k == 1 or len(mia) <= 1:
            if len(pla) == 0:
                cnt = cnt * mia.pop() % mod
            elif len(pla) > 0:
                cnt = cnt * pla.pop() % mod
            k -= 1
        elif len(pla) <= 1:
            if k == 1:
                cnt = cnt * pla.pop() % mod
                k -= 1
            elif k > 1:
                cnt = cnt * mia.pop() * mia.pop() % mod
                k -= 2
        elif len(pla) >= 2 and len(mia) >= 2:
            if pla[-1] * pla[-2] > mia[-1] * mia[-2]:
                cnt = cnt * pla.pop() % mod
                k -= 1
            elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
                cnt = cnt * mia.pop() * mia.pop() % mod
                k -= 2
print(cnt)
a,b,c=input()
print(c+" "+a+""+b)

### FIXED CODE ###

a,b,c= input().split()
print(c+" "+a+" "+b)
N, M = map(int, input().split())
def fib(n) :
    if n==1 :
        return 1
    elif n==0 :
        return 1
    else :
        return fib(n-1) + fib(n-2)
a=[]
b=1

for i in range(M):
    a.append(int(input()))
    if a[i]-a[i-1] == 1 :
        b=0

def rest(num) :
    return num % 1000000007
c=0
if b==0 :
    print(c)
else :
    for i in range(M+1):
        if i == 0 == M :
            c += rest(fib(N))
        elif i == 0:
            c += rest(fib(a[i]-1))
        elif i == M:
            c = rest(c * fib(N-a[i-1]-1))
        else :
            c = rest(c * fib(a[i]-a[i-1]-2))
    print(c)


### FIXED CODE ###

N, M = map(int, input().split())
def fib(n) :
    a, b = 1, 1
    if n==0 :
        return a
    elif n==1 :
        return b
    else :
        for i in range(n-1):
            a, b = b, a+b
        return b
a=[]
b=1

for i in range(M):
    a.append(int(input()))
    if a[i]-a[i-1] == 1 :
        b=0

def rest(num) :
    return num % 1000000007
c=0
if b==0 :
    print(c)
else :
    for i in range(M+1):
        if i == 0 == M :
            c += rest(fib(N))
        elif i == 0:
            c += rest(fib(a[i]-1))
        elif i == M:
            c = rest(c * fib(N-a[i-1]-1))
        else :
            c = rest(c * fib(a[i]-a[i-1]-2))
    print(c)
import math

R = (input())
print(2*math.pi*R)

### FIXED CODE ###

import math
R = int(input())
print(2*math.pi*R)
A, B = map(int, input().split())
c = math.ceil((B - A) / (B - 1))
print(c + 1)

### FIXED CODE ###

A, B = map(int, input().split())
import math
c = math.ceil((B - A) / (A - 1))
print(c + 1)
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,m = I()
s = v()
t = v()
l = lcm(n,m)
x = l//n
y = l//m
p = [-1]*l
k = 0
b = 0
for i in range(0,n,x):
    p[i]=s[k]
    k += 1

for j in range(0,m,y):
    if p[j] != -1 and p[j] != t[b]:
        print(-1)
        sys.exit()
    else:
        p[j]=t[b]
    b += 1

print(l)


### FIXED CODE ###

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,m = I()
s = v()
t = v()
l = lcm(n,m)
g = math.gcd(n,m)

for i in range(g):
    if s[n//g*i] != t[m//g*i]:
        print(-1)
        sys.exit()

print(l)
import numpy as np
import collections
N = int(input())
D = [int(i) for i in input().split()]+[0, 24]

C = collections.Counter(D)
if C.most_common()[0][1] >= 3:
    print(0)
    exit()


ans = 0
for i in range(2 ** N):
    D0 = D
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            D0[j] = 24-D0[j]

        D0 = np.sort(np.array(D0))
        c = np.amin(np.diff(D0))
    ans = max(ans, c)

print(ans)


### FIXED CODE ###

import collections
import copy
N = int(input())
D = [int(i) for i in input().split()]

C = collections.Counter(D)
if C.most_common()[0][1] >= 3:
    print(0)
    exit()

D1 = [0, 24]
m = []
for k, v in C.items():
    if v == 2:
        D1.append(k)
        D1.append(24-k)
    elif v == 1:
        m.append(k)

ans = 0
for i in range(2 ** len(m)):
    D0 = copy.deepcopy(D1)
    for j in range(len(m)):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            D0.append(24-m[j])
        else:
            D0.append(m[j])

    # print(D0)

    D0 = sorted(D0)
    c = 24
    for i in range(N+1):
        c = min(c, D0[i+1]-D0[i])
    ans = max(ans, c)

print(ans)
n,k=map(int,input().split())
td=sorted([list(map(int,input().split())) for i in range(n)],reverse=True,key=lambda x:x[1])
#print(td)
ans=0
kinds=dict()
for i in range(k):
    ans+=td[i][1]
    if td[i][0] in kinds:
        kinds[td[i][0]].append(td[i][1])
    else:
        kinds[td[i][0]]=[td[i][1]]
ans+=(len(kinds)**2)
#kindsの中はソートされている状況
#print(kinds)
ans_=[ans]
for i in range(k,n):
    if td[i][0] not in kinds:
        mi=[1000000000,1000000000]
        for j in kinds:
            if len(kinds[j])>1:
                if mi[1]>kinds[j][-1]:
                    mi=[j,kinds[j][-1]]
        if mi=[1000000000,1000000000]:
            break
        else:
            ans=ans-len(kinds)**2+(len(kinds)+1)**2-mi[1]+td[i][1]
            kinds[mi[0]].pop(-1)
            kinds[td[i][0]]=[td[i][1]]
            ans_.append(ans)
#print(kinds)
print(max(ans_))

### FIXED CODE ###

n,k=map(int,input().split())
td=sorted([list(map(int,input().split())) for i in range(n)],reverse=True,key=lambda x:x[1])

ans=0
kl=dict()
for i in range(k):
    ans+=td[i][1]
    if td[i][0] in kl:
        kl[td[i][0]]+=1
    else:
        kl[td[i][0]]=1
l=len(kl)
ans+=(l**2)
ans_=ans
now=k-1
for i in range(k,n):
    if td[i][0] not in kl:
        #最小を求めるのをもっと早く
        while now>=0:
            if kl[td[now][0]]>1:
                mi=td[now]
                kl[mi[0]]-=1
                now-=1
                break
            now-=1
        if now==-1:
            break
        else:
            ans=ans+2*l+1-mi[1]+td[i][1]
            kl[td[i][0]]=1
            ans_=max(ans,ans_)
            l+=1

print(ans_)
N, M = map(int, input().split())
print((N-2)(M-2))

### FIXED CODE ###

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

if(N == 1 or M == 1):
    if(M == 1 and N == 1):
        print(1)
    else:
        print(max(M-2, N-2))
else:
    print((N-2)*(M-2))
a = str(input())
if a=="000":
    print(0)
eif a=="001" or "010" or "100":
    print(1)
elif a=="111":
    print(3)
else:
    print(2) 

### FIXED CODE ###

a = int(input())
print(a%9)
mxn = 10**6 + 11
arr = []
for i in range(1,mxn):
    if i % 3 == 0 and i % 5 == 0:
        arr.append(0)
    elif i % 3 == 0:
        arr.append(0)
    elif i%5 == 0:
        arr.append(0)
    else:
        arr.append(i)

n = int(input())
print(sum[:n])


### FIXED CODE ###

mxn = 10**6 + 11
arr = []
for i in range(1,mxn):
    if i % 3 == 0 and i % 5 == 0:
        arr.append(0)
    elif i % 3 == 0:
        arr.append(0)
    elif i%5 == 0:
        arr.append(0)
    else:
        arr.append(i)

n = int(input())
print(sum(arr[:n]))
num = str(input())
for i in range(3):
    if num[i] == '1':
        num[i] = '9'
    else:
        num[i] = '1':
answer = num[0]+num[1]+num[2]
print(int(answer))

### FIXED CODE ###

a = input()
b = []
for i in range(3):
    if a[i] == '1':
        b.append('9')
    else:
        b.append('1')
print(''.join(b))