CodeEff/ECCO huggingface dataset:
# Original solution
N, Ma, Mb = list(map(int, input().split()))
a = [[0, 0, 0] for _ in range(N)]
sa = 0
sb = 0
for i in range(N):
    a[i][0], a[i][1], a[i][2] = list(map(int, input().split()))
    sa += a[i][0]
    sb += a[i][1]
INF = 1000000  

DP = [[[INF for _ in range(sb+1)] for _ in range(sa+1)] for _ in range(N+1)]
DP[0][0][0] = 0

for i in range(N):
    for j in range(sa+1):
        for k in range(sb+1):
            if(j >= a[i][0] and k >= a[i][1]):
                DP[i+1][j][k] = min(DP[i][j-a[i][0]][k-a[i][1]] + a[i][2], DP[i][j][k])
            else:
                DP[i+1][j][k] = DP[i][j][k]
ans = INF
for i in range(1, min(sa//Ma, sb//Mb)+1):
    ans = min(ans, DP[N][Ma*i][Mb*i])
    
if(ans == INF):
    print((-1))
else:
    print(ans)

# Optimized solution
def main():
    N, Ma, Mb = list(map(int, input().split()))
    yakuhin = []
    sa = 0
    sb = 0
    for i in range(N):
        yakuhin.append(list(map(int, input().split())))
        sa += yakuhin[i][0]
        sb += yakuhin[i][1]
    
    INF = 10**15
    DP = [[[INF for _ in range(sb+1)] for _ in range(sa+1)] for _ in range(N+1)]
    
    for i in range(N):
        DP[i][0][0] = 0
    
    for i in range(N):
        for j in range(sa+1):
            for k in range(sb+1):
                if(j >= yakuhin[i][0] and k >= yakuhin[i][1]):
                    DP[i+1][j][k] = min(DP[i][j][k], DP[i][j-yakuhin[i][0]][k-yakuhin[i][1]]+yakuhin[i][2])
                else:
                    DP[i+1][j][k] = min(DP[i+1][j][k], DP[i][j][k])
        
    ans = INF
    for i in range(1, N+1):
        for j in range(1, sa+1):
            for k in range(1, sb+1):
                if(j*Mb == k*Ma):
                    ans = min(ans, DP[i][j][k])    
        
    print((ans if ans != INF else -1))
    
main()
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,K = list(map(int,input().split()))
    A = sorted([int(input()) for i in range(0,K)])

    if (N,K) == (0,0):
        break

    if A[0] == 0:
        flag = True
        A = A[1:]
        K -= 1
    else:
        flag = False

    ans = 0
    for i in range(K):
        for j in range(i+ans,K):
            if j - i == A[j] - A[i]:
                ans = max(ans,A[j]-A[i])
            elif flag is True and j - i + 1 == A[j] - A[i]:
                ans = max(ans,A[j]-A[i])
            else:
                break

    print((ans+1))

# Optimized solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,K = list(map(int,input().split()))
    A = sorted([int(eval(input())) for i in range(0,K)])

    if (N,K) == (0,0):
        break

    if A[0] == 0:
        flag = True
        A = A[1:]
        K -= 1
    else:
        flag = False

    ans = 0
    count = 0
    diff_list = []
    s = 0
    for i in range(1,K):
        if A[i] - A[i-1] == 2:
            diff_list.append(A[i-1] - A[s])
            s = i
            count = 0
        elif A[i] - A[i-1] > 2:
            diff_list.append(A[i-1] - A[s])
            diff_list.append(0)
            s = i
            count = 0
        else:
            count += 1
            ans = max(ans,count)
    else:
        diff_list.append(A[i] - A[s])

    if flag is True:
        ans = 0
        for i in range(1,len(diff_list)):
            ans = max(ans,diff_list[i] + diff_list[i-1] + 2)

    print((ans + 1))
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,K = list(map(int,input().split()))
    A = sorted([int(eval(input())) for i in range(0,K)])

    if (N,K) == (0,0):
        break

    if A[0] == 0:
        flag = True
        A = A[1:]
        K -= 1
    else:
        flag = False

    ans = 0
    count = 0
    diff_list = []
    s = 0
    for i in range(1,K):
        if A[i] - A[i-1] == 2:
            diff_list.append(A[i-1] - A[s])
            s = i
            count = 0
        elif A[i] - A[i-1] > 2:
            diff_list.append(A[i-1] - A[s])
            diff_list.append(0)
            s = i
            count = 0
        else:
            count += 1
            ans = max(ans,count)
    else:
        diff_list.append(A[i] - A[s])

    if flag is True:
        ans = 0
        for i in range(1,len(diff_list)):
            ans = max(ans,diff_list[i] + diff_list[i-1] + 2)

    print((ans + 1))

# Optimized solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,K = list(map(int,input().split()))
    A = sorted([int(input()) for i in range(0,K)])

    if (N,K) == (0,0):
        break

    if A[0] == 0:
        flag = True
        A = A[1:]
        K -= 1
    else:
        flag = False

    ans = 0
    count = 0
    diff_list = []
    s = 0
    for i in range(1,K):
        if A[i] - A[i-1] == 2:
            diff_list.append(A[i-1] - A[s])
            s = i
            count = 0
        elif A[i] - A[i-1] > 2:
            diff_list.append(A[i-1] - A[s])
            diff_list.append(0)
            s = i
            count = 0
        else:
            count += 1
            ans = max(ans,count)
    else:
        diff_list.append(A[i] - A[s])

    if flag is True:
        ans = 0
        for i in range(1,len(diff_list)):
            ans = max(ans,diff_list[i] + diff_list[i-1] + 2)

    print((ans + 1))
# Original solution
while 1:
	n,k = list(map(int,input().split()))
	s = [0]*(n+1)
	ss = [0]*(n+1)
	if n == 0: break
	c = sorted([int(input()) for i in range(k)])
	if c[0] == 0:
		for i in c[1:]:
			s[i] = s[i-1]+1
			ss[i] = ss[i-1]+1
			if s[i-1] == 0 and s[i-2] > 0:
				ss[i] = s[i] + s[i-2] + 1
		print(max(ss))
	else:
		for i in c:
			s[i] = s[i-1] + 1
		print(max(s))

# Optimized solution
while 1:
	n,k = list(map(int,input().split()))
	s = [0]*(n+1)
	if n == 0: break
	c = sorted([int(input()) for i in range(k)])
	have0 = 1 if c[0] == 0 else 0
	jump = 0
	for i in c[have0:]:
		s[i] = s[i-1] + 1
		if have0 and s[i-1] == 0 and s[i-2] > 0:
			s[i] += s[i-2] + 1 - jump
			jump = s[i-2] + 1
		if s[i-1] == 0 and s[i-2] == 0:
			jump = 0
	print(max(s))
# Original solution
while True:
  n = int(eval(input()))
  if not n: break
  count = 0
  flag = -1
  lst = [0]
  for i in range(n):
    a = int(eval(input()))
    if flag == a:
      lst[-1] += 1
    else:
      if i % 2 == 0:
        lst.append(1)
        flag = a
      else:
        if len(lst) == 1:
          lst[-1] += 1
          flag = a
        elif len(lst) >= 2:
          lst.append(lst.pop() + lst.pop() + 1)
          flag = a
  ans = 0
  if flag == 0:
    for i in range(-1,len(lst) * (-1) - 1,-2):
      ans += lst[i]
  elif flag == 1:
    for i in range(-2,len(lst) * (-1) - 1,-2):
      ans += lst[i]
  print(ans)



# Optimized solution
def main():
  while True:
    n = int(eval(input()))
    if not n: break
    flag = -1
    lst = []
    for i in range(n):
      a = int(eval(input()))
      if flag == a:
        lst[-1] += 1
      else:
        if i % 2 == 0:
          lst.append(1)
          flag = a
        else:
          if len(lst) == 1:
            lst[-1] += 1
            flag = a
          elif len(lst) >= 2:
            lst[-2] = lst[-2] + lst[-1] + 1
            lst.pop()
            flag = a
    ans = 0
    if flag == 0:
      for i in range(-1,len(lst) * (-1) - 1,-2):
        ans += lst[i]
    elif flag == 1:
      for i in range(-2,len(lst) * (-1) - 1,-2):
        ans += lst[i]
    print(ans)

main()
# Original solution
n, m = list(map(int, input().split()))
ans = -1
mod = pow(10, 9) + 7

if abs(n-m) > 1:
    ans = 0
else:
    if abs(n-m) == 0:
        a = 1
        for i in range(1, n+1):
            a *= i
        ans = a*a*2
    if abs(n-m) == 1:
        a = 1
        for i in range(1, min(n, m)+1):
            a *= i
        b = a * max(n, m)
        ans = a * b

print((ans%mod))


# Optimized solution
import math
n, m = list(map(int, input().split()))
ans = -1
mod = pow(10, 9) + 7

if abs(n-m) > 1:
    ans = 0
else:
    if abs(n-m) == 0:
        a = math.factorial(n)
        ans = a*a*2
    if abs(n-m) == 1:
        a = math.factorial(min(n, m))
        b = a * max(n, m)
        ans = a * b

print((ans%mod))
# Original solution
n,m=list(map(int,input().split()))
mod=10**9+7
import sys
sys.setrecursionlimit(100002)
def kaijou(x):
  if x==1:
    return 1
  else:
    return ((x%mod)*kaijou(x-1))%mod

if abs(m-n)==1:
  n2=kaijou(n)
  m2=kaijou(m)
  print(((n2*m2)%mod))
elif abs(m-n)==0:
  n2=kaijou(n)
  m2=kaijou(m)
  print((2*(n2*m2)%mod))
else:
  print((0))

# Optimized solution
n,m=list(map(int,input().split()))
mod=10**9+7
nkai=1
mkai=1
for i in range(1,n+1):
  nkai*=(i%mod)
  nkai=(nkai%mod)
for i in range(1,m+1):
  mkai*=(i%mod)
  mkai=(mkai%mod)
if abs(n-m)>=2:
  print((0))
elif abs(n-m)==1:
  print(((mkai*nkai)%mod))
elif abs(n-m)==0:
  print(((mkai*nkai*2)%mod))
# Original solution

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

def func(n):
    sum = 1
    for i in range(1, n+1):
        sum *= i
    return sum % (10**9 + 7)

if abs(N - M) == 0:
    ans = 2 * func(N)*func(M)
elif abs(N - M) == 1:
    ans = func(N)*func(M)
    
print((ans % (10**9 + 7)))


# Optimized solution
N, M = list(map(int, input().split()))
ans = 0
MOD = 10**9 + 7

def func(n):
    sum = 1
    for i in range(1, n+1):
        sum = sum*i % MOD
    return sum 

if abs(N - M) == 0:
    ans = 2 * func(N)*func(M)
elif abs(N - M) == 1:
    ans = func(N)*func(M)
    
print((ans % MOD))
# Original solution
import sys

res=10**9+7
def permutation(n):
  x=1
  for i in range(n):x=(x*(i+1))
  return(x)
n,m=list(map(int,input().split()))
n%=res
m%=res
if(n>m+1 or m>n+1):
  print((0))
elif(n==m):
  p=permutation(n)
  print(((2*p*p)%res))
else:
  ma=max(n,m)
  p=permutation(ma)
  p2=p//ma
  print(((p*p2)%res))


# Optimized solution
import sys

res=10**9+7
def permutation(n):
  x=1
  for i in range(n):x=(x*(i+1))%res
  return(x%res)
n,m=list(map(int,input().split()))
n%=res
m%=res
if(n>m+1 or m>n+1):
  print((0))
elif(n==m):
  p=permutation(n)
  print(((2*p*p)%res))
else:
  mi=min(n,m)
  p=permutation(mi)
  p2=p*max(n,m)
  print(((p*p2)%res))
# Original solution
def kaijo(n):
    fact = 1
    for i in range(1, n+1):
        fact *=i
    return fact
    
n, m=list(map(int, input().split()))
if n-m>=2 or m-n>=2:
    print((0))
elif n!=m:
    print((kaijo(m)*kaijo(n)%(10**9+7)))
else:
    print((2*kaijo(m)*kaijo(n)%(10**9+7)))

# Optimized solution
import math

n, m=list(map(int, input().split()))
if n-m>=2 or m-n>=2:
    print((0))
elif n!=m:
    print((math.factorial(m)*math.factorial(n)%(10**9+7)))
else:
    print((2*math.factorial(m)*math.factorial(n)%(10**9+7)))
# Original solution
import math
n,m = list(map(int, input().split()))

num_b = max([n,m]) #多い方
num_l = min([n,m]) #少ない方
ans = 0
if num_b - num_l >= 2: #差が2以上あると、隣接なしでは並べられない
  ans = 0
elif num_b - num_l == 1:
  #差が1匹の場合
  #多い方が(num_b)!通り、少ない方が(num_l)!通りの並び方なので、その積をとる
  ans = math.factorial(num_b) * math.factorial(num_l) % (10 ** 9 + 7)
else:
  #差が0匹の場合
  #一方を先に並べる。(num_b)!通り。もう一方をまず間に入れる。(num_l - 1)匹選ぶ方法がnum_l通りで並べ方が(num_l - 1)!通り残りを左右のどちらに置くかで2通り
  ans = math.factorial(num_b) * num_l * math.factorial(num_l - 1) * 2 % (10 ** 9 + 7)
  
print(ans)

# Optimized solution

N,M = list(map(int, input().split()))
MOD = 10**9+7

if abs(N - M) > 1:
    print((0))
    exit()

factorial = [1] * (max(N,M)+1)
for i in range(1,max(N,M)+1):
    factorial[i] = (factorial[i-1]*i) % MOD

if abs(N - M) == 0:
    ans = ((factorial[N]**2) * 2) % MOD
else:
    ans = (factorial[N] * factorial[M]) % MOD
print(ans)
# Original solution
n,m=list(map(int,input().split()))
mod=10**9+7
import math
a=math.factorial(n)*math.factorial(m)
if abs(n-m)==0:
    print((2*a%mod))
    exit()
if abs(n-m)>1:
    print((0))
    exit()
print(a)

# Optimized solution
import math

n,m=list(map(int,input().split()))
a=math.factorial(n) * math.factorial(m) 
if abs(n-m) == 0:
    a *= 2
elif abs(n-m) > 1:
    a = 0
print((a%1000000007))
# Original solution

n,m=list(map(int,input().split()))
import math

a=math.factorial(n) * math.factorial(m) 
if abs(n-m) == 0:
    a *= 2
elif abs(n-m) > 1:
    a = 0
print((a%1000000007))


# Optimized solution
import math
n,m=list(map(int,input().split()))
mod=10**9+7
a=math.factorial(n)*math.factorial(m)
if abs(n-m)==0:
    print((2*a%mod))
    exit()
elif abs(n-m)>1:
    a=0
print((a%mod))
# Original solution
from math import factorial

n, m = list(map(int, input().split()))
if n == m:
    ans = factorial(n) % (10 ** 9 + 7)
    ans = ans ** 2 % (10 ** 9 + 7)
    print((ans * 2 % (10 ** 9 + 7)))
elif abs(n - m) == 1:
    ans1 = factorial(n) % (10 ** 9 + 7)
    ans2 = factorial(m) % (10 ** 9 + 7)
    print((ans1 * ans2 % (10 ** 9 + 7)))
else:
    print((0))

# Optimized solution
from math import factorial

mod = 10 ** 9 + 7
n, m = list(map(int, input().split()))
print((
    ((factorial(n) % mod) ** 2 % mod) * 2 % mod
    if n == m
    else (factorial(n) % mod) * (factorial(m) % mod) % mod
    if abs(n - m) == 1
    else 0
))
# Original solution
def fct(x):
	t = int(1)
	for i in range(1, x+1):
		t = t * int(i)
	return t

inpt = list(map(int, input().split()))
n = inpt[0]
m = inpt[1]

ans = int(0)

if abs(n-m) < 2:
	ans = fct(n)*fct(m)
	if n == m:
		ans = 2 * ans

print(ans)

# Optimized solution
def fct(x):
	t = 1
	for i in range(1, x+1):
		t = (t * int(i)) % 1000000007
	return t

inpt = list(map(int, input().split()))
n = inpt[0]
m = inpt[1]

ans = 0

if abs(n-m) < 2:
	ans = (fct(n)*fct(m)) % 1000000007
	if n == m:
		ans = (2 * ans) % 1000000007

print(ans)
# Original solution
import sys
n,m = list(map(int,input().split()))

if abs(n-m) >= 2:
    print((0))
    sys.exit()

if abs(n-m) == 1:
    x = max(n,m)
    for i in range(1,min(n,m)+1):
        x = x*i**2 % (10**9 + 7)

else:
    x = 2
    for i in range(1,n+1):
        x = x*i**2 % (10**9 + 7)
print(x)

# Optimized solution
n,m = list(map(int,input().split()))

if abs(n-m) >= 2:
    print((0))
    
elif abs(n-m) == 1:
    x = max(n,m)
    for i in range(1,min(n,m)+1):
        x = x*i**2 % (10**9 + 7)
    print(x)
else:
    x = 2
    for i in range(1,n+1):
        x = x*i**2 % (10**9 + 7)
    print(x)
# Original solution
def factorial(n):
    p = 1
    for i in range(1, n+1):
        p *= i
    return p
n, m = list(map(int, input().split()))
ans = 0
if abs(n-m) == 1:
    ans = factorial(n) * factorial(m)
elif n == m:
    ans = 2 * factorial(n) * factorial(m)
print((ans % (10 ** 9 + 7)))


# Optimized solution
n, m = list(map(int, input().split()))
ans = 0
d = [0] * (max([n,m])+1)
def factorial(n):
    global d
    d[0] = 1
    for i in range(1, n+1):
        d[i] = ((i+1) * d[i-1]) % (10** 9 +7)
factorial(max(m,n))
if abs(n-m) == 1:
    ans = d[n-1] * d[m-1]
elif n == m:
    ans = 2 * d[n-1] * d[m-1]
print((ans % (10 ** 9 + 7)))
# Original solution
import itertools

N, M = list(map(int, input().split()))
np = len(list(itertools.permutations(list(range(N))))) % (10**9+7)
mp = len(list(itertools.permutations(list(range(M))))) % (10**9+7)
if N == M:
    ans = np*mp % (10**9+7)*2
elif abs(N - M) == 1:
    ans = np * mp % (10 ** 9 + 7)
else:
    ans = 0
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
mod = 10**9+7


def for_factorial(n):
    mod = 10**9+7
    val = 1
    for i in range(2, n + 1):
        val = (val*i) % mod
    return val


f = for_factorial(N)*for_factorial(M) % mod
if N == M:
    ans = f*2 % mod
elif abs(N - M) == 1:
    ans = f % mod
else:
    ans = 0

print(ans)
# Original solution
import sys
from math import factorial


sys.setrecursionlimit(500000)
N, M = list(map(int, input().split()))
MOD = 10**9 + 7
diff = abs(N - M)


if diff == 0:
    ans = (factorial(N) * factorial(M)) * 2
elif diff == 1:
    ans = factorial(N) * factorial(M)
else:
    ans = 0


ans %= MOD
print(ans)

# Optimized solution
def fact(n):
    ret = 1
    MOD = 10**9 + 7
    for i in range(1, n + 1):
        ret = ret * i % MOD
    return ret


N, M = list(map(int, input().split()))
MOD = 10**9 + 7
diff = abs(N - M)


if diff == 0:
    ans = (fact(N) * fact(M)) * 2
elif diff == 1:
    ans = fact(N) * fact(M)
else:
    ans = 0


ans %= MOD
print(ans)
# Original solution
n,m=list(map(int,input().split()))
MOD = 1000000007

if abs(n-m) > 1:
    print((0))
    exit(0)
else:
    n_cnt,m_cnt=1,1
    for i in range(1,n+1):
        n_cnt*=i
        n_cnt%=MOD
    for i in range(1,m+1):
        m_cnt*=i
        m_cnt%=MOD

    if abs(n-m) == 0:
        ans=n_cnt*m_cnt*2
    else:
        ans=n_cnt*m_cnt
print((ans%MOD))

# Optimized solution
n, m = list(map(int, input().split()))
MOD = 1000000007
def nPk(n, k):
    r = 1
    while k > 0:
        r *= n
        r %= MOD
        n -= 1
        k -= 1
    return r
if abs(n - m) > 1:
    print((0))
elif n == m:
    print((nPk(n, n) * nPk(m, m) * 2 % MOD))
else:
    print((nPk(n, n) * nPk(m, m) % MOD))
# Original solution
from math import factorial
large_p = 10**9 + 7

def main():
    n, m = list(map(int, input().split()))
    if (abs(n-m)) >= 2:
        print((0))
    else:
        np = factorial(n)
        mp = factorial(m)

        if abs(n-m) == 1:
            r = (np * mp) % large_p
            print(r)
        else:
            r = ((np * mp) * 2) % large_p
            print(r)

if __name__ == '__main__':
    main()


# Optimized solution
large_p = 10**9 + 7

def main():
    n, m = list(map(int, input().split()))
    if (abs(n-m)) >= 2:
        print((0))
    else:
        
        np = 1
        for i in range(n,0,-1):
            np = (np * i) % large_p
        mp = 1
        for i in range(m,0,-1):
            mp = (mp * i) % large_p

        if abs(n-m) == 1:
            r = (np * mp) % large_p
            print(r)
        else:
            r = ((np * mp) * 2) % large_p
            print(r)

if __name__ == '__main__':
    main()
# Original solution
import math

a, b = list(map(int, input().split()))
fa = math.factorial(a)
fb = math.factorial(b)

if abs(a-b) >= 2:
  print((0))
elif abs(a-b) == 1:
  print((fa*fb))
elif abs(a-b) == 0:
  print((2*(fa*fb)))

# Optimized solution
import math

a, b = list(map(int, input().split()))
fa = math.factorial(a)
fb = math.factorial(b)
mod = 10**9 + 7
fa %= mod
fb %= mod
k = fa*fb

if abs(a-b) >= 2:
  print((0))
elif abs(a-b) == 1:
  print((k%mod))
elif abs(a-b) == 0:
  print(((2*k) % mod))
# Original solution
import math

a, b = list(map(int, input().split()))
fa = math.factorial(a)
fb = math.factorial(b)
mod = 10**9 + 7
fa %= mod
fb %= mod
k = fa*fb

if abs(a-b) >= 2:
  print((0))
elif abs(a-b) == 1:
  print((k%mod))
elif abs(a-b) == 0:
  print(((2*k) % mod))

# Optimized solution
import sys
input = sys.stdin.readline
import math

def main():
    n, m = input_list()
    if abs(n-m) > 1:
        print((0))
        exit()
    mod = 10**9 + 7
    diff = abs(n-m)
    if diff == 1:
        ans = math.factorial(n) * math.factorial(m)
        print((ans % mod))
    else:
        ans = 2 * (math.factorial(n) * math.factorial(m))
        print((ans % mod))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()
# Original solution
from math import factorial as frac

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

INF = 10**9 + 7

if abs(N-M) > 1:
    print((0))
elif abs(N-M) == 1:
    print((frac(N)*frac(M)%INF))
else:
    print((((frac(N)*frac(M))*2)%INF))


# Optimized solution
from math import factorial as frac

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

MOD = 10**9 + 7

def nPk(n, k):
    r = 1
    while k > 0:
        r *= n
        r %= MOD
        n -= 1
        k -=  1
    return r

if abs(N-M) > 1:
    print((0))
elif N==M:
    print((((nPk(N,N)*nPk(M,M))*2)%MOD))
else:
    print((nPk(N,N)*nPk(M,M)%MOD))
# Original solution
n,m=list(map(int,input().split()))
if abs(n-m)>1: print((0))
else:
    mod=10**9+7
    def fact(n):
        ans=1
        for i in range(n):
            ans*=(i+1)
        return ans%mod

    ans=(fact(n)*fact(m))%mod
    if n==m: print(((2*ans)%mod))
    else: print(ans)

# Optimized solution
n,m=list(map(int,input().split()))
if abs(n-m)>1: print((0))
else:
    mod=10**9+7
    def fact(n):
        ans=1
        for i in range(n):
            ans*=(i+1)
            ans%=mod
        return ans

    ans=(fact(n)*fact(m))%mod
    if n==m: print(((2*ans)%mod))
    else: print(ans)
# Original solution
import math
n,m=[int(i) for i in input().split()]
if(abs(n-m)>1):
    print((0))
    exit()

def is_even(n):
    if(n%2==0):
        return True
    else:
        return False
if(is_even(n) and is_even(m) or not is_even(n) and not is_even(m)):
    print((math.factorial(n)*math.factorial(m)*2))
    exit()
else:
    print((math.factorial(n)*math.factorial(m)))
    exit()
# if(is_even(n) and is_even(m)):
#     print(math.factorial(n)*math.factorial(m)*2)
#     exit()
# elif(is_even(n) and not is_even(m)):
#     print(math.factorial(n)*math.factorial(m))
#     exit()
# elif(not is_even(n) and is_even(m)):
#     print(math.factorial(m)*math.factorial(n))
#     exit()
# elif(not is_even(n) and not is_even(m)):
#     print(math.factorial(m)*math.factorial(n)*2)
#     exit()

# Optimized solution
import math
n,m=[int(i) for i in input().split()]
if(abs(n-m)>1):
    print((0))
    exit()

def is_even(n):
    if(n%2==0):
        return True
    else:
        return False
if(is_even(n) and is_even(m) or not is_even(n) and not is_even(m)):
    print((math.factorial(n)*math.factorial(m)*2%(10**9+7)))
    exit()
else:
    print((math.factorial(n)*math.factorial(m)%(10**9+7)))
    exit()
# if(is_even(n) and is_even(m)):
#     print(math.factorial(n)*math.factorial(m)*2)
#     exit()
# elif(is_even(n) and not is_even(m)):
#     print(math.factorial(n)*math.factorial(m))
#     exit()
# elif(not is_even(n) and is_even(m)):
#     print(math.factorial(m)*math.factorial(n))
#     exit()
# elif(not is_even(n) and not is_even(m)):
#     print(math.factorial(m)*math.factorial(n)*2)
#     exit()
# Original solution
# C - Reconciled?
N, M = list(map(int, input().split()))
ans_N = 1
ans_M = 1

if abs(N - M) >= 2:
    print((0))
else:
    for i in range(N):
        ans_N_1 = (M-i)*(N-i) % (10**9+7)
        ans_N = ans_N * ans_N_1

    for j in range(M):
        ans_M_1 = (M-j)*(N-j) % (10**9+7)
        ans_M = ans_M * ans_M_1
    print((ans_N+ans_M))

# Optimized solution
# C - Reconciled?
N, M = list(map(int, input().split()))
ans_N = 1
ans_M = 1
mod = 10**9+7

if abs(N - M) >= 2:
    print((0))
else:
    for i in range(N):
        ans_N = ans_N * ((M - i) * (N - i)) % mod
    for j in range(M):
        ans_M = ans_M * ((M - j) * (N - j)) % mod
    print(((ans_N+ans_M)% mod))
# Original solution
from math import factorial
MOD = 10**9+7
N,M = list(map(int,input().split()))
ans = 0
if abs(N-M) > 1:
    pass
elif abs(N-M) ==1:
    ans = factorial(N)*factorial(M) % MOD
elif N==M:
    ans = 2*factorial(N)*factorial(M) % MOD

print(ans)

# Optimized solution
from math import factorial
MOD = 10**9+7
N,M = list(map(int,input().split()))
ans = 0
if abs(N-M) > 1:
    pass
elif abs(N-M) ==1:
    ans = (factorial(N) % MOD * factorial(M) % MOD) % MOD
elif N==M:
    ans = ( 2 * factorial(N) % MOD * factorial(M) % MOD) % MOD

print(ans)
# Original solution
import math
n,m = list(map(int,input().split()))
a = 1000000007
if not (0 <= abs(n-m) <= 1):
    print((0))
    exit()

if n == m:
    num = 2
else:
    num = 1
print((num*math.factorial(n)*math.factorial(m) % a))

# Optimized solution
n,m = list(map(int,input().split()))
a = 10**9+7
if m > n:
    n,m = m,n
if not (0 <= n-m <= 1):
    print((0))
    exit()
 
if n == m:
    num = 2
    n = 1
else:
    num = 1
t = 1
for i in range(1,m+1):
    t *= i
    t %= a
print((num*t*t*n%a))
# Original solution
N,M=list(map(int,input().split()))

div=10**9+7
tmp=1
K=min(N,M)
diff=abs(N-M)
for i in range(K):
    tmp*=(i+1)%div
ans=max(0,(2-diff)*tmp*tmp*(1+K*diff))%div
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
MOD = 10 ** 9 + 7
nn = 1
mm = 1
for i in range(1, N + 1):
  nn = (nn * i) % MOD
for j in range(1, M + 1):
  mm = (mm * j) % MOD
if abs(N - M) >= 2:
  ans = 0
elif abs(N - M) == 1:
  ans = (nn * mm) % MOD
else:
  ans = (2 * nn * mm) % MOD
print(ans)