Harryxun/stf_run huggingface dataset:
def resolve():
    '''
    code here
    '''
    from functools import lru_cache

    N, M = [int(item) for item in input().split()]
    As = [int(input()) for _ in range(M)]
    memo = [False for _ in range(N+1)]

    for item in As:
        memo[item] = True

    res_list = []

    prev = 0
    for i in range(1,N+1):
        if memo[i] == True:
            res_list.append(i-1 - prev)
            prev = i+1
    else:
        if memo[N] == False and memo[N] == False:
            res_list.append(N - prev)

    @lru_cache
    def cal(num):
        if 0 <= num <= 1:
            return 1
        elif num == -1:
            return 0
        else:
            return cal(num-1) + cal(num-2)
    # print(res_list)
    res = 1
    for item in res_list:
        res *= cal(item)

    print(res % (10**9 + 7))



if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    from functools import lru_cache
    import sys
    sys.setrecursionlimit(10**6)

    N, M = [int(item) for item in input().split()]
    As = [int(input()) for _ in range(M)]
    memo = [False for _ in range(N+1)]

    for item in As:
        memo[item] = True

    res_list = []

    prev = 0
    for i in range(1,N+1):
        if memo[i] == True:
            res_list.append(i-1 - prev)
            prev = i+1
    else:
        if memo[N] == False and memo[N] == False:
            res_list.append(N - prev)

    @lru_cache
    def cal(num):
        if 0 <= num <= 1:
            return 1
        elif num == -1:
            return 0
        else:
            return cal(num-1) + cal(num-2)
    # print(res_list)
    res = 1
    for item in res_list:
        res *= cal(item)% (10**9 + 7)

    print(res % (10**9 + 7))



if __name__ == "__main__":
    resolve()
n = int(input())
p = [int(x) for x in input.split()]
ans = 0
mn = n
for i in p:
  if mn > i:
    mn = i
  if mn >= i:
    ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
p = [int(x) for x in input().split()]
ans = 0
mn = n
for i in p:
  if mn > i:
    mn = i
  if mn >= i:
    ans += 1
print(ans)
n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = raw_input().split()
  u = int(str[0])
  k = int(str[1])
  for j in range(k):
    v = int(str[2+j])
    c = int(str[3+j])
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]

d[0] = 0
color[0] = 1

for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])

### FIXED CODE ###

n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  for j in range(k):
    v = str[2+2*j]
    c = str[3+2*j]
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]
 
d[0] = 0
color[0] = 1
 
while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])
str = input()
if str.isupper()==TRUE:
  print("A")
else:
  print("a")

### FIXED CODE ###

str = input()
if str.isupper()==True:
  print("A")
else:
  print("a")
n = int(input())
s=[]
for i in range(n):
    s.append(input())

list_s = []
for j in range(n):
    #list_s.append(sorted(list(s[j])))
    list_s.append(''.join(sorted(s[j])))

m = {}
for i in range(n):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
  
count = 0
for k in range(len(m)):
        count += cmb( m[list_s[k]], 2 )


print(count)

### FIXED CODE ###

n = int(input())
s=[]
for i in range(n):
    s.append(input())

list_s = []
for j in range(n):
    #list_s.append(sorted(list(s[j])))
    list_s.append(''.join(sorted(s[j])))

m = {}
for i in range(n):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

def cmb(num):
    if num == 1:
        return 0
    elif num == 2:
        return 1
    else:
        return (num * (num-1) // 2)
  
count = 0
for k in m.keys():
        count += cmb( m[k] )


print(count)
import sys

args = sys.argv
a = int(args[1])
b = int(args[2])

def P(x,y):
 print(x*y)
 print(2*x+2*y)
 return 0

P(a,b)

### FIXED CODE ###

t = input()
t = t.split()
a = int(t[0])
b = int(t[1])

def P(x,y):
 print(x*y,2*(x+y))
 return 0

P(a,b)
from bisect import bisect_right, bisect_left

N,K = map(int,input().split())
A = sorted(map(int,input().split()))

t0 = bisect_left(A,0)
t1 = bisect_right(A,0)
pos = A[t1:]
neg = [-v for v in reversed(A[:t0])]
zeros = t1-t0
offset_negative = len(pos)*len(neg)
offset_zero = zeros*(N-zeros) + zeros*(zeros-1)//2
offset = offset_zero + offset_negative

def bisect2(ng, ok, judge):
    while abs(ng-ok) > 1:
        m = (ng+ok)//2
        if judge(m):
            ok = m
        else:
            ng = m
    return ok

def count1(l,n):
    j = len(l)
    cnt = 0
    for i,a in enumerate(l):
        v = n//a
        while j > i and l[j-1] > v:
            j -= 1
        if j <= i:
            break
        else:
            cnt += j-i-1
    return cnt

def count2(l1,l2,n):
    j = len(l2)
    cnt = 0
    for i,a in enumerate(l1):
        v = n//a
        while j > 0 and l2[j-1] > v:
            j -= 1
        cnt += j
    return cnt


def cnt(n):
    if n > 0:
        cnt = count1(pos,n-1) + count1(neg,n-1) + offset
    else:
        cnt = offset_negative - count2(pos,neg,-n)
    return cnt


if offset_negative <= K < offset:
    print(0)
else:
    temp = max(pos[-1],neg[-1])**2
    print(bisect2(temp, -temp, lambda n: cnt(n) <= K-1))

# from itertools import combinations
# s = sorted(a*b for a,b in combinations(A,2))
# for i,v in enumerate(s):
#     print(cnt(v),i,v)

### FIXED CODE ###

from bisect import bisect_right, bisect_left

N,K = map(int,input().split())
A = sorted(map(int,input().split()))

t0 = bisect_left(A,0)
t1 = bisect_right(A,0)
pos = A[t1:]
neg = [-v for v in reversed(A[:t0])]
zeros = t1-t0
offset_negative = len(pos)*len(neg)
offset_zero = zeros*(N-zeros) + zeros*(zeros-1)//2
offset = offset_zero + offset_negative

def bisect2(ng, ok, judge):
    while abs(ng-ok) > 1:
        m = (ng+ok)//2
        if judge(m):
            ok = m
        else:
            ng = m
    return ok

def count1(l,n):
    j = len(l)
    cnt = 0
    for i,a in enumerate(l):
        v = n//a
        while j > i and l[j-1] > v:
            j -= 1
        if j <= i:
            break
        else:
            cnt += j-i-1
    return cnt

def count2(l1,l2,n):
    j = len(l2)
    cnt = 0
    for i,a in enumerate(l1):
        v = n//a
        while j > 0 and l2[j-1] > v:
            j -= 1
        cnt += j
    return cnt


def cnt(n):
    if n > 0:
        cnt = count1(pos,n-1) + count1(neg,n-1) + offset
    else:
        cnt = offset_negative - count2(pos,neg,-n)
    return cnt


if offset_negative < K <= offset:
    print(0)
else:
    temp = max(abs(a) for a in A)**2
    print(bisect2(temp, -temp, lambda n: cnt(n) <= K-1))

# from itertools import combinations
# s = sorted(a*b for a,b in combinations(A,2))
# for i,v in enumerate(s):
#     print(cnt(v),i,v)
def main():
    import sys
    inl = sys.stdin.buffer.readline
    
    n= int(input())
    tmp = 0
    for _ in range(n):
        l,r = map(int,inl().split())
        if(l==r):
            tmp+=1
            if(tmp==3):
                print("Yes")
                return
        else:
            tmp =0
        


        


    




















if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    import sys
    ikimasu = sys.stdin.buffer.readline
    ini = lambda: int(ins())
    ina = lambda: list(map(int, ikimasu().split()))
    ins = lambda: ikimasu().strip()
    
    n= ini()
    tmp = 0
    for _ in range(n):
        l,r = ina()
        if(l==r):
            tmp+=1
            if(tmp==3):
                print("Yes")
                return
        else:
            tmp =0
    print("No")
        


        


    




















if __name__ == "__main__":
    main()
S = input()
print(S.count(+) - S.count(-))

### FIXED CODE ###

S = input()
print(S.count("+") - S.count("-"))
K = int(input())

if K < 9:
    for i in range(1,K+1):
        print(i)
else:
    for i in range(1,9):
        print(i)
    for i in range(K-8):
        print((i+1) * 10 -1)


### FIXED CODE ###

S = input()
result = 0
for i in S:
    if i == "+":
        result += 1
    else:
        result -= 1
print(result)
N = int(input())
A = list(map(int, input().split()))

cost = 0
for i in range(N):
  temp_A = [0] + [A[x] for x in range(N) if x != (i+1)] + [0]
  print(temp_A)
  for j in range(N):
    cost += abs(temp_A[j+1] - temp_A[j])
  print(cost)
  cost = 0

### FIXED CODE ###

a = input()
b = input()
c = input()
d = input()
print(min((int(a), int(b))) + min((int(c), int(d))))
#xが所持金
#a * n + b *nの桁数
a,b,x =map(int,input().split())

if a+b>x:
  print(0)
  exit()

if a*(10**9)+b*10<=x:
  print(10**9)
  exit()
  
  
for i in range(10):
  if (a*(10**i)+b*len(str(10**i))<=x and a*(10**(i+1))+b*len(str(10**(1+i))) >x) or i==9:
    kagen=10**i
    jougen=min(10**9,10**(i+1))
    
    atai=kagen+jougen//2
    
    while 1:
      #print(kagen,atai,jougen)
      if a*atai+b*len(str(atai))<=x and a*(atai+1)+b*len(str((1+atai))) >x:
        print(atai)
        exit()
      if a*atai+b*len(str(atai))<=x:
        kagen=atai
        atai=(atai+jougen)//2
      else:
        jougen=atai
        atai=(kagen+atai)//2
        
    



      
  


### FIXED CODE ###

s=input()

days=["SUN","MON","TUE","WED","THU","FRI","SAT"]

print(7-days.index(s))
N = input()

if N[0] =- N[2]:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = input()

if N[0] == N[2]:
  print('Yes')
else:
  print('No')
N,X,T=map(int, input().split())
if N%X==0:
  print(N/X*T)
  else:
  print((int(N/X)+1)*T)
  

### FIXED CODE ###

N,X,T=map(int, input().split())
if N%X==0:
  print(int(N/X*T))
else:
  print((int(N/X)+1)*T)
A, B = map(int, input().split())

if A % 2 != B % 2:
  K = "IMPOSSIBLE"
elif:
  # A - K = - (B - K)
  # 2K = A + B
  K = int((A + B) / 2)
print(K)
  

### FIXED CODE ###

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

if A % 2 != B % 2:
  K = "IMPOSSIBLE"
else:
  # B - K = - (A - K)
  # 2K = B - A
  K = int((B + A) / 2)
print(K)
N = int(input())
if N == 1:
	print("Hello World")
else:
	A = int(input())
    B = int(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)
a, b, c, d = map(int, input().split())

# ans = b-(a-1) - (b//c - (a-1)//c) - (b//d - (a-1)//d) + (b//(c*d) - (a-1)//(c*d))
ans = b - b//c - b//d + b//(c*d) - (a-1 - (a-1)//c - (a-1)//d + (a-1)//(c*d))

print(ans)


### FIXED CODE ###

s = str(input())
_s = s[0]
ans = 'Good'

for x in s[1:]:
    if x == _s:
        ans = 'Bad'
        break
    _s = x

print(ans)
float(input())
print(float(r*r*math.pi),float(2*r*math.pi))


### FIXED CODE ###

from math import pi
r = float(input())
print("{:.010f} {:.010f}".format(r * r * pi, 2 * pi * r))
from sys import stdin
input = stdin.readline
def BFS(K,path,N):
  """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""
  import queue
  dist=[-1]*N
  dist[K]=0
  que=queue.Queue()
  que.put(K)
  while que.qsize():
    label=que.get()
    for i,c in path[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        que.put(i)
  return dist
 
N=int(input())
path=[ [] for i in range(N)]
for i in range(N-1):
  a,b,c=map(int,input().split())
  path[a-1]+=[(b-1,c)]
  path[b-1]+=[(a-1,c)]
Q,K=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(Q)]
distance=BFS(K-1,path,N)
for i in range(Q):
  print(distance[xy[i][0]-1]+distance[xy[i][1]-1])

### FIXED CODE ###

n,m=map(int,input().split())
print((n-1)*(m-1))
def keta1(n):
    s = str(n)
    return (len(s) - 1) * 9 + int(s[0])
 
def keta2(n):
    if n < 10:
      return 0
    s = str(n)
    cnt = [0] * 101
    for i in range(2, 101):
        cnt[i] = 9 * 9 * (i - 1)
    res = 0
    for i in range(len(s)):
        res += cnt[i]
    res += (int(s[0]) - 1) * keta1(10 ** (len(s) - 1) - 1) + keta1(int(s[1:]))
    return res
 
def keta3(n):
    s = str(n)
    cnt = [0] * 101
    for i in range(3, 101):
        cnt[i] = 9 * 9 * 9 * (i - 1) * (i - 2) // 2
    res = 0
    for i in range(len(s)):
        res += cnt[i]
    res += (int(s[0]) - 1) * keta2(10 ** (len(s) - 1) - 1) + keta2(int(s[1:]))
    return res
 
if K == 1:
    print(keta1(N))
elif K == 2:
    print(keta2(N))
elif K == 3:
    print(keta3(N))
        

### FIXED CODE ###

N = int(input())
K = int(input())
 
def keta1(n):
    s = str(n)
    return (len(s) - 1) * 9 + int(s[0])
 
def keta2(n):
    if n < 10:
      return 0
    s = str(n)
    cnt = [0] * 101
    for i in range(2, 101):
        cnt[i] = 9 * 9 * (i - 1)
    res = 0
    for i in range(len(s)):
        res += cnt[i]
    res += (int(s[0]) - 1) * keta1(10 ** (len(s) - 1) - 1) + keta1(int(s[1:]))
    return res
 
def keta3(n):
    s = str(n)
    cnt = [0] * 101
    for i in range(3, 101):
        cnt[i] = 9 * 9 * 9 * (i - 1) * (i - 2) // 2
    res = 0
    for i in range(len(s)):
        res += cnt[i]
    res += (int(s[0]) - 1) * keta2(10 ** (len(s) - 1) - 1) + keta2(int(s[1:]))
    return res
 
if K == 1:
    print(keta1(N))
elif K == 2:
    print(keta2(N))
elif K == 3:
    print(keta3(N))
a,b,c,d=map(int,input().split())
if abs(a-c)<= d:
  print("Yes")
elif abs(a-b)<=d and abs(b-c)<=d:
  print("Yes")
else:
  print("No"

### FIXED CODE ###

a,b,c,d=map(int,input().split())
if abs(a-c)<= d:
  print("Yes")
elif abs(a-b)<=d and abs(b-c)<=d:
  print("Yes")
else:
  print("No")
s = input()
t = input()

count = 0
for i in range(s):
  if s[i] == t[i]:
    count += 1
    
print(count)

### FIXED CODE ###

s = input()
t = input()

count = 0
for i in range(len(s)):
  if s[i] == t[i]:
    count += 1
    
print(count)
import collections
import math
import re
import numpy


def ai():return input()#s
def a():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
s=0
c=0
e =1
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")
#def rep(i):return for i in range()
a = a()
x = lma()
l = set(x)
m=1
tn = 0
for i in l:
    if i- tn==1:
        ta = tb
        tb = tc
        tc = x.count(i+1)
    else:
        ta = x.count(i-1)
        tb = x.count(i)
        tc = x.count(i+1)
    t = ta+tb+tc
    m=max(m,t)
    if m>=len(x):break
    tn = i
print(m)






### FIXED CODE ###

def abc072_c():
    from collections import Counter
 
    _ = int(input())
    a = list(map(int, input().split()))
    a_ex = []
    for num in a:
        a_ex.append(num)
        a_ex.append(num-1)
        a_ex.append(num+1)
 
    print(max(Counter(a_ex).values()))
 
 
abc072_c()
[n, k] = [int(x) for x in input().split()]

prob = 0

for i in range(n):
    
    num = math.ceil(math.log2(k/(i+ 1)))
    
    if num < 0:
        num = 0
    prob += 1 / n * ((1 / 2) ** num)
    
print(prob)

### FIXED CODE ###

import math

[n, k] = [int(x) for x in input().split()]

prob = 0

for i in range(n):
    
    num = math.ceil(math.log2(k/(i+ 1)))
    
    if num < 0:
        num = 0
    prob += 1 / n * ((1 / 2) ** num)
    
print(prob)
r,g,b = map(str,input().split())
list_C = [r,g,b]
num = int(''.join(list_c))
if num%4 == 0:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

r,g,b = map(str,input().split())
list_C = [r,g,b]
num = int(''.join(list_C))
if num%4 == 0:
    print('YES')
else:
    print('NO')
A = input()
B = input()
C = A * B
print(C)

### FIXED CODE ###

a, b = map(int, input().split())
print(a * b)
n,m=map(int,input().split())
inf=float("inf")

r=lambda n:range(n)
l=[[inf if i!=j else 0 for j in r(n)] for i in r(n)]
a,b,c=[None]*n,[None]*n,[None]*n

for i in r(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
  l[a[i]][b[i]]=min(l[a[i]][b[i]],c[i])
  l[b[i]][a[i]]=min(l[b[i]][a[i]],c[i])

for k in r(n):
  for i in r(n):
    for j in r(n):
      l[i][j]=min(l[i][j],l[i][k]+l[k][j])

ans=m
for i in r(m):
  f=False
  for j in r(n):
    if l[j][a[i]]+c[i]==l[j][b[i]]:
      f=True
  if f:ans-=1
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
inf=float("inf")

r=lambda n:range(n)
l=[[inf if i!=j else 0 for j in r(n)] for i in r(n)]
a,b,c=[None]*m,[None]*m,[None]*m

for i in r(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
  l[a[i]][b[i]]=c[i]
  l[b[i]][a[i]]=c[i]

for k in r(n):
  for i in r(n):
    for j in r(n):
      l[i][j]=min(l[i][j],l[i][k]+l[k][j])

ans=m
for i in r(m):
  f=False
  for j in r(n):
    if l[j][a[i]]+c[i]==l[j][b[i]]:
      f=True
  if f:ans-=1
print(ans)
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
i = 0
for j in range(M, -1, -1):
    if ruiA[i] + ruiB[j] <= K:
        MAX = max(MAX, i+j)
        best = j
    break
    
for i in range(1, N+1):
    for j in range(best, -1, -1):
        if ruiA[i] + ruiB[j] <= K:
            MAX = max(MAX, i+j)
        break


print(MAX)


### FIXED CODE ###

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

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
j = M

for i in range(N+1):
    if ruiA[i] > K:
        break
    while ruiA[i] + ruiB[j] > K:
        j -= 1
    MAX = max(MAX, i+j)

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

if M % 2 == 0 :
    vec = [[] for _ in range(N)]
    for _ in range(M) :
        A, B = map(int, input().split())
        vec[A-1].append(B-1)
        vec[B-1].append(A-1)

    visited = [False] * N
    CD = [[] for _ in range(N)]

    def dfs(cur, pre) :
        for nex in vec[cur] :
            if nex == pre :
                continue
            
            if not visited[nex] :
                visited[nex] = True
                dfs(nex, cur)
            elif not cur in CD[nex] :
                CD[cur].append(nex)
        
        if pre != -1 :
            if len(CD[cur]) % 2 == 0 :
                CD[pre].append(cur)
            else :
                CD[cur].append(pre)

    visited[0] = True            
    dfs(0, -1)

    for i in range(N) :
        for j in CD[i] :
            print(i + 1, j + 1)
else :
    print(-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

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

if M % 2 == 0 :
    vec = [[] for _ in range(N)]
    for _ in range(M) :
        A, B = map(int, input().split())
        vec[A-1].append(B-1)
        vec[B-1].append(A-1)

    visited = [False] * N
    CD = [[] for _ in range(N)]

    def dfs(cur, pre) :
        for nex in vec[cur] :
            if nex == pre :
                continue
            
            if not visited[nex] :
                visited[nex] = True
                dfs(nex, cur)
            elif not cur in CD[nex] :
                CD[cur].append(nex)
        
        if pre != -1 :
            if len(CD[cur]) % 2 == 0 :
                CD[pre].append(cur)
            else :
                CD[cur].append(pre)

    visited[0] = True            
    dfs(0, -1)

    for i in range(N) :
        for j in CD[i] :
            print(i + 1, j + 1)
else :
    print(-1)
x = int(input())
a = int(input())
b = int(input())
s= x-a
print(int(s-s*(b*(s//b)))

### FIXED CODE ###

x = int(input())
a = int(input())
b = int(input())
s= x-a
print(int(s-(b*(s//b))))
import fractions as f
g=f.gcd(list(map(int,input().split())));print(-1if input()[::n//g]!=input()[::m//g]else n*m//g)

### FIXED CODE ###

from fractions import gcd

n,m = map(int,input().split())
s = input()
t = input()
if n==m:
    if s!=t:
        print('-1')
        exit()
    else:
        print(n)
        exit()
elif n<m:
    n,m = m,n
    s,t = t,s
# n>m
if n%m==0:
    k = n//m
    if s[::k]==t:
        print(n)
        exit()
    else:
        print('-1')
        exit()
else:
    g = gcd(n,m)
    if s[::n//g]==t[::m//g]:
        print(n*m//gcd(n,m))
    else:
        print(-1)
A, B = map(int, input().split())
i = 2
cnt = 0
tmpA, tmpB = A, B
while i**2 <= min(tmpA, tmpB) and i <= min(A,B):
    if A % i == 0 and B % i == 0:
        cnt += 1
        while A % i == 0 and B % i == 0:
            A //= i
            B //= i
    i += 1
if cnt == 0 and min(A, B) != 1:
    cnt += 1
if cnt == 0 and max(A,B) % min(A,B) == 0:
    cnt += 1
print(cnt + 1)

### FIXED CODE ###

N = int(input())
if N % 2 == 0:
    print(0.5)
else:
    print((N // 2 + 1) / N)
s = list(input())

ans = 0
for i in len(s-2):
  if s[i]=="A" and s[i+1] == "B" and s[i+2] ==  "C":
    ans += 1
    
print(ans)

### FIXED CODE ###

N = input()
s = list(input())

ans = 0
for i in range(len(s)-2):
  if s[i]=="A" and s[i+1] == "B" and s[i+2] ==  "C":
    ans += 1
    
print(ans)
S, T = input().split()

ans = 0
for i in range(3):
    if S[i]==T[i]:
        ans += 1
    else:
        pass
print(ans)

### FIXED CODE ###

S, T = input(), input()
ans = 0
for i in range(3):
    if S[i]==T[i]:
        ans += 1
    else:
        pass
print(ans)
import math
n, w = map(int, input().split())
m = list()
for i in range(n):
  m.append(int(input()))

w -= sum(m)
print(len(m) + math.floor(w/min(m)))

### FIXED CODE ###

s = input()
t = 700 + (100 * s.count("o"))
print(t)
# -*- coding: utf-8 -*-
A=int(input())
B=int(input())
if A==1:
    if B==2:
        C=3
    if B==3:
        C=2
if A==2:
    if B==1:
        C=3
    if B==3:
        C=1
if A==3:
    if B==1:
        C==2
    if B==2:
        C==1

prnt(C)

### FIXED CODE ###

# -*- coding: utf-8 -*-
A=int(input())
B=int(input())
if A==1:
    if B==2:
        C=3
    if B==3:
        C=2
if A==2:
    if B==1:
        C=3
    if B==3:
        C=1
if A==3:
    if B==1:
        C=2
    if B==2:
        C=1

print(C)
import stdin

year, month, date = stdin.readline().rstrip().split('/')

y = int(year)
m = int(month)
d = int(date)

heisei_y = 2019
heisei_m = 4
heisei_d = 1

if y < heisei_y:
  print('Heisei')
elif  m < heisei_m:
  print('Heisei')
elif  d < heisei_d:
  print('Heisei')
else:
  print('TBD')



### FIXED CODE ###

from sys import stdin


year, month, date = stdin.readline().rstrip().split(sep='/')

y = int(year)
m = int(month)
d = int(date)

heisei_y = 2019
heisei_m = 4
heisei_d = 30

if y < heisei_y:
  print('Heisei')
elif  (y == heisei_y) and (m < heisei_m):
  print('Heisei')
elif  ((y == heisei_y) and m == heisei_m) and (d <= heisei_d):
  print('Heisei')
else:
  print('TBD')
import numpy as np
from collections import deque, defaultdict

N, K = (int(i) for i in input().split())  
P = [int(i) for i in input().split()] 

dice = [0]
for i in range(1000):
  dice.append(1 + 0.5 * i)

q = deque()
ans = 0
for p in P:
  q.append(dice[p])
  
  if len(q) < K:
    continue
  else:
    ans = max(ans, sum(q))
    q.popleft()

print(ans)

### FIXED CODE ###

from collections import deque, defaultdict

N, K = (int(i) for i in input().split())  
P = [int(i) for i in input().split()] 

dice = [0]
for i in range(1000):
  dice.append(1 + 0.5 * i)
  
lis = [0]
sum = 0
for p in P:
  sum += dice[p]
  lis.append(sum)
  
ans = 0
for i in range(N - K + 1):
  ans = max(ans, lis[K+i] - lis[i])
print(ans)
import math
n=int(input())
k=int(math.sqrt(n))
l=[]
for i in range(1,k+2):
    n%i==0:l.append(max(len(str(i),len(str(n//i))))
print(min(l))

### FIXED CODE ###

import math
n=int(input())
k=int(math.sqrt(n))
l=[]
for i in range(1,k+2):
    if n%i==0:l.append(max( len(str(i)), len(str(n//i)) ))
print(min(l))