Problem:
 Score : 300 points    Problem Statement 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 1 2 2      Sample Output 1 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 .       Sample Input 2 3 2      Sample Output 2 12       Sample Input 3 1 8      Sample Output 3 0       Sample Input 4 100000 100000      Sample Output 4 530123477

Solution (Python):
n, m = 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)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import factorial

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

Solution (Python):
n,m = map(int,input().split())
if m>n:
    n,m = m,n
mod = 10**9+7
ans = 1
if n>m+1:
    print(0)
    exit()
if n==m:
    ans = 2
for i in range(1,n+1):
    ans = (ans*i)%mod
for i in range(1,m+1):
    ans = (ans*i)%mod
print(ans)

Solution (Python):
N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
    quit()
MOD = 10 ** 9 + 7
fact = [1] * (max(N, M) + 1)
f = 1
for i in range(1, max(N, M) + 1):
    f = f * i % MOD
    fact[i] = f
print(((N == M) + 1) * fact[N] * fact[M] % MOD)

Solution (Python):
A,B = map(int,input().split())
ans = 1
if A-B == 0:
    for i in range(1,A+1):
        ans = (ans * i) % (10**9+7)
    for i in range(1,B+1):
        ans = (ans * i) % (10**9+7)
    print(ans*2%1000000007)
elif abs(A-B) == 1:
    for i in range(1,A+1):
        ans = (ans * i) % (10**9+7)
    for i in range(1,B+1):
        ans = (ans * i) % (10**9+7)
    print(ans%1000000007)
else:
    print(0)

Solution (Python):
import sys

N, M = [int(n) for n in input().split()]

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

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

N_fact = factorial_mod(N)
M_fact = factorial_mod(M)

if N == M:
    print((2*N_fact*M_fact) % (10**9 + 7))
else:
    print((N_fact*M_fact) % (10**9 + 7))

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

Solution (Python):
n, m = map(int, input().split())

if abs(n-m)>1:
    ans = 0
else:
    if m < n:
        n, m = m, n

    total_n = 1
    for i in range(1,n+1):
        total_n *= i
        if total_n >= 1000000007:
            total_n = total_n % 1000000007

    if n != m:
        ans = (total_n * total_n * m) % 1000000007
    else:
        ans = (total_n * total_n * 2) % 1000000007

print(int(ans))

Solution (Python):
n,m=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)

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

Solution (Python):
import math
n, m = map(int, input().split())

mod = 10**9+7
ans = 0
if abs(n-m) > 1:
    ans = 0
elif abs(n-m) == 1:
    ans = math.factorial(n)*math.factorial(m)
elif abs(n-m) == 0:
    ans = 2 * (math.factorial(n)*math.factorial(m))

print(ans % mod)

Solution (Python):
n, m = map(int, input().split())
mod = 1000000007
fact = [1]
for i in range(max(n, m)):
  fact.append(fact[-1] * (i + 1) % mod)
if n == m:
  print(2 * fact[n] * fact[m] % mod)
elif abs(n - m) == 1:
  print(fact[n] * fact[m] % mod)
else:
  print(0)

Solution (Python):
from math import factorial
n, m = map(int, input().split())
if abs(n - m) == 1:
    print((factorial(n) * factorial(m)) % 1000000007)
elif abs(n - m) == 0:
    print(((factorial(n) * factorial(m)) * 2) % 1000000007)
else:
    print(0)

Solution (Python):
import math


def combinations_count(n):
    return math.factorial(n)


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



if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial
n, m = map(int, input().split())
MOD = 1000000007
if abs(n - m) == 1:
    ans = max(n, m)
elif n == m:
    ans = 2
else:
    ans = 0
ans *= ((factorial(min(n, m)) % MOD)) ** 2
ans %= MOD
print(ans)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n,m = map(int,input().split())
if abs(n-m)>1:
    print(0)
else:
    if n == m:
        ans = (2*math.factorial(n%MOD)*math.factorial(m%MOD))%MOD
        print(ans)
    else:
        ans = (math.factorial(n%MOD)*math.factorial(m%MOD))%MOD
        print(ans)

Solution (Python):
import sys
n, m = map(int, input().split())
r = 10**9 + 7

if 1 < abs(n - m):
    print(0)
    sys.exit()
elif abs(n - m) == 1:
    ans = 1
else:
    ans = 2
    
for i in range(2, n + 1):
    ans *= i
    ans %= r

for i in range(2, m + 1):
    ans *= i
    ans %= r

print(ans)

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

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

N,M=max(N,M),min(N,M)
if N-M>=2:
  print(0)
elif N==M:
  fact=fact_mod(N)
  print(2*fact**2%MOD)
else:
  fact1=fact_mod(M)
  fact2=fact_mod(N)
  print(fact1*fact2%MOD)

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

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

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

Solution (Python):
n , m = map(int, input().split())
N=1000000007
def fac(a):
    ans = 1
    while a>1:
        ans=ans*a%N
        a-=1
    return ans

if abs(n-m)==1:
    ans = fac(n)*fac(m)%N
elif n == m:
    ans = fac(n)*fac(m)*2%N
else:
    ans = 0
print(ans)

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

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

Solution (Python):
import math

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

MOD = 10**9 + 7

if abs(N-M) > 1:
    ans = 0
elif abs(N-M) == 1:
    ans = math.factorial(N) * math.factorial(M)
else:
    ans = math.factorial(N) * math.factorial(M) * 2

print(ans % MOD)

Solution (Python):

import sys

def main():
    N, M = map(int, input().split())
    if abs(N-M) > 1:
        print(0)
        exit()

    p = 10**9 + 7
    ans = 1
    if N == M:
        ans *=2
    
    for i in range(N):
        ans = ans * (i+1) % p
    for j in range(M):
        ans = ans * (j+1) % p
    
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n,m = map(int,input().split())
mod = 10**9 + 7
import math
def perm(n, r):
    return (math.factorial(n) // math.factorial(n - r))%mod

if abs(n-m) >= 2:
    print(0)
else:
    mx = max(n,m)
    mn = min(n,m)
    p = math.factorial(mn)%mod
    k = (mn-1)*math.factorial(mx)%mod if mn == mx else 0
    print(p*(perm(mn+1,mx) - k)%mod)

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

Solution (Python):
import math
mod=10**9+7

def main():
    N,M=map(int,input().split())
    ans=0
    
    if abs(N-M)>=2:
        print(0)
    else:
        if N==M:
            ans+=(math.factorial(N)*math.factorial(M))*2
            ans%=mod
            print(ans)
            
        else:
            ans+=(math.factorial(N)*math.factorial(M))
            ans%=mod
            print(ans)
        
if __name__=="__main__":
    main()

Solution (Python):
N, M = map(int, input().split())
MOD = int(1e9) + 7


def factorial_cor(n):
    fact = 1
    for integer in range(1, n + 1):
        fact = (fact * integer) % MOD
    return fact


if abs(N - M) >= 2:
    print(0)
else:
    if abs(N - M) == 1:
        print((factorial_cor(N) * factorial_cor(M))%MOD)
    else:
        print(((factorial_cor(N) * factorial_cor(M))*2)%MOD)

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

Solution (Python):
from math import factorial

def resolve():
	n, m = map(int, input().split())
	mod = 10**9+7
	if abs(n - m) > 1:
		print(0)
		return
	a = factorial(m) % mod * factorial(n) % mod
	if (n + m) % 2 == 0:
		a = a * 2 % mod
	print(a)
resolve()

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

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

Solution (Python):
import math
mod = 1000000007

n,m = map(int,input().split())
if abs(n-m) >= 2:
    num_dm = 0
elif abs(n-m) == 1:
    num_dm = 1
else:
    num_dm = 2
d_comb_num = math.factorial(n) % mod
m_comb_num = math.factorial(m) % mod
ans = num_dm * d_comb_num * m_comb_num
ans %= mod
print(ans)

Solution (Python):
from math import factorial

if __name__ == "__main__":
    n, m = map(int, input().split())

    mod = 10**9+7

    if n > m + 1 or m > n + 1:
        print(0)
        exit()

    if n == m:
        print((factorial(n)**2 + factorial(m)**2) % mod)
    else:
        print(factorial(n)*factorial(m) % mod)

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

Solution (Python):
from functools import reduce

n, m = map(int, input().split())
if abs(n-m) > 1:
    print(0)
    exit()
MOD = 10**9 + 7
mul_mod = lambda x, y, mod=MOD : x*y % mod
ans = reduce(mul_mod, range(1, n+1)) * reduce(mul_mod, range(1, m+1)) % MOD
if abs(n-m) == 0:
    ans *= 2
print(ans%MOD)

Solution (Python):
from functools import reduce

n, m = map(int, input().split())
if abs(n-m) > 1:
    print(0)
    exit()
mod = 10**9 + 7
mul_mod = lambda x, y : x*y % mod
ans = reduce(mul_mod, range(1, n+1)) * reduce(mul_mod, range(1, m+1)) % mod
if abs(n-m) == 0:
    ans *= 2
print(ans%mod)

Solution (Python):
n,m=map(int,input().split())
ans=1
if abs(n-m)>=2:
    print(0)
    exit()
for i in range(1,max(n,m)+1):
    ans*=i
    ans%=(10**9+7)
for i in range(1,min(n,m)+1):
    ans*=i
    ans%=(10**9+7)
if n==m:
    ans=(ans*2)%(10**9+7)
print(ans)

Solution (Python):
import sys

MOD = 10 ** 9 + 7
MOD = 10 ** 9 + 7
class ModInt:

	def __init__(self, x, inv=None):
		self.x = x.x if isinstance(x, ModInt) else x % MOD
		self.inv = inv

	__str__ = lambda self:str(self.x)
	__repr__ = __str__
	__int__ = lambda self: self.x
	__index__ = __int__

	__add__ = lambda self, other: ModInt(self.x + ModInt(other).x)
	__radd__ = lambda self, other: ModInt(other + self.x)
	__iadd__ = __add__

	__sub__ = lambda self, other: ModInt(self.x - ModInt(other).x)
	__rsub__ = lambda self, other: ModInt(other - self.x)
	__isub__ = __sub__

	__mul__ = lambda self, other: ModInt(self.x * ModInt(other).x)
	__rmul__ = lambda self, other: ModInt(other * self.x)
	__imul__ = __mul__

	__pow__ = lambda self, other: ModInt(pow(self.x, ModInt(other).x, MOD))
	__rpow__ = lambda self, other: ModInt(pow(other, self.x, MOD))
	__pow__ = __pow__

	def __truediv__(self, other):
		if isinstance(other, ModInt) and other.inv != None:
			return ModInt(self.x * other.inv)
		else:
			return ModInt(self.x * pow(ModInt(other).x, MOD - 2, MOD))
	
	def __rtruediv__(self, other):
		if not self.inv:
			return ModInt(other * pow(self.x, MOD - 2, MOD))
		else:
			return ModInt(other * self.inv)

	__itruediv__ = __truediv__

	__floordiv__ = lambda self, other: ModInt(self.x // ModInt(other).x)
	__rfloordiv__ = lambda self, other: ModInt(other // self.x)
	__ifloordiv__ = __floordiv__

	__mod__ = lambda self, other: ModInt(self.x % other)
	__rmod__ = lambda self, other: ModInt(other % self.x)
	__imod__ = __mod__

	__lt__ = lambda self, other: self.x < ModInt(other).x
	__gt__ = lambda self, other: self.x > ModInt(other).x
	__le__ = lambda self, other: self.x <= ModInt(other).x
	__ge__ = lambda self, other: self.x >= ModInt(other).x
	__eq__ = lambda self, other: self.x == ModInt(other).x
	__ne__ = lambda self, other: self.x != ModInt(other).x


class Fact:
	def __init__(self, MAX):
		MAX += 1
		self.fact = [0] * MAX
		finv = [0] * MAX
		inv = [0] * MAX
		self.fact[0] = 1
		self.fact[1] = 1
		finv[0] = 1
		finv[1] = 1
		inv[1] = 1
		for i in range(2, MAX):
			self.fact[i] = self.fact[i - 1] * i % MOD
			inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
			finv[i] = finv[i - 1] * inv[i] % MOD
		for i in range(MAX):
			self.fact[i] = ModInt(self.fact[i], inv=finv[i])
	def __call__(self, value):
		return self.fact[value]



def main():
	n, m = map(int, sys.stdin.readline().split())
	fact = Fact(10**5)
	if abs(n - m) > 1:
		print(0)
		exit()
	ans = fact(n) * fact(m)
	if (n + m) % 2 == 0:
		ans *= 2
	print(ans)

main()

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

if '__main__' == __name__:
    resolve()

Solution (Python):
n,m=map(int,input().split())

if abs(n-m)>=2:
    print(0)
else:
    nm=1
    p=10**9+7
    for ni in range(1,n+1):
        nm=nm*ni%p
    for ni in range(1,m+1):
        nm=nm*ni%p
    if abs(n-m)==1:
        print(nm)
    else:
        print((2*nm)%p)

Solution (Python):
n,m=map(int,input().split())
import math 
mod=10**9+7
if n==m:
    x=math.factorial(n)
    x=x%mod
    x=x**2
    x%=mod
    x*=2
    x%=mod
    print(x)
elif abs(n-m)==1:
    x=min(n,m)
    y=max(n,m)
    ans=math.factorial(x)%mod
    ans*=ans
    ans%=mod
    ans=ans*y
    ans%=mod
    print(ans)
else:
    print(0)

Solution (Python):
import collections
import itertools
import math

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

Solution (Python):
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def factorial(N, mod=MOD):
    res = 1
    for i in range(2, N+1):
        res *= i
        res %= mod
    return res

def main():
    N, M = map(int, readline().rstrip().split())
    if abs(N-M) > 1:
        ans = 0
    elif N == M:
        ans = factorial(N) ** 2 * 2
    else:
        ans = factorial(min(N, M)) ** 2 * max(N, M)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def factorial(N, mod=MOD):
    res = 1
    for i in range(2, N+1):
        res *= i
        res %= mod
    return res

def main():
    N, M = map(int, readline().rstrip().split())
    if abs(N-M) > 1:
        ans = 0
    elif N == M:
        ans = factorial(N) * factorial(M) * 2
    else:
        ans = factorial(N) * factorial(M)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline
from math import factorial
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, readline().rstrip().split())
    if abs(N-M) > 1:
        ans = 0
    elif N == M:
        ans = (factorial(N) % MOD) * (factorial(M) % MOD) * 2
    else:
        ans = (factorial(N) % MOD) * (factorial(M) % MOD)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial
import sys
sys.setrecursionlimit(2000000)






n, m = list(map(int, input().split()))
if abs(n-m) >= 2:
    print(0)
else:
    if n == m:
        a = factorial(n) * factorial(m) * 2
    else:
        a = factorial(n) * factorial(m)
    print(a % (pow(10, 9)+7))

Solution (Python):
from functools import reduce
mod = 10**9+7
N, M = map(int, input().split())
A = abs(N-M)
if A > 1:
  print(0)
elif A == 1:
  print((reduce(lambda x,y:x*y%mod, range(1, N+1))*reduce(lambda x,y:x*y%mod, range(1, M+1)))%mod)
else:
  print((reduce(lambda x,y:x*y%mod, range(1, N+1))*reduce(lambda x,y:x*y%mod, range(1, M+1))*2)%mod)

Solution (Python):
from math import factorial
n, m = map(int, input().split())
ans = 0
mod = 10**9 + 7
if abs(n-m) <= 1:
    ans = factorial(n)%mod * factorial(m)%mod
    if n==m:
        ans *= 2

print(ans%mod)

Solution (Python):
from math import factorial
n, m = map(int, input().split())

if abs(n - m) > 1:
    print(0)
elif n == m:
    print(factorial(n) * factorial(m) * 2 % (10 ** 9 + 7))
else:
    print(factorial(n) * factorial(m) % (10 ** 9 + 7))

Solution (Python):
from math import factorial
n,m = map(int,input().split())
dist = abs(n-m)
if dist==0:
    ans = factorial(n)*factorial(m)*2
elif dist<2:
    ans = factorial(n)*factorial(m)
else:
    ans = 0
print(ans%(10**9+7))

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

Solution (Python):
import sys

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

mod = 10 ** 9 + 7
N, M = map(int,input().split())
if abs(N - M) >= 2:
    print(0)
    sys.exit()
ans = factorial(N, mod) * factorial(M, mod)
if N == M:
    ans *= 2
print(ans % mod)

Solution (Python):
import math

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

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

Solution (Python):
def main():
  N, M = (int(_) for _ in input().split())
  MOD = 10 ** 9 + 7
  
  def fact(n):
    res = 1
    for i in range(n):
      res *= (i+1)
      res %= MOD
    return res
  
  ret = 0
  if abs(N - M) == 1:
    ret = (fact(N) * fact(M)) % MOD
  elif N == M:
    ret = (2 * fact(N) * fact(M)) % MOD
  else:
    pass
  print(ret)
  return

if __name__ == '__main__':
  main()

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

Solution (Python):
import math

nim, mike = map(int, input().split())
mod = 10**9+7

t = math.factorial(nim)*math.factorial(mike)
if nim == mike:
    print((2*t)%mod)
elif abs(nim-mike) > 1:
    print(0)
elif abs(nim-mike) <= 1:
    print(t%mod)

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

if abs(n -m) > 1:
    print(0)
    
if  abs(n -m) == 0:
    n_ans = 1
    m_ans = 1
    for i in range(1,n+1):
        n_ans *= i
        n_ans %= mod
    for i in range(1,m+1):
        m_ans *= i
        m_ans %= mod
    print(2*n_ans*m_ans%mod)
    
if abs(n -m) == 1:
    n_ans = 1
    m_ans = 1
    for i in range(1,n+1):
        n_ans *= i
        n_ans %= mod
    for i in range(1,m+1):
        m_ans *= i
        m_ans %= mod
    print(n_ans*m_ans%mod)

Solution (Python):
n,m=map(int,input().split())
def mfact(n,mod):
    f=[1]
    for i in range(1,n+1):
        f.append(f[-1]*i%mod)
    return f
if abs(n-m)>1:
    print(0)
else:
    f = mfact(max(m, n),10**9+7)
    if n==m:
        print(pow(f[n],2)*2%(10**9+7))
    else:
        print(f[n]*f[m]%(10**9+7))

Solution (Python):
n,m=map(int,input().split())
if abs(n-m)>1:
  print(0)
  exit()
import math

if abs(n-m)==1:
  n_=math.factorial(n)%(10**9+7)
  m_=math.factorial(m)%(10**9+7)
  print((n_*m_)%(10**9+7))
if abs(n-m)==0:
  n_=math.factorial(n)%(10**9+7)
  m_=math.factorial(m)%(10**9+7)
  print((2*n_*m_)%(10**9+7))

Solution (Python):
import math
def slove(n, m):

    if abs(n-m) >= 2:
        return 0
    elif abs(n-m) == 1:
        ans = math.factorial(n) * math.factorial(m)
        return ans % (10**9 + 7)
    else:
        ans = math.factorial(n) * math.factorial(m) * 2
        return ans % (10**9 + 7)

if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    print(slove(n, m))

Solution (Python):
def main():
    n,m=map(int,input().split())
    ans=1
    mod=10**9+7
    if abs(n-m)>=2:
        print(0)
    elif n==m:
        for i in range(1,n+1):
            ans=(ans*i**2)%mod
        ans=(2*ans)%mod
        print(ans)
    else:
        for i in range(1,min(m,n)+1):
            ans=(ans*i**2)%mod
        ans=(ans*max(m,n))%mod
        print(ans)
if __name__=="__main__":
    main()

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

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

if abs(n-m)>1:
    print(0)
elif abs(n-m)==1:
    num = factorial(min(m,n))
    print(num**2*max(m,n)%mod)
else:
    num = factorial(m)
    print(num**2*2%mod)

Solution (Python):
MOD=1000000007
N,M=map(int,input().split())
if N>M: N,M=M,N
if M-N>1:
  print(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)

Solution (Python):
n, m = map(int, input().split())
mod = 10**9 + 7
def fact(n, mod=10**9 + 7):
  val = 1
  for i in range(2, n+1):
    val = val * i % mod
  return val

if n == m:
  print(2*fact(n)*fact(m) % mod)
elif n == m+1 or n+1 == m:
  print(fact(n)*fact(m) % mod)
else:
  print(0)

Solution (Python):
N, M = map(int, input().split())

MOD = 1000000007

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

dogs = 1
for i in range(1, N + 1):
    dogs *= i
    dogs %= MOD

monks = 1
for i in range(1, M + 1):
    monks *= i
    monks %= MOD

res = (dogs * monks) % MOD
if (N + M) % 2 == 0:
    res *= 2
    res %= MOD

print(res)

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

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

if abs(N - M) > 1:
    print(0)
else:
    ans = fact[N] * fact[M] % MOD
    if N == M:
        ans *= 2
        ans %= MOD
    print(ans)

Solution (Python):
mod = 10 ** 9 + 7
fact = [i for i in range(10**5+1)]
fact[0] = 1
for i in range(10 ** 5):
  fact[i+1] *= fact[i]
  fact[i+1] %= mod
n,m = map(int,input().split())
if abs(n-m)>1:
  print(0)
else:
  if n!=m:
    print(fact[n]*fact[m]%mod)
  else:
    print(fact[n]*fact[m]*2%mod)

Solution (Python):
mod = int(1e9+7)
n,m = map(int,input().split())
if abs(n-m) > 1:
    print(0)
    exit()
if n != m:
    ans = 1
    ans2 = 1
    for i in range(1, m+1):
        ans *= i
        ans %= mod
    for i in range(1,n+1):
        ans2 *= i
        ans2 %= mod
    print(ans*ans2%mod)
else:
    ans = 1
    for i in range(1, n+1):
        ans *= i
        ans %= mod
    print(ans*ans*2%mod)

Solution (Python):
import math
n, m = 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)

Solution (Python):
import math

def permutations(a,b):
    return math.factorial(a)//math.factorial(a-b)

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

Solution (Python):
import math

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

o = math.factorial(n)
p = math.factorial(m)

if abs(n-m) > 1:
  print(0)
elif abs(n-m) == 1:  
  print((o*p)%(int(1e9)+7))
elif n-m == 0:  
  print((2*o*p)%(int(1e9)+7))

Solution (Python):
N = 10**6
mod = 10**9 + 7
fact = [1]
for i in range(1, N+1):
     fact.append(fact[-1]*i%mod)

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

if n-m  > 1 or m-n >1:
     ans=0
elif n-m == 0:
     ans = 2*fact[n]*fact[m]%mod
else:
     ans = fact[n] * fact[m] % mod
print(ans)

Solution (Python):
import math
a,b=map(int,input().split())
m=10**9+7
p=math.factorial(a)
q=math.factorial(b)
if abs(a-b)==0:print(2*p*q%m)
elif abs(a-b)==1:print(p*q%m)
else:print(0)

Solution (Python):
from math import factorial

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

mod = 10 ** 9 + 7

if abs(n - m) > 1:
    ans = 0
else:
    ans = factorial(n) * factorial(m) % mod
    if n == m:
        ans = ans * 2 % mod
print(ans)

Solution (Python):
import sys

import numpy as np
MOD = 10 ** 9 + 7
U = 10 ** 6
def mod_cumprod(a, p=MOD):
  l = len(a); sql = int(np.sqrt(l) + 1)
  a = np.resize(a, sql**2).reshape(sql, sql)
  for i in range(sql - 1): a[:, i+1] *= a[:, i]; a[:, i+1] %= p
  for i in range(sql - 1): a[i+1] *= a[i, -1]; a[i+1] %= p
  return np.ravel(a)[:l]

def make_fac_ifac(n=U, p=MOD):
  fac = np.arange(n + 1); fac[0] = 1
  fac = mod_cumprod(fac)
  ifac = np.arange(n + 1, 0, -1); ifac[0] = pow(int(fac[-1]), p-2, p)
  ifac = mod_cumprod(ifac)[n::-1]
  return fac, ifac

fac, ifac = make_fac_ifac()

def mod_choose(n, r, p=MOD):
  if r > n or r < 0: return 0
  return fac[n] * ifac[r] % p * ifac[n-r] % p

def make_choose_n_table(n=10 ** 9, r=U, p=MOD):
  table = [None] * (r + 1)
  table = np.arange(n + 1, n - r, -1); table[0] = 1
  table[1:] = mod_cumprod(table[1:]) * ifac[1:r+1] % p
  return table

mod_choose_n = make_choose_n_table()

n, m = map(int, sys.stdin.readline().split())

def main():
  d = abs(n - m)
  if d >= 2: res = 0
  elif d == 1: res = fac[n] * fac[m] % MOD
  else: res = fac[n] * fac[m] % MOD * 2 % MOD
  print(res)
  
if __name__ == '__main__':
  main()

Solution (Python):
import sys

MOD = 10 ** 9 + 7
U = 10 ** 6
def make_fac_ifac(n=U, p=MOD):
  fac = [None] * (n + 1)
  fac[0] = 1
  for i in range(n): fac[i+1] = fac[i] * (i + 1) % p
  ifac = [None] * (n + 1)
  ifac[n] = pow(fac[n], p - 2, p)
  for i in range(n, 0, -1): ifac[i-1] = ifac[i] * i % p
  return fac, ifac

fac, ifac = make_fac_ifac()

def mod_choose(n, r, p=MOD):
  if r > n or r < 0: return 0
  return fac[n] * ifac[r] % p * ifac[n-r] % p

def make_choose_n_table(n=10 ** 9, r=U, p=MOD):
  table = [None] * (r + 1)
  table[0] = 1
  j = 1
  for i in range(n, n - r, -1): 
    table[j] = table[j-1] * i % p
    j += 1
  for i in range(1, r + 1): table[i] = table[i] * ifac[i] % p
  return table
    
mod_choose_n = make_choose_n_table()

n, m = map(int, sys.stdin.readline().split())

def main():
  d = abs(n - m)
  if d >= 2: res = 0
  elif d == 1: res = fac[n] * fac[m] % MOD
  else: res = fac[n] * fac[m] % MOD * 2 % MOD
  print(res)
  
if __name__ == '__main__':
  main()

Solution (Python):
N,M = map(int,input().split())
mod = pow(10,9)+7

def f(x,mod):
    k = 1
    res = 1
    while k<x:
        k+=1
        res*=k
        res %= mod
    return res

if abs(N-M)>1:print(0)
elif abs(N-M)==1:
    a = f(min(N,M),mod)
    print(pow(a,2,mod)*max(N,M)%mod)
else:
    a = f(N,mod)
    print(2*pow(a,2,mod)%mod)

Solution (Python):
from math import factorial 
a,b = map(int,input().split())
m = 10**9+7
s = (((factorial(a)%m)*(factorial(b)%m))%m)
if abs(a-b)>=2:
  print(0)
elif abs(a-b)==1:
  print(s)
else:
  print((2*s)%m)

Solution (Python):
import math
N, M = map(int, input().split())
p = 10**9 + 7

if abs(N-M) == 1:
  print((math.factorial(N)*math.factorial(M)) % p)
elif N-M == 0:
  print((math.factorial(N)*math.factorial(M)*2) % p)
else:
  print(0)

Solution (Python):
from math import factorial

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


n, m = map(int, input().split())
mod = 10 ** 9 + 7
if abs(n - m) > 1:
    print(0)
else:
    if n == m:
        res = fac(n, mod) * fac(m, mod) * 2 % mod
    else:
        res = fac(n, mod) * fac(m, mod) % mod
    print(res)

Solution (Python):
def fac(a):
    result = 1
    for i in range(1, a+1):
        result = result * i % (10**9+7)
    return result

n, m = map(int, input().split())
if abs(n-m) >= 2:
    print(0)
else:
    dog = fac(n)
    monkey = fac(m)
    if abs(n-m) == 1:
        print(dog*monkey%(10**9+7))
    else:
        print(2*dog*monkey%(10**9+7))

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