Harryxun/stf_run huggingface dataset:
n,m=map(int,input().split())
mod=10**9+7
if abs(n-m)>1:
    print(0)
    exit()
a,b=[1,1]
for i in range(1,min(n,m)+1):
    a=(a*i)%mod
if n!=m:
    b*=max(n,m)*a
    print((a*b)%mod)
else:
    b=a
    print((2*a*b)%mod)

### FIXED CODE ###

mod=10**9+7
import math

def co(n,r,mod):
    x=1
    y=1
    for i in range(1,r+1):
        x=(x*(n-i+1))%mod
        y=(y*i)%mod
    return (x*pow(y,mod-2,mod))%mod
    
n,a,b=map(int,input().split())
ans=pow(2,n,mod)-1-co(n,a,mod)-co(n,b,mod)
print(max(ans%mod,0))#ansにmod取らないと無理
def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N:
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,k+1)
    distance += tmp_dist
    tmps = [tmp_x,tmp_y]
    for k in range(N-1):
        tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+2)
        distance += tmp_dist
        tmps = [tmp_x,tmp_y]
    print(distance)

if __name__=='__main__':
    main()

### FIXED CODE ###

def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N:
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,1)
    distance += tmp_dist
    tmps = [tmp_x,tmp_y]
    for k in range(N-1):
        tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+2)
        distance += tmp_dist
        tmps = [tmp_x,tmp_y]
    print(distance)

if __name__=='__main__':
    main()
N, T= map(int, input().split(' '))
X = [int(i) for i in input().split()]
num = T
for i in range(1, n):
    num += min(T, X[i] - X[i - 1])
print(num)

### FIXED CODE ###

N, T= map(int, input().split(' '))
X = [int(i) for i in input().split()]
num = T
for i in range(1, N):
    num += min(T, X[i] - X[i - 1])
print(num)
X=input()
c=list(input())
result=0
i=0
while i<len(c):
    if c[i]=='A':
        if c[i+1]=='B' and c[i+2]=='C':
            result+=1
            i+=1
        else:
            i+=1
    else:
        i+=1
print(result)

### FIXED CODE ###

X=input()
c=list(input())
result=0
i=0
while i<len(c)-2:
    if c[i]=='A':
        if c[i+1]=='B' and c[i+2]=='C':
            result+=1
            i+=3
        else:
            i+=1
    else:
        i+=1
print(result)
i = 1
while True:
    x = int(input().strip())
    if x == 0:
        break
    else:
        print ("""Case {}: {}""").format(i,x)
        i += 1

### FIXED CODE ###

i = 1
while True:
    x = int(input().strip())
    if x == 0:
        break
    else:
        print ("Case {}: {}".format(i,x))
        i += 1
kazu = int(input())
numbers_list = list(map(int, input().split()))
count = 0
seisu = 0
while True:
    for index in range(kazu):
        if numbers_list(index) % 2 == 0:
            numbers_list[inedx] = numbers_list[index] / 2
            count += 1
        else:
            seisu = 1
            break
    if seisu == 1:
        break
print(count)

### FIXED CODE ###

kazu = int(input())
numbers_list = list(map(int, input().split()))
count = 0
seisu = 0
while True:
    for index in range(kazu):
        if numbers_list[index] % 2 != 0:
            seisu = 1
            break
        else:
            numbers_list[index] = numbers_list[index] / 2
    if seisu == 1:
        break
    count += 1
print(count)
a,b=map(input().split())
if (a=="H" and b=="H") or (a=="D" and b=="D"):
    print("H")
else:
    print("D")

### FIXED CODE ###

a,b=input().split()
if (a=="H" and b=="H") or (a=="D" and b=="D"):
    print("H")
else:
    print("D")
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()
L = lcm(N,M)
ans = ['']*L
ans[0] = S[0]
for i in range(1,N):
    ans[i*(L//N)] = S[i]
for i in range(1,M):
    if ans[i*(L//M)] == '' or ans[i*(L//M)] == T[i]:
        ans[i*(L//M)] = T[i]
    else:
        print(-1)
        exit()
print(L)

### FIXED CODE ###

import fractions
import bisect
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N,M)
S_arr = [0]*N
T_arr = [0]*M
for i in range(1,N):
    S_arr[i] = i*(L//N)
for i in range(1,M):
    T_arr[i] = i*(L//M)
if M <= N:
    for i in range(M):
        index = bisect.bisect_left(S_arr,T_arr[i])
        if S_arr[index] == T_arr[i] and S[index] != T[i]:
            print(-1)
            exit()
else:
    for i in range(N):
        index = bisect.bisect_left(T_arr,S_arr[i])
        if T_arr[index] == S_arr[i] and T[index] != S[i]:
            print(-1)
            exit()

print(L)
import math

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

L=[0,0]
for ai in A:
    #L.append(gcd(L[-1],ai))
    L.append(math.gcd(L[-1],ai))
    print(L)

R=[0,0]
for ai in A[::-1]:
    #R.append(gcd(R[-1],ai))
    R.append(math.gcd(L[-1],ai))
    print(R)

print(max(math.gcd(l,r) for l,r in zip(L,reversed(R))))

### FIXED CODE ###

a,b,t=map(int,input().split())
x=0
num=0
c=a
for i in range(21):
    x=c
    c=a*(i+2)
    #print(x)
    if(x>t):
        break
    num+=b

print(num)
N = int(input())
s = list(map(int, input().split()))
a=[0]*N#N個の要素の配列
b=0
total=0

for i in range(N):
 a[i]=int(s[i])

while 1==1:
 for i in range(N):
  if a[i]%2==0:
        a[i]=a[i]/2
        b+=1
 if b==N:
  total+=1
 else: 
  break

print(total)

### FIXED CODE ###


s=list(input().split())
total=0

for digit in str(s):
 if digit=='1':
        total += 1

print(total)
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################

N,K = map(int,input().split())
def kitai(num):
    return (1+float(num)/2)
P = list(map(kitai,input().split()))	  

S = []

for i in range(N):
    S[i+1]=S[i]+P[i]
for i in range(N-K+1):
    ans = ans(ans,S[i+1]-S[i])
print(S[i])





### FIXED CODE ###

#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################

N,K = map(int,input().split())
def kitai(num):
    return (1+int(num))/2
P = list(map(kitai,input().split()))	  

S = [0]*(N+1)
ans = 0
for i in range(N):
    S[i+1]=S[i]+P[i]
for i in range(N-K+1):
    ans = max(ans,S[i+K]-S[i])
print(ans)
if X < A:
    print(0)
else:
    print(10)

### FIXED CODE ###

X, A = map(int, input().split())
 
if X < A:
 print(0)
else:
 print(10)
s = input()
t = input()
ss = s * (len(t))
ans = 0

if set(t) <= set(s):
    for i in range(len(t)):
        ans = ss.find(t[i], ans)
    print(ans + 1)
else:
    print(-1)

### FIXED CODE ###

s = input()
t = input()
t_long = len(t)
position = [0] * t_long
rep = 0

if set(t) <= set(s):
    position[0] = s.find(t[0])
    for i in range(1, t_long):
        if s.find(t[i], position[i - 1] + 1) > -1:
            position[i] = s.find(t[i], position[i - 1] + 1)
        else:
            position[i] = s.find(t[i])
    for k in range(t_long - 1):
        if position[k + 1] <= position[k]:
            rep += 1
    print(rep * len(s) + position[t_long - 1] + 1)
else:
    print(-1)
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l)
for i in range(1,n+1):
  if l1.index(l[i])<=n//2:
    print(l1[(n+2)//2])
  else:
    print(l1[n//2])  

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
l1=sorted(l)
for i in range(1,n+1):
  if l[i-1]<=l1[n//2-1]:
    print(l1[n//2])
  else:
    print(l1[(n-2)//2])
Q = 998244353
# def modpower(a,b,Q):#a^b mod Q
#     if b == 0:
#         return 1
#     if b%2 == 0:
#         d = modpower(a,b//2,Q)
#         return d*d%Q
#     if b%2 == 1:
#         return (a*modpower(a,b-1,Q))%Q
# def factorials(n,Q):#n以下の階乗のリストと階乗の逆元のmodQでのリスト
#     F = [1]*(n+1)
#     R = [1]*(n+1)
#     for i in range(n):
#         F[i+1] = F[i]*(i+1)%Q
#         R[i+1] = R[i]*pow(i+1,Q-2,Q)
#     return F, R
def getInv(N):
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

N, A, B, K = map( int, input().split())
ans = 0
invs = getInv(N)
nCk = [1]*(N+1)
for i in range(1,N+1):
    nCk[i] = (nCk[i-1]*(N-i+1)*invs[i])%Q
for i in range( min(K//A, N)+1):
    if (K-A*i)%B == 0:
        j = (K-A*i)//B
        ans = (ans + nCk[i]*nCk[j])%Q
print(ans)


### FIXED CODE ###

Q = 998244353
def getInv(N):
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

N, A, B, K = map( int, input().split())
ans = 0
invs = getInv(N)
nCk = [1]*(N+1)
for i in range(1,N+1):
    nCk[i] = (nCk[i-1]*(N-i+1)*invs[i])%Q
for i in range(N+1):
    j = (K-A*i)//B
    if A*i + B*j == K and j <= N and 0 <= j:
        j = (K-A*i)//B
        ans = (ans + nCk[i]*nCk[j])%Q
print(ans)
#include<stdio.h>

int main( void )
{
    int r, g;
    scanf("%d", &r);
    scanf("%d", &g);

    printf("%d\n", r + (g-r)*2);
    return 0;
}

### FIXED CODE ###

x, y = int(input()), int(input())
print( (y - x)*2 + x )
n = input()
ans = 1
while (n != 4 and n != 2 and n != 1):
  ans += 1
  if n % 2 == 0:
    n = n / 2
  else:
    n = 3 * n + 1

print(ans + 3)

### FIXED CODE ###

n = int(input())
ans = 1
while (n != 4 and n != 2 and n != 1):
  ans += 1
  if n%2 == 0:
    n = n / 2
  else:
    n = 3 * n + 1

print(ans + 3)
N = int(input())
S = []
for i in range(N):
    si = input()
    if si not in S:
        S = S + [si]
print(len(S))

### FIXED CODE ###

S,W = map(int,input().split())
if S > W:
    print("safe")
else:
    print("unsafe")
S = list(input())
print(s.count('1'))

### FIXED CODE ###

S = list(input())
print(S.count('1'))
a=list(map(int,input().split()))
a.sort(reverse=True)
s=a[-1]
if s==0:
    print(0)
else:
    for i in range(0,n-1):
        s*=a[i]
    if s>10**18:
        print(-1)
        sys.exit()
    print(s)

### FIXED CODE ###

import sys
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=a[n-1]
if s==0:
    print(0)
else:
    for i in range(0,n-1):
        s*=a[i]
        if s>10**18:
            print(-1)
            sys.exit()
    print(s)
class union_find:
    def __init__(self, node_num):
        self.root_array = [-1] * node_num

    def root(self, x):
        if self.root_array[x] < 0:
            return x
        else:
            return self.root_array[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.root_array[x] > self.root_array[y]:
            x, y = y, x
        self.root_array[x] += self.root_array[y]
        self.root_array[y] = x

    def size(self, x):
        return -self.root_array[self.root(x)]


def solve(n, m, ab_array):
    uf = union_find(n)
    for ab in ab_array:
        a, b = ab
        uf.unite(a - 1, b - 1)

    ans = 0
    for i in range(n):
        ans = max(ans, uf.size(i))

    return ans

if __name__ == '__main__':
    n, m = map(int, input().split())
    ab_array = [list(map(int, input().split())) for _ in range(m)]
    ans = solve(n, m, ab_array)
    print(ans)

### FIXED CODE ###

from collections import deque

n, m = map(int, input().split())
ab_array = [list(map(int, input().split())) for _ in range(m)]

ad_sum_array = [0] * n
ad_array = [set() for _ in range(n)]

for ab in ab_array:
    a, b = ab
    ad_array[a - 1].add(b - 1)
    ad_array[b - 1].add(a - 1)

check_array = [False] * n

def bfs(node_num):
    queue = deque([node_num])
    check_array[node_num] = True
    num = 1

    while queue:
        node = queue.popleft()
        for ad in ad_array[node]:
            if not check_array[ad]:
                check_array[ad] = True
                queue.append(ad)
                num += 1
    return num

ans = 0
for i in range(n):
    if not check_array[i]:
        ans = max(ans, bfs(i))

print(ans)
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())
x,n=input2()
p=sorted(input_array())
q=[0]*102
result=[10000,-1]
for i in range(n):
	q[p[i]]=1
for i in range(102):
	if q[i]==0:
		num=abs(i-x)
		if num<result[0]:
			result=[num,i]
print(result[1])

### FIXED CODE ###

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
x,n=input2()
p=sorted(input_array())
q=[0]*102
result=[10000,-1]
for i in range(n):
	q[p[i]]=1
for i in range(102):
	if q[i]==0:
		num=abs(i-x)
		if num<result[0]:
			result=[num,i]
print(result[1])
n,m,x=map(int,input().split())
nums=[0]*(n+1)
indices=list(map(int,input().split()))
for i in indices:
    nums[i]=1
print(min(num[:x].count(1),nums[x:].count(1)))

### FIXED CODE ###

n,m,x=map(int,input().split())
l=list(map(int,input().split()))
ans1=0
ans2=0
for i in range(x+1,n):
    for j in range(m):
        if l[j]==i:
            ans1+=1
for i in range(0,x):
    for j in range(m):
        if l[j]==i:
            ans2+=1
print(min(ans1,ans2))
S=list(map(int, input().split()))
if S[2] >= S[0]+S[1]:
  print(0,0)
else S[2] >= S[0]:
  print(0,S[1]+S[0]-S[2])
else:
  print(S[0]-S[2],S[1])

### FIXED CODE ###

S=list(map(int, input().split()))
if S[2] >= S[0] + S[1]:
  print(0,0)
elif S[2] >= S[0]:
  print(0,S[1]+S[0]-S[2])
else:
  print(S[0]-S[2],S[1])
def resolve():
    li = input().split()

    if li[0]+li[1] < 8:
        print("win")
    else if [0]+li[1];li[2] <= 22:
        print("win")
    else:
        print("bust")

### FIXED CODE ###

a = list(map(int,input().split()))
if a[0]+a[1]+a[2] <= 21:
  print('win')
else:
  print('bust')
url = "https://atcoder.jp//contests/abc049/tasks/abc049_b"

def main():
    h, w = list(map(int, input().split()))
    ss = [input() for _ in range(h)]
    for s in ss:
        print(s)
        print(s)

if __name__ == '__main__':
    main()


### FIXED CODE ###


url = "https://atcoder.jp//contests/abc049/tasks/arc065_a"

def main():
    words = ['dream','dreamer', 'erase', 'eraser']
    s = input()
    rs = s[::-1]
    while rs != '':
        tmp = len(rs)
        for word in words:
            if len(word) > len(rs):
                continue
            rs = rs[0:len(word)].replace(word[::-1], '') + rs[len(word):]
        if tmp == len(rs):
            print('NO')
            exit()
    print('YES')

if __name__ == '__main__':
    main()
N,Y = map(int, input().split())
ans= [-1, -1, -1]

for x in range(N+1):
    for y in range(N-x+1):
        price = x*10000 + y*5000 + int(N-x-y)*1000
#         print(x,y,N-x-y)
        if price == Y:
        print(x,y,N-x-y)
        break


### FIXED CODE ###

# N = 2000
# Y = 20000000
N,Y = map(int, input().split())
ans= [-1, -1, -1]

for x in range(N+1):
    for y in range(N-x+1):
        price = x*10000 + y*5000 + int(N-x-y)*1000
#         print(x,y,N-x-y)
        if price == Y:
            ans = [x,y,N-x-y]
            break
            
    if price == Y: 
        break

print(ans[0], ans[1], ans[2])
s = input()
atcg = ["A", "T", "C", "G"]
index = []
for i in range(len(s)-1):
  if s[i] not in atcg:
    index.append(i)

max = index[0]
for i in range(1, len(index), 1):
  if index[i] - index[i-1] - 1> max:
    max = index[i] - index[i-1] - 1 
print(max)

### FIXED CODE ###

def change(c):
  if c in atcg:
    return "1"
  else:
    return "0"
  
s = input()
atcg = "ATCG"
s = "".join([change(i) for i in s])
print(max([len(i) for i in s.split("0")]))
N, Y = list(map(int, input().split()))
flag=0
try:
  for x in range(N+1):
    #if flag != 0:break
    for y in range(N+1-x):
      #if flag != 0:break
      for z in range(N+1-x-y):
        if x+y+z == N:
          if x*10000 + y*5000 + z*1000 == Y:
			print(x, y, z)
            flag = 1
            raise Exception
except Exception:
  pass
if flag == 0:
  print('-1 -1 -1')


### FIXED CODE ###

N, Y = list(map(int, input().split()))
flag=0
try:
  for x in range(N+1):
    for y in range(N+1-x):
      z = N - x- y
      if x*10000 + y*5000 + z*1000 == Y:
        print(x, y, z)
        flag = 1
        raise Exception
except Exception:
  pass
if flag == 0:
  print('-1 -1 -1')
s,t = input().split
ans = t + s
print(ans)


### FIXED CODE ###

s,t = input().split()
ans = t + s
print(ans)
s = int(input)

A = []

A.append(s)
a = s
for i in range(10000):
    if a % 2 == 0:
        a = int(a/2)
        A.append(a)
    else:
        a = 3*a+1
        A.append(a)
    if A.count(a) == 2:
        print(a)
        break


### FIXED CODE ###

s = int(input())
A = []

A.append(s)
a = s
for i in range(10000):
    if a % 2 == 0:
        a = int(a/2)
        A.append(a)
    else:
        a = 3*a+1
        A.append(a)
    if A.count(a) == 2:
        print(len(A))
        break
a=int(input())
b=int(input())
if a%2==0 or a%2==0:
  print('Even')
else:
  print('Odd')

### FIXED CODE ###

a,b=map(int,input().split())
if a%2==0 or b%2==0:
    print('Even')
else:
    print('Odd')
line = input()
A, B, C, D = map(int, input().split())
left, right = A + B, C + D
print((
    "Left" if left > right else
    "Balanced" if left == right else
    "Right"
    ))


### FIXED CODE ###

A, B, C, D = map(int, input().split())
left, right = A + B, C + D
print((
    "Left" if left > right else
    "Balanced" if left == right else
    "Right"
    ))
import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
gcds = 0
for N in range(n):
    gcds = max(gcds,reduce(fractions.gcd, a[:N],a[N+1:]))
print(gcds)

### FIXED CODE ###


import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
gcds = 0
r = [0]
l = [0]
for N in range(n):
	r.append(fractions.gcd(r[N],a[N]))
	l.append(fractions.gcd(l[N],a[n - N - 1]))
for i in range(n):
	gcds = max(gcds,(fractions.gcd(r[i],l[n - i - 1])))
print(gcds)
from fractions import gcd
n,m = map(int, input().split())
s = input()
t = input()
# Xの長さLはnとmで割り切れる
# Xの1, L/n + 1, ..., (n-1) * L/n + 1 番目の文字をつなげるとSになる
# Xの1, L/m + 1, ..., (m-1) * L/m + 1 番目の文字をつなげるとTになる

ans = [""] * (n*m//gcd(n,m))
N,M = 1,1
for i in range(len(ans)):
    if i == 0: 
        if s[i] != t[i]:
            print(-1)
            exit()
        ans[0] = s[i]
    else:
        if i % (len(ans)//n) == 0: 
            ans[i] = s[N]
            N += 1
        if i % (len(ans)//m) == 0:
            if ans[i] == "" or ans[i] == t[M]:
                ans[i] = t[M]
                M += 1
            else:
                print(-1)
                exit()
print(n*m//gcd(n,m))

### FIXED CODE ###

from fractions import gcd
n,m = map(int, input().split())
s = input()
t = input()
# Xの長さLはnとmで割り切れる
# Xの1, L/n + 1, ..., (n-1) * L/n + 1 番目の文字をつなげるとSになる
# Xの1, L/m + 1, ..., (m-1) * L/m + 1 番目の文字をつなげるとTになる

ans = -1
if n==m:
    if s==t: ans= n
else:
    gcd_nm = gcd(n,m)
    for i in range(gcd_nm):
        if s[n//gcd_nm*i] != t[m//gcd_nm*i]: break
    else: ans = n*m//gcd_nm
print(ans)
mod = 998244353
N, S = map(int,input().split())
A = list(map(int,input().split()))
dp = [[0 for i in range(S+1)] for j in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j] * 2
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
        dp[i+1][j] %= mod

print(dp[N][S])
z

### FIXED CODE ###

mod = 998244353
N, S = map(int,input().split())
A = list(map(int,input().split()))
dp = [[0 for i in range(S+1)] for j in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j] * 2
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
        dp[i+1][j] %= mod

print(dp[N][S])