Harryxun/stf_run huggingface dataset:
w = int(raw_input())
n = int(raw_input())$
a = []
for i in range(n):
  a.append(map(int, raw_input().split(',')))
  r = range(1,w + 1)
for i in a:
 tmp = r[i[0] - 1]
 r[i[0] - 1] = r[i[1] - 1]
 r[i[1] - 1] = tmp
for i in r:
  print i

### FIXED CODE ###

w = int(raw_input())
n = int(raw_input())
a = []
for i in range(n):
  a.append(map(int, raw_input().split(',')))
r = range(1,w + 1)
for i in a:
  tmp = r[i[0] - 1]
  r[i[0] - 1] = r[i[1] - 1]
  r[i[1] - 1] = tmp
for i in r:
  print i
x = input()
y = x **3
print(y)

### FIXED CODE ###

x = int(input())

print(x*x*x)
#!/usr/bin/env python3
a, b = input().split(" ")
for i in range(a):
    a += a
for i in range(b):
    b += b
print(sorted([a, b])[0])

### FIXED CODE ###

#!/usr/bin/env python3
a, b = input().split(" ")
A = a * int(b)
B = b * int(a)
print(sorted([A, B])[0])
S = str(input())
if S = "ABC":
  print("ARC")
else:
  print("ABC")

### FIXED CODE ###

S = str(input())
if S == "ARC":
  print("ABC")
else:
  print("ARC")
N=input()
s=str(N)
s1=s[-1]
s2=s[-2]
s3=s[-3]
if s1=='7':
    print('Yes')
    elif s2=='7':
          print('Yes')
        elif s3=='7':
              print('Yes')
            else:
                print('No')
                


### FIXED CODE ###

N=input()
s=str(N)
s1=s[-1]
s2=s[-2]
s3=s[-3]
if s1 == '7':
    print('Yes')
elif s2 == '7':
    print('Yes')
elif s3=='7':
    print('Yes')
else:
    print('No')
K = int(input())
A,B = map(int,input().split())
for i in range(a,b+1)
if i%K == 0
  print('OK')
else:
  print('No')

### FIXED CODE ###

K = int(input())
a,b = map(int,input().split())
c = 'NG'
for i in range(a,b+1):
  if i % K == 0:
    c = 'OK'
    break
print(c)
import sys

def main():
    args = [int(input()) for i in range(2)]
    list = [1, 2, 3]
    for i in list:
        flg = False
        for j in args:
            if j == i:
                flg = True
        if not flg:
            print(i)
            return i

if __name__ == "__main__":
    sys.exit(main())

### FIXED CODE ###

args = [int(input()) for i in range(2)]
list = [1, 2, 3]
for i in list:
    flg = False
    for j in args:
        if j == i:
            flg = True
    if not flg:
        print(i)
N = int(input())
Lines = list(map(int, input().split(" ")))
Lines.sort()
answer = 0

import bisect

for lineI in range(N):
    for lineJ in range(lineI+1,N):
    	answer += bisect.bisect_left(Lines,Lines[lineI]+Lines[lineJ])-j-1
print(answer)

### FIXED CODE ###

N = int(input())
Lines = list(map(int, input().split(" ")))
Lines.sort()
answer = 0
 
import bisect
 
for lineI in range(N):
    for lineJ in range(lineI+1,N):
    	answer += bisect.bisect_left(Lines,Lines[lineI]+Lines[lineJ])-lineJ-1
print(answer)
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a*b==0:
    return a if b==0 else b
  else:
    while b:
      a,b=b,a%b
  return a

B=[]
B[0]=0
C=[]
C[0]=0
for i in range(n-1):
  B[i+1]=gcd(B[i],A[i])
  C[i+1]=gcd(C[i],A[n-i-1])
po=0
for i in range(n):
  po=max(po,B[i]*C[n-1-i])
print(po)


### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a*b==0:
    return a if b==0 else b
  else:
    while b:
      a,b=b,a%b
  return a

B=[0]*(n+5)
C=[0]*(n+5)

for i in range(n):
  B[i+1]=gcd(B[i],A[i])
  C[i+1]=gcd(C[i],A[n-i-1])
po=0
for i in range(n):
  po=max(po,gcd(B[i],C[n-1-i]))
print(po)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict

H, W, D = map(int, input().split())
A = [list(map(int, input().split()))  for _ in range(H)]

dic = defaultdict(list)

for h in range(W):
    for w in range(W):
        dic[A[h][w]] = [h, w]

def calc(l, r):
    return abs(dic[l][0] - dic[r][0]) + abs(dic[l][1] - dic[r][1])

lst = [0] * (H * W + 1)
for d in range(1, D + 1):
    tmp = d
    while tmp + D <= (H * W):
        lst[tmp + D] = lst[tmp] + calc(tmp, tmp + D)
        tmp += D

# print (lst)
Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    ans = lst[R] - lst[L]
    print (ans)


### FIXED CODE ###

H, W, D = map(int, input().split())

#盤面を取得
lst = [0] * (H * W + 1)
for i in range(1, H + 1):
    tmp = list(map(int, input().split()))
    for j in range(1, W + 1):
        lst[tmp[j - 1]] = [i, j]
#前処理

#xからyに移動するのにかかるコストを返す関数
def cost(x, y): 
    return abs(lst[x][0] - lst[y][0]) + abs(lst[x][1] - lst[y][1])

check_lst = [False] * (H * W + 1)
cost_lst = [0] * (H * W + 1)
for i in range(1, H * W + 1):
    if check_lst[i]:
        continue
    check_lst[i]  = True
    tmp = i
    while tmp + D <= H * W:
        cost_lst[tmp + D] = cost_lst[tmp] + cost(tmp, tmp + D)
        check_lst[tmp + D] = True
        tmp += D

#出力
Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    print (cost_lst[R] - cost_lst[L])
a,b,h=map(int,input().split())
ans=(a+b)*h*0.5
print(int(ans))



### FIXED CODE ###

a=int(input())
b=int(input())
h=int(input())
ans=(a+b)*h*0.5
print(int(ans))
def f(S):
    if S=="":
        return 0
    else:
        return f(S[:-1])+int(S[-1])

N=input()
if f(N)%9:
    print("No")
else:
    print("Yes")


### FIXED CODE ###

N=input()

S=0
for a in N:
    S+=int(a)

if S%9:
    print("No")
else:
    print("Yes")
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0117

INF = 1e12


def dijkstra(graph, source):
    lg = len(graph)
    unused = list(range(lg))
    d = [INF] * (lg)
    d[source] = 0

    while unused:
        v = min(unused, key=lambda u: d[u])
        unused.remove(v)
        for u in range(n + 1):
            d[u] = min(d[u], d[v] + graph[v][u])

    return d

n = int(input())
m = int(input())

cost = [[INF] * (n + 1) for i in range(n + 1)]
for i in range(m):
    ai, bi, ci, di = map(int, input().split(','))
    cost[ai][bi] = ci
    cost[bi][ai] = di

x1, x2, y1, y2 = map(int, input().split(','))

d_go = dijkstra(cost, x1)[x2]
d_back = dijkstra(cost, x2)[x1]

print(y1 - y2 - d_go - d_back)

### FIXED CODE ###

INF = 1e12


def dijkstra(graph, source):
    lg = len(graph)
    unused = list(range(lg))
    d = [INF] * (lg)
    d[source] = 0

    while unused:
        v = min(unused, key=lambda u: d[u])
        unused.remove(v)
        for u in range(n + 1):
            d[u] = min(d[u], d[v] + graph[v][u])

    return d

n = int(input())
m = int(input())

cost = [[INF] * (n + 1) for i in range(n + 1)]
for i in range(m):
    ai, bi, ci, di = map(int, input().split(','))
    cost[ai][bi] = ci
    cost[bi][ai] = di

x1, x2, y1, y2 = map(int, input().split(','))

d_go = dijkstra(cost, x1)[x2]
d_back = dijkstra(cost, x2)[x1]

print(y1 - y2 - d_go - d_back)
import string
from collections
n=int(input())
A=list(string.ascii_lowercase)
d={}
for _ in range(n):
    s=input()
    c=collections.Counter(s)
    for i in A:
        if i in c.keys():
            if i not in d:
                d[i]=c[i]
            else:
                d[i]=min(d[i],c[i])
        else:
            d[i]=0
ans=[]
for i in d:
    ans+=i*d[i]
ans.sort()
print(*ans,sep='')

### FIXED CODE ###

import string
import collections
n=int(input())
A=list(string.ascii_lowercase)
d={}
for _ in range(n):
    s=input()
    c=collections.Counter(s)
    for i in A:
        if i in c.keys():
            if i not in d:
                d[i]=c[i]
            else:
                d[i]=min(d[i],c[i])
        else:
            d[i]=0
ans=[]
for i in d:
    ans+=i*d[i]
ans.sort()
print(*ans,sep='')
import numpy as np
n,k=map(int, input().split())
p=list(map(int,input().split()))


s=[]
p=np.array(p)
sum=0
for i in range(n):
  sum+=(1+p[i])/2
  s.append(sum)
  
max=s[k]-s[0]
for j in range(1,n-k):
  #print(j)
  if max<= s[j+k]-s[j]:
    max=s[j+k]-s[j]
  
print(max)

### FIXED CODE ###

import numpy as np
n,k=map(int, input().split())
p=list(map(int,input().split()))


s=[]
p=np.array(p)
sum=0
for i in range(n):
  sum+=(1+p[i])/2
  s.append(sum)
#print(s)
if k==n:
  print(s[-1])
  exit()
max=s[k-1]-s[0]
for j in range(1,n-k):
  #print(j)
  if max<= s[j+k]-s[j]:
    max=s[j+k]-s[j]
  
print(max)
import math
n, W = map(int, input().strip().split())
 
values = []
weights = []
total = 10
for _ in range(n):
    w, v = map(int, input().strip().split())
    weights.append(w)
    values.append(v)
    total += v

dp = [[math.inf for j in range(total)] for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
for i in range(1,n+1):
    for v in range(1,total):
        if v < values[i-1]:
            dp[i][v] = dp[i-1][v]
        else:
            dp[i][v] = min(dp[i-1][v],dp[i-1][v-values[i-1]]+weights[i-1]) 
res = 0
for i in range(total):
    if dp[n][i] <= W:
        res = i
print(res)

### FIXED CODE ###

INF = 1000000000000
n, W = map(int, input().split())
values = []
weights = []
total = 10
for _ in range(n):
    w, v = map(int, input().split())
    weights.append(w)
    values.append(v)
    total += v
dp = [[INF for j in range(total)] for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
for i in range(1,n+1):
    for v in range(1,total):
        if v < values[i-1]:
            dp[i][v] = dp[i-1][v]
        else:
            dp[i][v] = min(dp[i-1][v],dp[i-1][v-values[i-1]]+weights[i-1]) 
res = 0
for i in range(total):
    if dp[n][i] <= W:
        res = i
print(res)
X,N = map(int,input().split())
p = list(map(int,input().split()))

if (1 <= X <= 100) and (0 <= N <= 100) and ((1 <= len(p) <= 100 ) or N == 0) :
    ans = X-1
    bns = X+1
    
    while True:
        if N == 0:
            print(X)
            break
        
        if ans in p:
            ans-=1         
        if ans not in p:
            print(ans)
            break
        
        if bns in p:
            bns+=1
        if bns not in p:
            print(bns)
            break
        

### 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)
    
elif e == 0:
    print(5)
mi = lambda : map(int,input().split())

import math

a,b,c = mi()

# if a+b-c/2 >= math.sqrt(a*b):
if math.sqrt(a) + math.sqrt(b) < math.sqrt(c)
    print('Yes')
else:
    print('No')

### FIXED CODE ###

mi = lambda : map(int,input().split())

a,b,c = mi()

x = c-a-b
if x < 0:
    print('No')
elif 4* a*b < (c-a-b)**2:
    print('Yes')
else:
    print('No')
n = int(input())
l = list(map(int, input().split()))

k = round(sum(l) / n)
ans = 0
for i in l:
    ans += (k - i) ** 2

print(ans)


### FIXED CODE ###

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

if n >= 10:
    print(r)
else:
    print(r + (100 * (10 - n)))
from math import gcd
from functools import reduce
N, M = map(int, input().split())
a = list(map(int, input().split()))

half_a = [ai // 2 for ai in a]
L = reduce(lambda x, y: x * y // gcd(x, y), half_a)


### FIXED CODE ###

from functools import reduce

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


def f(x):
    c = 0
    while x % 2 == 0:
        x //= 2
        c += 1
    return c


def gcd(x, y):
    return gcd(y, x % y) if y != 0 else x


nth = [f(ai) for ai in a]
if len(set(nth)) == 1:
    half_a = [ai >> 1 for ai in a]
    L = reduce(lambda x, y: x * y // gcd(x, y), half_a)
    ans = (M - L) // (2 * L) + 1 if M >= L else 0
else:
    ans = 0
print(ans)
import math
k = int(input())
ans = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    for m in range(1,k+1):
      ans += math.gcd(i,j,m)
print(ans)

### FIXED CODE ###

from math import gcd
k = int(input())
ans = 0
for i in range(1,k+1):
  for j in range(1,k+1):
    v = gcd(i,j)
    for m in range(1,k+1):
      ans += gcd(v,m)
print(ans)
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

from math import gcd
#from fractions import gcd

def main():
	n=int(input())
	A=list(map(int,input().split()))
	A.sort()
	a=1
	for i in A:
		a=a*i//gcd(a, i)
	ans=0
	for i in A:
		ans+=(a//i)
		ans%=mod
	print(ans)
	
	
	
	
	
	


if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

#from math import gcd
from fractions import gcd

def main():
	n=int(input())
	A=list(map(int,input().split()))
	B=set(A)
	A=list(A)
	A.sort(reverse=True)
	a=1
	ans=0
	for i in A:
		g=gcd(a, i)
		ans *=i//g
		a=a*i//gcd(a, i)
		ans+=a//i
	
	
	
	
	print(ans%mod)
	
	
	
	
	
	


if __name__ == "__main__":
	main()
import time

n=int(input())
x=(n%15)*0.001*100
a=0.037
#time.sleep(x+a)
ls=[for i in range((n%100)*10**6)]
print('Yes')

### FIXED CODE ###

x=int(input())
s=str(x)
keta=0
for i in s:
  keta+=int(i)
if x%keta==0:
  ans='Yes'
else:
  ans='No'
print(ans)
N = int(input())
A = map(int, input().split())

As = A.sort()
ans = As[len(N)-1] - As[0]
print(ans)

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]

A.sort()
ans = A[N-1] - A[0]
print(ans)
import itertools
N = int(input())
AB = [list(map(int, input().split())) for n in range(N)]

if N % 2 == 0:
  k1 = int(N/2-1)
  k2 = int(N/2)
  arr1 = list(range(AB[k1][0], AB[k1][1] + 1))
  arr2 = list(range(AB[k2][0], AB[k2][1] + 1))
  pattern = list(itertools.product(arr1, arr2))
  ans = set()
  for p in pattern:
    ans.add(sum(p))
  print(len(ans))
  

else:
  k = int((N+1)/2)-1
  A = AB[k][0]
  B = AB[k][1]
  print(B-A+1)

### FIXED CODE ###

import itertools
N = int(input())
AB = [list(map(int, input().split())) for n in range(N)]
sortA = sorted(AB, key= lambda x:x[0])
sortB = sorted(AB, key= lambda x:x[1])
if N % 2 == 0:
  k1 = int(N/2-1)
  k2 = int(N/2)
  minM = sortA[k1][0] + sortA[k2][0]
  maxM = sortB[k1][1] + sortB[k2][1]
  print(maxM-minM+1)
else:
  k = int((N+1)/2)-1
  A = sortA[k][0]
  B = sortB[k][1]
  print(B-A+1)
S = input()
T = input()
if (T[:-1] == S):
  return "Yes"
else :
  return "No"

### FIXED CODE ###

S = input()
T = input()
if T[:-1] == S :
  print("Yes")
else :
  print("No")
x, y = (int(i) for in in input().split())

pos = (4*x - y) // 2 >= 0

if pos:
  print('Yes')
else:
  print('No')
  

### FIXED CODE ###

def main():
    na, nl = (int(i) for i in input().split())
    nc = (4*na - nl) / 2

    pos = (nc == int(nc) and nc >= 0 and nc <= na)

    if pos:
        print('Yes')
    else:
        print('No')
      
main()
l=list()
L=list()
for i in range(5):
  n=int(input())
  if n%10==0:
    l.append(n)
  else:
    L.append(n)
    
LL=list()
for n in L:
  N=n%10
  LL.append(N)
key=min(LL)
LL.remove(key)

x=len(LL)*10

M=list()
for n in L:
  nn=n//10*10
  M.append(nn)
  
  
print(sum(l)+sum(M)+x+key)
  


### FIXED CODE ###

l=list()
L=list()
for i in range(5):
  n=int(input())
  if n%10==0:
    l.append(n)
  else:
    L.append(n)
if len(l)==5:
  print(sum(l))
  exit()
    
LL=list()
for n in L:
  N=n%10
  LL.append(N)
key=min(LL)
LL.remove(key)

x=len(LL)*10

M=list()
for n in L:
  nn=n//10*10
  M.append(nn)
  
  
print(sum(l)+sum(M)+x+key)
N,X,Y=map(int,input().split())


def count(k):
    count=0
    for i in range(1,N):
        for j in range(i+1,N+1):
            if min(abs(j-i),abs(X-i)+abs(Y-j)+1)==k:
                count+=1
                if count >= 4:
                    break
    return count

for k in range(1,N):
    print(count(k))

### FIXED CODE ###

S=list(input())

if S[2]==S[3] and S[4]==S[5]:
    print("Yes")
else:
    print("No")
n = int(input())
a = list(map(int, input().split()))
def pow(x):
    if x % 2 == 0:
        return 0
    else:
        return 1 + pow(x/2)
print(min(pow(_) for _ in a))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
def pow(x):
    if x % 2 != 0:
        return 0
    else:
        return 1 + pow(x/2)
print(min(pow(_) for _ in a))
import itertools
 
x = int(input())
 
y = itertools.combinations(range(-50,50), 2)
i = 0
for n in y:
    if (n[0]**5 - n[1]**5) == x:
        print(n[0], n[1])
        break
    elif (n[1]**5 - n[0]**5) == x:
        print(n[1], n[0])
        break

### FIXED CODE ###

a = input()

if a == "ABC":
    print("ARC")
else:
    print("ABC")
l = map(int, raw_input().split( ))
if l[0] == l[1]:
	print(l[2])
elif l[0] == l[2] :
	print(l[1])
else:
	print(l[0])

### FIXED CODE ###

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
if a == b :
	print(c);
elif a == c :
	print(b);
else :
	print(a);
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
tour=[0]
next_town = 0
for i in range(n*2):
    next_town=A[next_town]-1
    if next_town in tour:
        first_roop_idx = tour.index(next_town)
        break
    tour.append(next_town)
#print(tour)
if k<=len(tour):
    ans = tour[k]
else:
    k-=first_roop_idx
    ans = tour[k%(len(tour)+first_roop_idx)+first_roop_idx-1]
print(ans)


### FIXED CODE ###

n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
tour=[0]
visited=[0]*n
visited[0]=1
next_town = 0
flag=False
for i in range(n):
    next_town=A[next_town]-1
    if i+1==k:
        flag = True
        ans = next_town
        break
    if next_town==0:
        first_roop_idx = 0
        break
    if visited[next_town]>0:
        first_roop_idx = visited[next_town]
        break
    tour.append(next_town)
    visited[next_town]=i+1
#print(tour)
#print(visited)
#print(first_roop_idx)
if not flag:
    if k<=len(tour):
        ans = tour[k]
    else:
        k-=first_roop_idx
        #print("k=",k)
        if len(tour)-first_roop_idx==0:
            k=0
        else:k=k%(len(tour)-first_roop_idx)
        #print("k=",k)
        ans = tour[first_roop_idx+k]
print(ans+1)
#print(flag)
s=input()
print(s.count('1')

### FIXED CODE ###

s=input()
print(s.count('1'))
n = int(input())
l = sort(map(int, input().split()))
l_sum = 0
for i in range(n-1):
	l_sum += l[i]
if l_sum > l[n-1]:
	print('Yes')
else:
	print('No')

### FIXED CODE ###

n = int(input())
l = [int(x) for x in input().split()]
l.sort()
# print(l)
l_sum = 0
for i in range(n-1):
	l_sum += l[i]
if l[n-1] < l_sum:
	print('Yes')
else:
	print('No')
a=int(input())
c=[]
b=list(map(int,input().split()))
c=b.sort()
print(c[-1]*c[-2])

### FIXED CODE ###

a=int(input())
import itertools 
b=list(map(int,input().split()))
c=0
for d,e in itertools.combinations(b,2):
  c+=d*e
print(c)
import sys

# お約束
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(args, *params):
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    print(*v, file=sys.stderr)

# エントリーポイント
def main(args):
    N, M = parse(args, int, int)
    A = map(int, next(args).split())

    #       1  2  3  4  5  6  7  8  9
    nums = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    dp = [[]] + [[] for _ in range(N)]
    for a in A:
        na = nums[a - 1]
        def chmax(c):
            nl = sorted(dp[c - na] + [a], reverse=True)
            if len(nl) < len(dp[c]):
                return dp[c]
            if len(dp[c]) < len(nl):
                return nl
            return max(nl, dp[c])
        dp[na] = chmax(na)
        for c in range(na + 1, N + 1):
            if dp[c - na]:
                dp[c] = chmax(c)
    # for i, v in enumerate(dp, start=0):
    #     debug(i, v)
    print(*dp[N], sep="")

if __name__ == '__main__':
    main(iter(sys.stdin.read().split("\n")))


### FIXED CODE ###

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

costs = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]

# 優先度：桁数, [要素(降順)]
dp = [[0, []] for _ in range(N + 1)]
for a in A:
	cost = costs[a]
	for n in range(N):
		if n != 0 and dp[n][0] == 0:
			continue
		ni = n + cost
		if N < ni:
			break
		np = [dp[n][0] + 1, sorted(dp[n][1] + [a], reverse=True)]
		if dp[ni] < np:
			dp[ni] = np

print(*sorted(dp[N][1], reverse=True), sep="")
import math
N,M = map(int,input().split())
S = input()
T = input()

flag = True
for n in range(N):
    if M*n%N==0:
        m = M*n//N
        flag = S[n]==T[m]
    if not flag:
        break
if not flag:
    print(-1)
else:
    print(N*M//math.gcd(N,M))


### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
N,M = map(int,input().split())
s = input()
t = input()
g = gcd(N,M)
l = N*M//g

n = N//g
m = M//g

ans = l

for i in range(g):
    if s[i*n]!=t[i*m]:
        ans = -1
        break
print(ans)
import math
import sys
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
a = list(map(int, input().split()))
def binary_search(left, right):
    if right - left <= 0.01:
        return right
    middle = (right + left) / 2
    if is_can(middle):
        return binary_search(left, middle)
    else:
        return binary_search(middle, right)
def is_can(target):
    count = 0
    for i in range(n):
        count += a[i] // target
    return count <= k
p = binary_search(0, 10**10)
if is_can(int(p)): 
    print(is_can(int(p)))
else:
    print(int(p) + 1)


### FIXED CODE ###

import math
import sys
sys.setrecursionlimit(10**8)
n, k = map(int, input().split())
a = list(map(int, input().split()))
def binary_search(left, right):
    if right - left <= 0.01:
        return right
    middle = (right + left) / 2
    if is_can(middle):
        return binary_search(left, middle)
    else:
        return binary_search(middle, right)
def is_can(target):
    count = 0
    for i in range(n):
        if a[i] > target:
            count += a[i] // target
    return count <= k
p = binary_search(0, 10**10)
if int(p) != 0 and is_can(int(p)) :
    print(int(p))
else:
    print(int(p) + 1)
from math import factorial
def comb(n,k,p):
  #from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res
#print(comb(5,3,10**9+7))
N,K = map(int,input().split())
for i in range(1,K+1):
    if i == 1 or i == K:
        print(comb(N-K+1,i,10**9+7))
    else:
        k = factorial(N-K+1)
        l = factorial(N-K+1-i)
        m = factorial(i-1)
        #print(k,l,m)
        #print( (k//(l*m)) % 10**9+7 )
        print( (k//(l*m)))
        #print(comb(N-K+1,i,10**9+7))

### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
MAX = 4000
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, MAX + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n,k= map(int,input().split())
for i in range(1,k+1):
    pre = cmb(k-1,i-1,mod)
    pos = cmb(n-k+1,i,mod)
    print((pre*pos)%mod)
n=int(input())
a=list(map(int,input().split()))
a_min=min(a)
a_max=max(a)

s=list(range(a_min,a_max+1))
t=[0]*(a_max+1)

for i in range(n):
  t[a[i]]+=1

x=0
for j in range(1,n-1):
  x=max(x,t[j-1]+t[j]+t[j+1])

print(x)
  

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a_min=min(a)
a_max=max(a)

s=list(range(a_min,a_max+1))
t=[0]*(a_max+1)

for i in range(n):
  t[a[i]]+=1

x=sum(t[:2]) #initialize
for j in range(1,len(t)-1):
  x=max(x,t[j-1]+t[j]+t[j+1])

print(x)
#!/usr/bin/env python3
N, C = map(int, input().split())
table = [0] * (10 ** 5 + 1)
for i in range(N):
    s, t, c = map(int, input().split())
    table[s] += 1
    table[t + 1] -= 1

ans = 0
for i in range(1, 10 ** 5 + 1):
    table[i] += table[i - 1]
    ans = max(ans, table[i])

print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
N, C = map(int, input().split())
table = [[0] * C for i in range(10 ** 5 + 1)]
for i in range(N):
    s, t, c = map(int, input().split())
    table[s - 1][c - 1] += 1
    table[t - 1][c - 1] -= 1

imos = [0] * (10 ** 5 + 1)
for i in range(10 ** 5 + 1):
    for j in range(C):
        if table[i][j] == 1:
            imos[i] += 1
        if table[i][j] == -1:
            imos[i + 1] -= 1

ans = 0
for i in range(1, 10 ** 5 + 1):
    imos[i] += imos[i - 1]
    ans = max(ans, imos[i])

print(ans)