Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

-----Constraints-----
 - 1 ≤ N,M ≤ 10^5

-----Input-----
Input is given from Standard Input in the following format:
N M

-----Output-----
Print the number of possible arrangements, modulo 10^9+7.

-----Sample Input-----
2 2

-----Sample Output-----
8

We will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.

Difficulty: EASY

Solutions:
import math
(n, m) = map(int, input().split())
mod = 10 ** 9 + 7
if abs(n - m) > 1:
	print(0)
	return
dog = math.factorial(n)
monkey = math.factorial(m)
if abs(n - m) == 1:
	ans = dog * monkey % mod
elif n == m:
	ans = dog * monkey * 2 % mod
print(ans % mod)


(N, M) = map(int, input().split())
a = [0] * (max(N, M) + 1)
a[0] = 1
a[1] = 1
for i in range(2, len(a)):
	a[i] = i * a[i - 1] % 1000000007
if N == M:
	print(a[N] * a[M] * 2 % 1000000007)
elif abs(N - M) == 1:
	print(a[N] * a[M] % 1000000007)
else:
	print(0)


(N, M) = map(int, input().split())
x = abs(N - M)
if x >= 2:
	print(0)
else:
	mod = 10 ** 9 + 7
	a = 1
	for i in range(2, N + 1):
		a *= i
		a %= mod
	b = 1
	for i in range(2, M + 1):
		b *= i
		b %= mod
	if x == 0:
		print(a * b * 2 % mod)
	else:
		print(a * b % mod)


(N, M) = list(map(int, input().split()))
mod = 1000000007
if abs(N - M) > 1:
	print(0)
elif (N + M) % 2 == 1:
	x = max(N, M)
	y = min(N, M)
	Sum = 1
	for i in range(N + M):
		if i % 2 == 0:
			Sum *= x - i // 2
			Sum %= mod
		else:
			Sum *= y - i // 2
			Sum %= mod
	print(Sum)
else:
	Sum = 1
	for i in range(2 * N):
		Sum *= N - i // 2
		Sum %= mod
	Sum *= 2
	Sum %= mod
	print(Sum)


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


(n, m) = list(map(int, input().split()))
mod = 10 ** 9 + 7
l = n + m
ans = 1
b = max(n, m)
s = min(n, m)
for i in range(l):
	if i % 2 == 0:
		tmp = b - i // 2
		if tmp > 0:
			ans = ans % mod * (tmp % mod)
		else:
			print(0)
			return
	else:
		tmp = s - i // 2
		if tmp > 0:
			ans = ans % mod * (tmp % mod)
		else:
			print(0)
			return
if l % 2 == 0:
	ans = ans % mod * (2 % mod)
print(ans % mod)


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

def f(n):
	ans = n
	for i in range(1, n):
		ans *= i
		ans %= 1000000007
	return ans
if n == m:
	print(f(n) ** 2 * 2 % 1000000007)
elif n == m + 1 or m == n + 1:
	print(f(n) * f(m) % 1000000007)
else:
	print(0)


(n, m) = map(int, input().split(' '))
if abs(n - m) >= 2:
	print(0)
else:
	temp = 1
	mod = 10 ** 9 + 7
	for i in range(1, min(n, m) + 1):
		temp *= i
		temp %= mod
	if n != m:
		print(temp ** 2 * max(n, m) % mod)
	else:
		print(temp ** 2 * 2 % mod)


(n, m) = list(map(int, input().split()))
p = 10 ** 9 + 7

def ka(t):
	an = 1
	for i in range(2, t + 1):
		an = an * i % p
	return an
if n == m + 1 or n == m - 1:
	print(ka(n) * ka(m) % p)
elif n == m:
	print(ka(n) * ka(m) * 2 % p)
else:
	print(0)


(n, m) = [int(x) for x in input().split()]
mod = 10 ** 9 + 7

def kaizyou(p):
	ans = 1
	for i in range(1, p + 1):
		ans *= i
		if ans >= mod:
			ans %= mod
	return ans
res = 0
if abs(m - n) <= 1:
	res += kaizyou(m)
	res %= mod
	res *= kaizyou(n)
	res %= mod
	if n == m:
		res *= 2
	res %= mod
print(res)


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


(n, m) = list(map(int, input().split()))
MOD = int(1000000000.0) + 7
fac = [-1 for _ in range(100001)]
fac[1] = 1
for i in range(1, 100000):
	fac[i + 1] = (i + 1) * fac[i] % MOD
if abs(n - m) > 1:
	print(0)
	return
ans = 0
if n == m:
	ans = fac[n] * fac[m] * 2 % MOD
else:
	ans = fac[n] * fac[m] % MOD
print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
if abs(n - m) > 1:
	print(0)
	return
f = [1]
for i in range(1, max(n, m) + 1):
	x = f[i - 1] * i
	if x > 10 ** 9 + 7:
		x %= 10 ** 9 + 7
	f.append(x)
if n != m:
	print(f[n] * f[m] % (10 ** 9 + 7))
else:
	print(f[n] * f[m] * 2 % (10 ** 9 + 7))


(N, M) = [int(x) for x in input().split()]
MOD = 10 ** 9 + 7
if max(N, M) - min(N, M) > 1:
	print(0)
	return

def floor(n):
	result = n
	for i in range(n - 1, 0, -1):
		result *= i
		result %= MOD
	return result
r = floor(max(N, M))
t = floor(min(N, M))
if r == t:
	result = r * t * 2 % MOD
else:
	result = r * t % MOD
print(result)


import math
(n, m) = map(int, input().split())
mod = 10 ** 9 + 7
fact_n = math.factorial(n) % mod
fact_m = math.factorial(m) % mod
if abs(n - m) >= 2:
	print(0)
elif n == m:
	print(fact_n * fact_m * 2 % mod)
else:
	print(fact_n * fact_m % mod)


import math

def ModFact(N, Mod):
	Num = 1
	for T in range(2, N + 1):
		Num = Num * T % Mod
	return Num
(N, M) = (int(T) for T in input().split())
Mod = 10 ** 9 + 7
if N == M:
	print(2 * ModFact(N, Mod) * ModFact(M, Mod) % Mod)
elif N == M + 1 or M == N + 1:
	print(ModFact(N, Mod) * ModFact(M, Mod) % Mod)
else:
	print(0)


from math import factorial as fac
(N, M) = map(int, input().split())
if abs(N - M) > 1:
	print(0)
elif abs(N - M) == 1:
	print(fac(N) * fac(M) % 1000000007)
else:
	print(2 * fac(N) * fac(M) % 1000000007)


MOD = 1000000007
(n, m) = map(int, input().split())
if abs(n - m) > 1:
	print(0)
else:
	if abs(n - m) == 1:
		ans = 1
	else:
		ans = 2
	for i in range(n):
		ans = ans * (i + 1) % MOD
	for i in range(m):
		ans = ans * (i + 1) % MOD
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7

def I():
	return int(input())

def F():
	return float(input())

def S():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LS():
	return input().split()

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

def resolve():
	(N, M) = LI()
	if N == M:
		ans = 2 * pow(fact_mod(N, MOD), 2, MOD)
		ans %= MOD
		print(ans)
	elif abs(N - M) <= 1:
		ans = fact_mod(N, MOD) * fact_mod(M, MOD)
		ans %= MOD
		print(ans)
	else:
		print(0)

def __starting_point():
	resolve()
__starting_point()


(n, m) = map(int, input().split())
if abs(n - m) >= 2:
	print(0)
	return
ans = 1
div = 10 ** 9 + 7
for i in range(1, n + 1):
	ans = ans * i % div
for i in range(1, m + 1):
	ans = ans * i % div
if n != m:
	print(ans)
else:
	print(ans * 2 % div)


(N, M) = map(int, input().split())
mod = 10 ** 9 + 7
factorial = [1 for i in range(10 ** 5 + 5)]
for i in range(1, 10 ** 5 + 5):
	if i == 1:
		factorial[i] = 1
	else:
		factorial[i] = factorial[i - 1] * i % mod
if abs(N - M) > 1:
	print(0)
	return
if N == M:
	print(factorial[M] ** 2 * 2 % mod)
else:
	print(factorial[M] * factorial[N] % mod)


mod = 10 ** 9 + 7
(n, m) = map(int, input().split())
if abs(n - m) >= 2:
	print(0)
	return
(x, y) = (1, 1)
for i in range(1, n + 1):
	x *= i
	x %= mod
for i in range(1, m + 1):
	y *= i
	y %= mod
if n == m:
	print(2 * x * y % mod)
else:
	print(x * y % mod)


import math
(n, m) = map(int, input().split())
ans = 0
if n == m:
	ans = math.factorial(n) * math.factorial(m) * 2
elif n + 1 == m or n == m + 1:
	ans = math.factorial(n) * math.factorial(m)
else:
	ans = 0
ans = ans % (10 ** 9 + 7)
print(ans)


import sys
import math
mod = 10 ** 9 + 7
(N, M) = map(int, sys.stdin.readline().split())
diff = abs(N - M)
if diff > 1:
	print(0)
	return
n_p = 1
for i in range(1, N + 1):
	n_p *= i
	n_p %= mod
m_p = 1
for i in range(1, M + 1):
	m_p *= i
	m_p %= mod
if diff == 0:
	print(2 * n_p * m_p % mod)
else:
	print(n_p * m_p % mod)


def main():
	(N, M) = list(map(int, input().split()))
	if abs(N - M) > 1:
		return 0
	N_mlt = 1
	M_mlt = 1
	for i in range(1, N + 1, 1):
		N_mlt *= i
		N_mlt = N_mlt % 1000000007
	for i in range(1, M + 1, 1):
		M_mlt *= i
		M_mlt = M_mlt % 1000000007
	ans = N_mlt * M_mlt % 1000000007
	if abs(N - M) == 0:
		ans = ans * 2 % 1000000007
		return ans
	else:
		return ans
print(main())


import math
(a, b) = map(int, input().split())
if abs(a - b) == 1:
	c = math.factorial(a) % (10 ** 9 + 7)
	d = math.factorial(b) % (10 ** 9 + 7)
	print(c * d % (10 ** 9 + 7))
if abs(a - b) == 0:
	c = math.factorial(a) % (10 ** 9 + 7)
	d = math.factorial(b) % (10 ** 9 + 7)
	print(c * d * 2 % (10 ** 9 + 7))
if abs(a - b) >= 2:
	print(0)


import math
(N, M) = map(int, input().split())
if abs(N - M) > 1:
	print(0)
	return
fac = 1
num = 10 ** 9 + 7
for i in range(1, N + 1):
	fac *= i
	if fac > num:
		fac %= num
fac2 = 1
for i in range(1, M + 1):
	fac2 *= i
	if fac2 > num:
		fac2 %= num
if N == M:
	print(fac ** 2 * 2 % num)
else:
	print(fac * fac2 % num)


import math
(n, m) = map(int, input().split())
x = 10 ** 9 + 7
ans = 0
if n == m:
	ans += math.factorial(n) * math.factorial(m) * 2
	print(ans % x)
	return
elif n >= m and n - m == 1:
	ans += math.factorial(n) * math.factorial(m)
	print(ans % x)
	return
elif m >= n and m - n == 1:
	ans += math.factorial(n) * math.factorial(m)
	print(ans % x)
	return
else:
	print(ans % x)


import math as m
(N, M) = map(int, input().split())
w = 1000000007
if abs(N - M) < 2:
	if N == M:
		print(m.factorial(N) ** 2 * 2 % w)
	else:
		print(m.factorial(N) * m.factorial(M) % w)
else:
	print(0)


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

def factorial(n):
	ans = 1
	i = 0
	while i < n:
		ans *= n - i
		ans %= mod
		i += 1
	return ans
if abs(N - M) >= 2:
	print(0)
elif N == M:
	ans = factorial(N) * factorial(M) * 2 % mod
	print(ans)
else:
	ans = factorial(N) * factorial(M) % mod
	print(ans)


(N, M) = map(int, input().split())
abs_NM = abs(N - M)
if abs_NM > 1:
	print(0)
	return
p = 10 ** 9 + 7
ans = 1
for i in range(1, N + 1):
	ans = ans * i % p
for i in range(1, M + 1):
	ans = ans * i % p
if abs_NM == 0:
	ans = ans * 2 % p
print(ans)


MOD = pow(10, 9) + 7

def MODINV(n: int, MOD=MOD):
	return pow(n, MOD - 2, MOD)

def perm(n, k, MOD):
	numer = 1
	for i in range(n, n - k, -1):
		numer *= i
		numer %= MOD
	return numer

def main():
	(N, M) = list(map(int, input().split()))
	if N == M + 1 or N + 1 == M:
		ans = perm(N, N, MOD) * perm(M, M, MOD) % MOD
	elif N == M:
		ans = 2 * (perm(N, N, MOD) * perm(M, M, MOD)) % MOD
	else:
		ans = 0
	print(ans)

def __starting_point():
	main()
__starting_point()


from math import factorial
mod = 10 ** 9 + 7
(n, m) = 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)


from math import factorial as f
(n, m) = list(map(int, input().split()))
mod = 10 ** 9 + 7
if abs(n - m) == 1:
	res = f(n) * f(m)
	print(res % mod)
elif n == m:
	res = f(n) * f(m) * 2
	print(res % mod)
else:
	print(0)


def factorial(a):
	result = 1
	for i in range(1, a + 1):
		result *= i
		result %= 1000000007
	return result
(N, M) = map(int, input().split())
if N == M:
	ans = 2 * factorial(N) ** 2 % 1000000007
elif abs(N - M) == 1:
	ans = max(N, M) * factorial(min(N, M)) ** 2 % 1000000007
else:
	ans = 0
print(ans)


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

def mod(num):
	return num % (10 ** 9 + 7)

def calc():
	dp[1] = 1
	for i in range(2, maxmn + 1):
		dp[i] = mod(dp[i - 1] * i)
absnm = abs(N - M)
maxmn = max(N, M)
dp = [0] * (maxmn + 1)
if absnm > 1:
	print(0)
else:
	calc()
	if absnm == 1:
		r = mod(dp[M] * dp[N])
	elif absnm == 0:
		r = mod(dp[M] * dp[N] * 2)
	else:
		r = 0
	print(r)


(N, M) = map(int, input().split())
a = abs(N - M)
mod = 10 ** 9 + 7
n = 1
for i in range(N):
	n *= N - i
	n %= mod
m = 1
for i in range(M):
	m *= M - i
	m %= mod
if a > 1:
	print(0)
elif a == 1:
	print(n * m % mod)
else:
	print(n * m * 2 % mod)


import math

def main():
	(N, M) = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	if abs(N - M) > 1:
		ans = 0
	elif N - M == 1:
		ans = math.factorial(M) ** 2 * N % mod
	elif N - M == -1:
		ans = math.factorial(N) ** 2 * M % mod
	else:
		ans = math.factorial(N) ** 2 * 2 % mod
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, M) = list(map(int, input().split()))
from math import factorial
mod = 10 ** 9 + 7
if abs(N - M) > 1:
	print(0)
elif abs(N - M) == 1:
	print(factorial(N) * factorial(M) % mod)
else:
	print(2 * factorial(N) * factorial(M) % mod)


(n, m) = list(map(int, input().split()))
mod = 10 ** 9 + 7

def permitation(x):
	res = 1
	for i in range(1, x + 1):
		res = res * i % mod
	return res
pn = permitation(n)
pm = permitation(m)
if n == m:
	res = pn * pm * 2 % mod
	print(res)
elif n == m - 1 or n == m + 1:
	res = pn * pm % mod
	print(res)
else:
	print(0)


(n, m) = map(int, input().split())
(n, m) = (max(n, m), min(n, m))
div = 10 ** 9 + 7
res = 1
if n - m == 0:
	for i in range(1, n + 1):
		res *= i
		res %= div
	res = res * res * 2
	print(res % div)
elif n - m == 1:
	for i in range(1, n + 1):
		res *= i
		res %= div
	for i in range(1, m + 1):
		res *= i
		res %= div
	print(res)
else:
	print(0)


(n, m) = map(int, input().split())
if n < m:
	(n, m) = (m, n)
if m + 1 == n or m == n:
	if m + 1 == n:
		ans = 1
	else:
		ans = 2
	k = 1
	for i in range(1, n + 1):
		k *= i
		if i == m:
			ans *= k
		k = k % (10 ** 9 + 7)
	ans *= k
	print(ans % (10 ** 9 + 7))
else:
	print(0)


import math
(n, m) = map(int, input().split())
a = math.factorial(m)
b = math.factorial(n)
if 1 < abs(n - m):
	print(0)
elif abs(n - m) == 0:
	print(a * b * 2 % 1000000007)
elif abs(m - n) == 1:
	print(a * b % 1000000007)


MOD = 1000000007

def fac(x):
	ret = 1
	for i in range(1, x + 1):
		ret *= i
		ret %= MOD
	return ret
(N, M) = list(map(int, input().split()))
if N == M:
	print(fac(N) ** 2 * 2 % MOD)
elif abs(N - M) == 1:
	print(fac(N) * fac(M) % MOD)
else:
	print(0)


(N, M) = map(int, input().split())
MOD = 10 ** 9 + 7
if abs(N - M) >= 2:
	ans = 0
else:
	Mfact = 1
	for m in range(1, M + 1):
		Mfact = Mfact * m % MOD
	Nfact = 1
	for n in range(1, N + 1):
		Nfact = Nfact * n % MOD
	ans = Nfact * Mfact % MOD
	if abs(N - M) == 0:
		ans = ans * 2 % MOD
print(ans)


MOD = 10 ** 9 + 7

def modFact(x):
	if x < 1:
		raise ValueError
	res = 1
	for i in range(x):
		res = res * (i + 1) % MOD
	return res

def solve(n, m):
	if abs(n - m) > 1:
		return 0
	elif abs(n - m) == 1:
		return modFact(n) * modFact(m) % MOD
	else:
		return modFact(n) * modFact(m) * 2 % MOD

def main():
	(N, M) = list(map(int, input().split()))
	print(solve(N, M))
	return

def __starting_point():
	main()
__starting_point()


def solve():
	(N, M) = map(int, input().split())
	if abs(N - M) > 1:
		return 0
	mod = 10 ** 9 + 7
	ans = 2 - abs(N - M)
	for i in range(N):
		ans *= i + 1
		ans %= mod
	for i in range(M):
		ans *= i + 1
		ans %= mod
	return ans
print(solve())


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


import math
(N, M) = map(int, input().split())
p = 10 ** 9 + 7
dog = math.factorial(N)
mon = math.factorial(M)
if N == M:
	ans = dog * mon * 2 % p
elif abs(N - M) == 1:
	ans = dog * mon % p
else:
	ans = 0
print(ans)


(n, m) = map(int, input().split())
mod = 10 ** 9 + 7
if abs(n - m) > 1:
	print(0)
else:
	if n < m:
		(n, m) = (m, n)
	n_parm = 1
	for i in range(n, 0, -1):
		n_parm = n_parm * i % mod
	m_parm = 1
	for i in range(m, 0, -1):
		m_parm = m_parm * i % mod
	ans = n_parm * m_parm % mod
	if m == n:
		ans = ans * 2 % mod
	print(ans)


(N, M) = map(int, input().split())
t = 10 ** 9 + 7
import math
n = math.factorial(N) % t
m = math.factorial(M) % t
if 2 <= abs(N - M):
	print(0)
elif abs(N - M) == 1:
	print(n * m % t)
else:
	print(n * m * 2 % t)


(n, m) = list(map(int, input().split()))
mod = 10 ** 9 + 7

def fact(n, mod):
	ans = 1
	for i in range(2, n + 1):
		ans = ans * i
		ans = ans % mod
	return ans
if abs(n - m) >= 2:
	print(0)
elif abs(n - m) == 1:
	print(fact(n, mod) * fact(m, mod) % mod)
elif abs(n - m) == 0:
	print(2 * fact(n, mod) * fact(m, mod) % mod)


(n, m) = list(map(int, input().split()))
ans = 0
rd = 10 ** 9 + 7
if abs(n - m) > 1:
	ans = 0
	print(ans)
elif abs(n - m) == 1:
	tmp = min(n, m)
	tmp_mx = max(n, m)
	sm = 1
	for i in range(tmp):
		sm = sm * (i + 1) % rd
	ans = sm * sm * tmp_mx % rd
	print(ans)
else:
	sm = 1
	for i in range(n):
		sm = sm * (i + 1) % rd
	ans = 2 * sm * sm % rd
	print(ans)


(N, M) = list(map(int, input().split()))
if N == M + 1:
	A = N
	B = M
	ans = 1
elif N + 1 == M:
	A = M
	B = N
	ans = 1
elif N == M:
	A = N
	B = M
	ans = 2
else:
	print(0)
	return
ansa = 1
ansb = 1
for i in range(1, A + 1):
	ansa = ansa * i % (10 ** 9 + 7)
for j in range(1, B + 1):
	ansb = ansb * j % (10 ** 9 + 7)
print(ansa * ansb * ans % (10 ** 9 + 7))


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

def main():
	(N, M) = list(map(int, input().split()))
	mod = 10 ** 9 + 7
	if abs(N - M) > 1:
		ans = 0
	elif abs(N - M) == 1:
		ans = factorial(min(N, M)) ** 2 * max(N, M) % mod
	else:
		ans = factorial(N) ** 2 * 2 % mod
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))
MOD = 10 ** 9 + 7

def fac(k):
	res = 1
	for i in range(2, k + 1):
		res = res * i % MOD
	return res

def solve():
	(n, m) = inl()
	if n < m:
		(n, m) = (m, n)
	if n - m > 1:
		return 0
	if n - m == 1:
		return fac(n) * fac(m) % MOD
	assert n == m
	a = fac(n)
	a = 2 * a * a % MOD
	return a
print(solve())


mod = 10 ** 9 + 7

def factorial(n, mod):
	fact = 1
	for integer in range(1, n + 1):
		fact *= integer
		fact %= mod
	return fact
(N, M) = map(int, input().split())
if abs(N - M) > 1:
	print(0)
else:
	ans = 1
	ans *= factorial(N, mod)
	ans *= factorial(M, mod)
	ans *= 2 - abs(N - M)
	ans %= mod
	print(ans)


(N, M) = map(int, input().split())
abs_NM = abs(N - M)
if abs_NM > 1:
	print(0)
	return
p = 10 ** 9 + 7
min_ = min(N, M)
max_ = max(N, M)
ans = 1
for i in range(1, min_ + 1):
	ans = ans * i % p
	ans = ans * i % p
if abs_NM == 1:
	ans = ans * max_ % p
else:
	ans = ans * 2 % p
print(ans)


import sys
from io import StringIO
import unittest
import math

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '2 2'
		output = '8'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '3 2'
		output = '12'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '1 8'
		output = '0'
		self.assertIO(input, output)

	def test_入力例_4(self):
		input = '100000 100000'
		output = '530123477'
		self.assertIO(input, output)

def resolve():
	(N, M) = list(map(int, input().split()))
	if abs(N - M) > 1:
		print('0')
	elif N == M:
		print(2 * math.factorial(N) * math.factorial(M) % (10 ** 9 + 7))
	else:
		print(math.factorial(N) * math.factorial(M) % (10 ** 9 + 7))

def __starting_point():
	resolve()
__starting_point()


import math
(n, m) = map(int, input().split())
p = 10 ** 9 + 7
nf = math.factorial(n) % p
mf = math.factorial(m) % p
if abs(n - m) > 1:
	ans = 0
elif n == m:
	ans = nf * mf * 2
else:
	ans = nf * mf
print(ans % p)


import sys

def LI():
	return list(map(int, input().split()))
(N, M) = LI()
if abs(N - M) >= 2:
	print(0)
	return
mod = pow(10, 9) + 7
x = 1
if N == M:
	for i in range(1, N + 1):
		x = x * i % mod
	ans = x * x * 2 % mod
else:
	A = max(N, M)
	B = min(N, M)
	for i in range(1, B + 1):
		x = x * i % mod
	y = x * A % mod
	ans = x * y % mod
print(ans)


(n, m) = [int(i) for i in input().split()]
new_n = min(n, m)
new_m = max(n, m)
mod = 10 ** 9 + 7

def ans(n, m):
	if n == m:
		return 2 * kaijyou(n, mod) * kaijyou(m, mod)
	elif m - n == 1:
		return kaijyou(n, mod) * kaijyou(m, mod)
	else:
		return 0

def kaijyou(n, mod):
	ans = 1
	for i in range(1, n + 1):
		ans *= i
		ans = ans % mod
	return ans
print(ans(new_n, new_m) % mod)


import math
mod = 10 ** 9 + 7
(n, m) = list(map(int, input().split()))
if n + 1 < m or m + 1 < n:
	print(0)
	return
elif n == m:
	print(2 * math.factorial(n) ** 2 % mod)
else:
	print(math.factorial(n) * math.factorial(m) % mod)


from math import factorial

def count(n, r):
	if n == r:
		return 2
	else:
		return 1
(N, M) = map(int, input().split())
mod = 10 ** 9 + 7
print(factorial(N) % mod * (count(N, M) % mod) * (factorial(M) % mod) % mod if abs(N - M) < 2 else 0)


(n, m) = list(map(int, input().split()))
f = [1]
p = 10 ** 9 + 7
for i in range(1, max(n, m) + 1):
	f.append(f[-1] * i % p)
if abs(n - m) == 1:
	print(f[n] * f[m] % p)
elif abs(n - m) == 0:
	print(f[n] * f[m] * 2 % p)
else:
	print(0)


import math
(N, M) = list(map(int, input().split()))
if abs(N - M) >= 2:
	print(0)
	return
N = math.factorial(N) % (10 ** 9 + 7)
M = math.factorial(M) % (10 ** 9 + 7)
if N == M:
	print(N * M * 2 % (10 ** 9 + 7))
else:
	print(N * M % (10 ** 9 + 7))


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

def facmod(a, mod):
	res = 1
	for i in range(1, a + 1):
		res = res * i % mod
	return res
mod = 10 ** 9 + 7
mn = min(m, n)
mx = max(m, n)
if abs(mn - mx) > 1:
	ans = 0
elif n == m:
	ans = 2 * facmod(m, mod) * facmod(n, mod) % mod
else:
	ans = facmod(mx, mod) * facmod(mn, mod) % mod
print(ans)


def main():
	(N, M) = [int(n) for n in input().split(' ')]
	if abs(N - M) >= 2:
		print(0)
	elif abs(N - M) == 1:
		print(factorial(N) * factorial(M) % 1000000007)
	else:
		print(factorial(N) * factorial(M) * 2 % 1000000007)

def factorial(n):
	ret = 1
	for i in range(1, n + 1):
		ret = ret * i % 1000000007
	return ret
main()


(N, M) = list(map(int, input().strip().split()))
inf = 10 ** 9 + 7
ans = 1
for n in range(1, N + 1):
	ans *= n
	ans %= inf
for m in range(1, M + 1):
	ans *= m
	ans %= inf
if abs(N - M) >= 2:
	print(0)
elif abs(N - M) == 1:
	print(ans)
else:
	print(ans * 2 % inf)


import math
(n, m) = map(int, input().split())
n_f = math.factorial(n)
m_f = math.factorial(m)
mod = 1000000007
if abs(n - m) > 1:
	print(0)
	return
if n == m:
	print(n_f * m_f * 2 % mod)
else:
	print(n_f * m_f % mod)


def mod1(x):
	mod = 10 ** 9 + 7
	ans = 1
	y = 1
	while y <= x:
		ans = ans * y
		y += 1
		ans = ans % mod
	return ans % mod
(n, m) = map(int, input().split())
if n == m:
	print(2 * mod1(n) * mod1(m) % (10 ** 9 + 7))
elif abs(n - m) == 1:
	print(mod1(n) * mod1(m) % (10 ** 9 + 7))
else:
	print(0)


def factorial(n, mod):
	num = 1
	for i in range(1, n + 1):
		i %= mod
		num *= i
		num %= mod
	return num

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

def __starting_point():
	main()
__starting_point()


def gyakugen(x, p):
	binp = str(bin(p - 2))[::-1]
	ruijou = x
	result = 1
	for i in range(len(binp) - 2):
		if binp[i] == '1':
			result *= ruijou
			result %= p
		ruijou *= ruijou
		ruijou %= mod
	return result
(N, M) = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
if abs(N - M) > 1:
	print(0)
	return
elif N == M:
	ans = 1
	for i in range(1, N + 1):
		ans *= i
		ans %= mod
		ans *= i
		ans %= mod
	ans *= 2
	ans %= mod
	print(ans)
else:
	ans = 1
	m = min(N, M)
	for i in range(1, m + 1):
		ans *= i
		ans %= mod
		ans *= i
		ans %= mod
	ans *= max(N, M)
	ans %= mod
	print(ans)


from math import factorial
(n, m) = 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)


def main():
	from math import factorial
	(n, m) = map(int, input().split())
	p = 10 ** 9 + 7
	if abs(n - m) < 2:
		if n == m:
			print(2 * factorial(n) * factorial(m) % p)
		else:
			print(factorial(n) * factorial(m) % p)
	else:
		print(0)
main()