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.
[{"code": "import math\nn, m = map(int, input().split())\nmod = 10**9+7\nif abs(n-m) > 1:\n    print(0)\n    return\n\ndog = math.factorial(n)\nmonkey = math.factorial(m)\nif abs(n-m) == 1:\n    ans = dog*monkey % mod\nelif n == m:\n    ans = dog*monkey*2 % mod\nprint(ans%mod)", "passed": true, "time": 1.09, "memory": 14508.0, "status": "done"}, {"code": "N,M = map(int,input().split())\na = [0]*(max(N,M)+1)\na[0] = 1\na[1] = 1\nfor i in range(2,len(a)):\n    a[i] = i * a[i-1] % 1000000007\n    \nif N==M:\n    print(a[N]*a[M]*2 % 1000000007)\nelif abs(N-M)==1:\n    print(a[N]*a[M] % 1000000007)\nelse:\n    print(0)", "passed": true, "time": 0.17, "memory": 17076.0, "status": "done"}, {"code": "N, M = map(int, input().split())\n\nx = abs(N-M)\nif x >= 2:\n    print(0)\nelse:\n    mod = 10**9+7\n    a = 1\n    for i in range(2, N+1):\n        a *= i\n        a %= mod\n    b = 1\n    for i in range(2, M+1):\n        b *= i\n        b %= mod\n    \n    if x == 0:\n        print(a*b*2%mod)\n    else:\n        print(a*b%mod)", "passed": true, "time": 0.16, "memory": 14340.0, "status": "done"}, {"code": "N, M = list(map(int, input().split()))\nmod = 1000000007\n\nif abs(N - M) > 1:\n    print((0))\nelif (N + M) % 2 == 1:\n    x = max(N, M)\n    y = min(N, M)\n    Sum = 1\n    for i in range(N + M):\n        if i % 2 == 0:\n            Sum *= x - (i // 2)\n            Sum %= mod\n        else:\n            Sum *= y - (i // 2)\n            Sum %= mod\n    print(Sum)\nelse:\n    Sum = 1\n    for i in range(2 * N):\n        Sum *= N - (i // 2)\n        Sum %= mod\n    Sum *= 2\n    Sum %= mod\n    print(Sum)\n", "passed": true, "time": 0.17, "memory": 14296.0, "status": "done"}, {"code": "import math\nn,m=map(int,input().split());r=10**9+7\nif n==m: print(2*math.factorial(n)*math.factorial(m)%r)\nelif abs(n-m)==1: print(math.factorial(n)*math.factorial(m)%r)\nelse: print(0)", "passed": true, "time": 0.6, "memory": 14624.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\n\nmod = 10**9 + 7\nl = n+m\nans = 1\nb = max(n, m)\ns = min(n, m)\nfor i in range(l):\n    if i % 2 == 0:\n        tmp = b-i//2\n        if tmp > 0:\n            ans = (ans % mod) * (tmp % mod)\n        else:\n            print((0))\n            return\n    else:\n        tmp = s-i//2\n        if tmp > 0:\n            ans = (ans % mod) * (tmp % mod)\n        else:\n            print((0))\n            return\nif l%2 == 0:    \n    ans = (ans % mod) * (2 % mod)\nprint((ans%mod))\n", "passed": true, "time": 0.41, "memory": 14184.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\n\ndef f(n):\n    ans = n\n    for i in range(1, n):\n        ans *= i\n        ans %= 1000000007\n    return ans\n\nif n == m:\n    print(((f(n))**2 *2)%1000000007)\nelif n == m+1 or m == n+1:\n    print((f(n)*f(m))%1000000007)\nelse:\n    print(0)", "passed": true, "time": 0.15, "memory": 14228.0, "status": "done"}, {"code": "from math import factorial\n\nn, m = map(int, input().split())\nif n == m:\n    print((factorial(n) ** 2 * 2) % (10 ** 9 + 7))\nelif abs(n - m) == 1:\n    print((factorial(n) * factorial(m)) % (10 ** 9 + 7))\nelse:\n    print(0)", "passed": true, "time": 0.71, "memory": 14300.0, "status": "done"}, {"code": "n,m = map(int, input().split(\" \"))\nif abs(n-m) >= 2:\n  print(0)\nelse:\n  temp = 1\n  mod = 10 ** 9 + 7\n  for i in range(1, min(n,m)+1):\n    temp *= i\n    temp %= mod\n  #print(temp)\n  if n != m:\n    print((temp**2*(max(n,m)) % mod))\n  else:\n    print((temp**2*2 % mod))", "passed": true, "time": 0.22, "memory": 14296.0, "status": "done"}, {"code": "import math\nn, m = map(int, input().split())\nmod = 10 ** 9 + 7\n\nif n == m:\n  res = 2 * math.factorial(n) * math.factorial(m)\n  print(res % mod)\nelif abs(n - m) == 1:\n  res = math.factorial(n) * math.factorial(m)\n  print(res % mod)  \nelse:\n  print(0)", "passed": true, "time": 1.03, "memory": 14288.0, "status": "done"}, {"code": "n,m = list(map(int,input().split()))\n\np = 10**9+7\ndef ka(t):\n    an = 1\n    for i in range(2,t+1):\n        an = (an*i)%p\n    return an\n\nif n==m+1 or n==m-1:\n    print(((ka(n)*ka(m))%p))\nelif n==m:\n    print(((ka(n)*ka(m)*2)%p))\nelse:\n    print((0))\n", "passed": true, "time": 0.38, "memory": 14160.0, "status": "done"}, {"code": "n, m = [int(x) for x in input().split()]\nmod = 10 ** 9 + 7\n\ndef kaizyou(p):\n  ans = 1\n  for i in range(1,p+1):\n    ans *= i\n    if ans >= mod:\n      ans %= mod\n  return ans\n  \nres = 0\nif abs(m - n) <= 1:\n  res += kaizyou(m)\n  res %= mod\n  res *= kaizyou(n)\n  res %= mod\n  if n == m:\n    res *= 2\n  res %= mod\n\nprint(res)", "passed": true, "time": 0.26, "memory": 14112.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Sep 27 02:58:21 2020\n\n@author: liang\n\"\"\"\n\nN, M = list(map(int,input().split()))\nMOD = 10**9 + 7\n\nif abs(N-M) >= 2:\n    ans = 0\nelse:\n    ans = 1\n    for i in range(1,N+1):\n        ans *= i\n        ans %= MOD\n\n    for i in range(1,M+1):\n        ans *= i\n        ans %= MOD\n    \n    if N == M:\n        ans *= 2\n        ans %= MOD\nprint(ans)\n", "passed": true, "time": 0.27, "memory": 14128.0, "status": "done"}, {"code": "#/usr/bin/env python\n\nn, m = list(map(int, input().split()))\nMOD = int(1e9)+7\nfac = [-1 for _ in range(100001)]\nfac[1] = 1 \n\nfor i in range(1, 100000):\n    fac[i+1] = ((i+1)*fac[i])%MOD\n\nif abs(n-m) > 1:\n    print((0))\n    return\n\nans = 0 \nif n == m:\n    ans = (fac[n]*fac[m]*2)%MOD\nelse:\n    ans = (fac[n]*fac[m])%MOD\n\nprint(ans)\n", "passed": true, "time": 0.5, "memory": 17008.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\n#l = list(map(int, input().split()))\n#import numpy as np\n#arr = np.array([int(i) for i in input().split()])\n'''\na,b=[],[]\nfor i in range():\n    A, B = map(int, input().split())\n    a.append(A)   \n    b.append(B)'''\n\nn,m=map(int,input().split())\nif abs(n-m)>1:\n    print(0)\n    return\n\nf=[1]\nfor i in range(1,max(n,m)+1):\n    x=f[i-1]*i\n    if x>10**9+7:\n        x%=10**9+7\n    f.append(x)\nif n!=m:\n    print(f[n]*f[m]%(10**9+7))\nelse:\n    print(f[n]*f[m]*2%(10**9+7))", "passed": true, "time": 0.38, "memory": 17380.0, "status": "done"}, {"code": "N, M = [int(x) for x in input().split()]\nMOD = 10**9+7\n\nif max(N, M) - min(N, M) > 1:\n    print((0))\n    return\n\n\ndef floor(n):\n    result = n\n    for i in range(n-1, 0, -1):\n        result *= i\n        result %= MOD\n\n    return result\n\n\nr = floor(max(N, M))\nt = floor(min(N, M))\n\nif r == t:\n    result = (r * t * 2) % MOD\nelse:\n    result = (r * t) % MOD\n\nprint(result)\n", "passed": true, "time": 0.18, "memory": 14236.0, "status": "done"}, {"code": "import math\nn,m = map(int,input().split())\nmod = 10**9+7\nfact_n = math.factorial(n) % mod\nfact_m = math.factorial(m) % mod\n\nif abs(n-m) >= 2:\n  print(0)\nelif n == m:\n  print((fact_n * fact_m * 2) % mod)\nelse:\n  print((fact_n * fact_m) % mod)", "passed": true, "time": 0.52, "memory": 14256.0, "status": "done"}, {"code": "import math\ndef ModFact(N,Mod):\n    Num = 1\n    for T in range(2,N+1):\n        Num = (Num*T)%Mod\n    return Num\n  \nN,M = (int(T) for T in input().split())\nMod = 10**9+7\nif N==M:\n    print((2*ModFact(N,Mod)*ModFact(M,Mod))%Mod)\nelif N==M+1 or M==N+1:\n    print((ModFact(N,Mod)*ModFact(M,Mod))%Mod)\nelse:\n    print(0)", "passed": true, "time": 0.16, "memory": 14088.0, "status": "done"}, {"code": "from math import factorial as fac\n\nN,M = map(int,input().split())\n\nif abs(N-M) > 1:\n  print(0)\nelif abs(N-M) == 1:\n  print((fac(N)*fac(M))%1000000007)\nelse:\n  print((2*fac(N)*fac(M))%1000000007)", "passed": true, "time": 1.05, "memory": 14624.0, "status": "done"}, {"code": "n, m  =list(map(int, input().split()))\n\nmod = 10**9+7\nans = 1\n\n\nif abs(n-m) >= 2:\n    ans = 0\nelif abs(n-m) == 1:\n    for i in range(1, max(n, m)+1):\n        ans *= i\n        ans %= mod\n    for j in range(1, min(n, m)+1):\n        ans *= j\n        ans %= mod\nelif abs(n-m) == 0:\n    for i in range(1, n+1):\n        ans *= i\n        ans %= mod\n    ans **= 2\n    ans*= 2\n    ans %= mod\n\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14116.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\nif abs(n-m)>1:\n  print((0))\n  return\n\nsm=1 if n!=m else 2\nwhile n>0:\n  sm=(sm*n)%(10**9+7)\n  n-=1\nwhile m>0:\n  sm=(sm*m)%(10**9+7)\n  m-=1\nprint(sm)\n", "passed": true, "time": 0.16, "memory": 14308.0, "status": "done"}, {"code": "from math import factorial\nN,M=map(int,input().split())\nans=0\nif abs(N-M)>1:\n    ans=0\nelse:\n    if N==M:\n        a=N\n        b=M\n        ans=factorial(a)*factorial(b)*2\n    else:\n        a=max(N,M)\n        b=min(N,M)\n        ans=factorial(a)*factorial(b)\nprint(ans%(10**9+7))", "passed": true, "time": 0.6, "memory": 14648.0, "status": "done"}, {"code": "def prepare(n, MOD):\n \n    # 1! - n! \u306e\u8a08\u7b97\n    f = 1\n    factorials = [1]  # 0!\u306e\u5206\n    for m in range(1, n + 1):\n        f *= m\n        f %= MOD\n        factorials.append(f)\n    # n!^-1 \u306e\u8a08\u7b97\n    inv = pow(f, MOD - 2, MOD)\n    # n!^-1 - 1!^-1 \u306e\u8a08\u7b97\n    invs = [1] * (n + 1)\n    invs[n] = inv\n    for m in range(n, 1, -1):\n        inv *= m\n        inv %= MOD\n        invs[m - 1] = inv\n     \n    return factorials, invs\n\nMOD = 10**9+7\nfact, fact_inv = prepare(2*10**5, MOD)\n\nn, m = map(int,input().split())\nif abs(n-m) > 1:\n    print(0)\nelif abs(n-m) == 1:\n    print(fact[n] * fact[m] % MOD)\nelse:\n    print(2 * fact[n] % MOD * fact[m] % MOD)", "passed": true, "time": 0.4, "memory": 28692.0, "status": "done"}, {"code": "import math\n\nn, m = map(int, input().split())\n\nif abs(n - m) >= 2:\n    print(0)\n\nelif abs(n - m) == 1:\n    ans = math.factorial(n) * math.factorial(m)\n    ans %= 10 ** 9 + 7\n    print(ans)\n\nelse:\n    ans = 2*math.factorial(n) * math.factorial(m)\n    ans %= 10 ** 9 + 7\n    print(ans)", "passed": true, "time": 0.59, "memory": 14928.0, "status": "done"}, {"code": "import math\nn,m = map(int,input().split())\nmod = 10**9+7\nfact_n = math.factorial(n) % mod\nfact_m = math.factorial(m) % mod\n\nif abs(n-m) >= 2:\n  print(0)\n  return\nelif n == m:\n  print((fact_n * fact_m * 2) % mod)\nelse:\n  print((fact_n * fact_m) % mod)", "passed": true, "time": 0.43, "memory": 14088.0, "status": "done"}, {"code": "MOD = 1_000_000_007\nn, m = map(int,input().split())\nif abs(n-m)>1:\n    print(0)\nelse:\n    if abs(n-m)==1:\n        ans = 1\n    else:\n        ans = 2\n    for i in range(n):\n        ans = (ans*(i+1))%MOD\n    for i in range(m):\n        ans = (ans*(i+1))%MOD\n    print(ans)", "passed": true, "time": 0.16, "memory": 14328.0, "status": "done"}, {"code": "import sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = 10**20\nMOD = 10 ** 9 + 7\ndef I(): return int(input())\ndef F(): return float(input())\ndef S(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LS(): return input().split()\n\ndef fact_mod(n, MOD):\n    ret = 1\n    for i in range(1, n + 1):\n        ret *= i\n        ret %= MOD\n    return ret\n\ndef resolve():\n    N, M = LI()\n\n    if N == M:\n        ans = 2 * pow(fact_mod(N, MOD), 2, MOD)\n        ans %= MOD\n        print(ans)\n    elif abs(N - M) <= 1:\n        ans = fact_mod(N, MOD) * fact_mod(M, MOD)\n        ans %= MOD\n        print(ans)\n    else:\n        print((0))\n\n\ndef __starting_point():\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14424.0, "status": "done"}, {"code": "import math\nn,m=map(int,input().split())\nN=math.factorial(n)\nif abs(n-m)>1:\n    print(0)\nelif abs(n-m)==0:\n    print(2*N*N%(10**9+7))\nelif n>m:\n    print((N*N//n)%(10**9+7))\nelse:\n    print(N*N*m%(10**9+7))", "passed": true, "time": 0.46, "memory": 14464.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\nif abs(n-m) >= 2:\n    print(0)\n    return\n\nans = 1\ndiv = 10**9+7\n\nfor i in range(1, n+1):\n    ans = (ans * i) % div\nfor i in range(1, m+1):\n    ans = (ans * i) % div\n\nif n != m:\n    print(ans)\nelse:\n    print((ans*2)%div)", "passed": true, "time": 0.16, "memory": 14260.0, "status": "done"}, {"code": "N,M=map(int,input().split())\nmod = 10**9+7\n\nfactorial=[1 for i in range(10**5+5)]\nfor i in range(1,10**5+5):\n    if i==1:factorial[i]=1\n    else:factorial[i] = factorial[i-1]*i % mod\n      \nif abs(N-M)>1:\n  print(0)\n  return\n\nif N==M:\n  print(factorial[M]**2*2%mod)\nelse:\n  print(factorial[M]*factorial[N]%mod)", "passed": true, "time": 0.22, "memory": 17040.0, "status": "done"}, {"code": "mod = 10**9+7\nn, m = map(int, input().split())\nif abs(n-m) >= 2:\n    print(0)\n    return\nx, y = 1, 1\nfor i in range(1, n+1):\n    x *= i\n    x %= mod\nfor i in range(1, m+1):\n    y *= i\n    y %= mod\nif n == m:\n    print((2*x*y)%mod)\nelse:\n    print((x*y)%mod)", "passed": true, "time": 0.17, "memory": 14212.0, "status": "done"}, {"code": "import math\nn, m = map(int, input().split())\nans = 0\nif n == m:\n  ans = (math.factorial(n) * math.factorial(m)) * 2\nelif  n + 1 == m or n == m + 1:\n  ans = (math.factorial(n) * math.factorial(m))\nelse:\n  ans = 0\nans = ans % (10 ** 9 + 7)\nprint(ans)", "passed": true, "time": 0.62, "memory": 14464.0, "status": "done"}, {"code": "import sys\nimport math\n\nmod = 10**9 + 7\nN, M = map(int, sys.stdin.readline().split())\ndiff = abs(N - M)\nif diff > 1:\n    print(0)\n    return\n\nn_p = 1\nfor i in range(1, N+1):\n    n_p *= i\n    n_p %= mod\nm_p = 1\nfor i in range(1, M+1):\n    m_p *= i\n    m_p %= mod\n\nif diff == 0:\n    print(2 * n_p * m_p % mod)\nelse:\n    print(n_p * m_p % mod)", "passed": true, "time": 0.16, "memory": 14328.0, "status": "done"}, {"code": "def main():\n    N,M = list(map(int,input().split()))\n    if abs(N-M) > 1:\n        return 0\n    N_mlt = 1\n    M_mlt = 1\n    for i in range(1,N+1,1):\n        N_mlt *= i\n        N_mlt = N_mlt%1000000007\n        #print(i,N_mlt)\n    for i in range(1,M+1,1):\n        M_mlt *= i\n        M_mlt = M_mlt%1000000007\n        #print(i,M_mlt)\n    #print(N_mlt,M_mlt)\n    ans = (N_mlt*M_mlt)%1000000007\n    if abs(N-M)==0:\n        ans = (ans*2)%1000000007\n        return  ans\n    else:\n        return ans\n\nprint((main()))\n", "passed": true, "time": 0.38, "memory": 14228.0, "status": "done"}, {"code": "import math\na,b=map(int, input().split())\n\nif abs(a-b) == 1:\n    c = math.factorial(a)%(10**9+7)\n    d = math.factorial(b)%(10**9+7)\n    print(c*d%(10**9+7))\nif abs(a-b) == 0:\n    c = math.factorial(a)%(10**9+7)\n    d = math.factorial(b)%(10**9+7)\n    print(c*d*2%(10**9+7))\nif abs(a-b) >= 2:\n    print(0)", "passed": true, "time": 0.44, "memory": 14252.0, "status": "done"}, {"code": "import math\nN,M = map(int,input().split())\nif abs(N-M) > 1:\n    print(0)\n    return\n\nfac = 1\nnum = 10**9 + 7\nfor i in range(1,N+1):\n    fac *= i\n    if fac > num:\n        fac %= num\n\nfac2 = 1\nfor i in range(1,M+1):\n    fac2 *= i\n    if fac2 > num:\n        fac2 %= num\n\nif N == M:\n    print(fac**2*2%num)\nelse:\n    print(fac*fac2%num)", "passed": true, "time": 0.18, "memory": 14104.0, "status": "done"}, {"code": "import math\nmod = 10**9+7\nans = 1\nn, m = map(int, input().split())\nif abs(n - m) > 1:\n  print(0)\n  return\nelif n == m:\n  ans = 2\nans = ans * math.factorial(n) % mod\nans = ans * math.factorial(m) % mod\nprint(ans)", "passed": true, "time": 0.44, "memory": 14280.0, "status": "done"}, {"code": "import math\nn,m = map(int,input().split())\n\nx = 10**9+7\n\nans = 0\nif n == m:\n    ans += math.factorial(n) * math.factorial(m) * 2\n    print(ans % x)\n    return\nelif n >= m and n -m == 1:\n    ans += math.factorial(n) * math.factorial(m)\n    print(ans % x)\n    return\nelif m >= n and m -n== 1:\n    ans += math.factorial(n) * math.factorial(m)\n    print(ans % x)\n    return\nelse:\n    print(ans % x)", "passed": true, "time": 0.63, "memory": 14568.0, "status": "done"}, {"code": "import math as m\nN,M=map(int,input().split())\nw=1000000007\nif abs(N-M)<2:\n    if N==M:\n        print((m.factorial(N)**2*2)%w)\n    else:\n        print((m.factorial(N)*m.factorial(M))%w)\nelse:\n    print(0)", "passed": true, "time": 0.41, "memory": 14272.0, "status": "done"}, {"code": "N, M = list(map(int, input().split()))\nmod = 10**9 + 7\n\ndef factorial(n):\n    ans = 1\n    i = 0\n    while i < n:\n        ans *= (n-i)\n        ans %= mod\n        i += 1\n    return ans\n\nif abs(N-M) >= 2:\n    print((0))\nelif N == M:\n    ans = (factorial(N) * factorial(M) * 2) % mod\n    print(ans)\nelse:\n    ans = (factorial(N) * factorial(M)) % mod\n    print(ans)\n", "passed": true, "time": 0.18, "memory": 14124.0, "status": "done"}, {"code": "N,M=map(int,input().split())\nabs_NM=abs(N-M)\nif abs_NM>1:\n    print(0)\n    return\n\np=10**9+7\nans=1\nfor i in range(1,N+1):\n    ans=(ans*i)%p\nfor i in range(1,M+1):\n    ans=(ans*i)%p\nif abs_NM==0:\n    ans=(ans*2)%p\n\nprint(ans)", "passed": true, "time": 0.16, "memory": 14268.0, "status": "done"}, {"code": "MOD =  pow(10,9)+7\ndef MODINV(n:int, MOD=MOD):\n    return pow(n, MOD-2, MOD)\n\ndef perm(n, k, MOD):\n    numer = 1\n    for i in range(n, n-k, -1):\n        numer *= i\n        numer %= MOD\n    return numer\n\ndef main():\n    N, M = list(map(int, input().split()))\n    if N == M+1 or N+1 == M:\n        ans = (perm(N, N, MOD)*perm(M, M, MOD))%MOD\n    elif N == M:\n        ans = (2*(perm(N, N, MOD)*perm(M, M, MOD)))%MOD\n    else:\n        ans = 0\n    print(ans)\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.17, "memory": 14284.0, "status": "done"}, {"code": "import math\nn, m = list(map(int, input().split()))\nif abs(n - m) >= 2:\n    print((0))\nelif n == m:\n    print(((2 * math.factorial(n) * math.factorial(m)) % (10**9 + 7)))\nelse:\n    print((math.factorial(n) * math.factorial(m) % (10**9 + 7)))\n", "passed": true, "time": 0.6, "memory": 14880.0, "status": "done"}, {"code": "from math import factorial\n\nmod = 10 ** 9 + 7\nn, m = map(int, input().split())\nprint(\n    ((factorial(n) % mod) ** 2 % mod) * 2 % mod\n    if n == m\n    else (factorial(n) % mod) * (factorial(m) % mod) % mod\n    if abs(n - m) == 1\n    else 0\n)", "passed": true, "time": 0.28, "memory": 14364.0, "status": "done"}, {"code": "from math import factorial as f\nn, m = list(map(int, input().split()))\nmod = 10 ** 9 + 7\nif abs(n - m) == 1:\n    res = f(n) * f(m)\n    print((res % mod))\nelif n == m:\n    res = f(n) * f(m) * 2\n    print((res % mod))\nelse:\n    print((0))\n", "passed": true, "time": 0.6, "memory": 14556.0, "status": "done"}, {"code": "def factorial(a):\n    result = 1\n    for i in range(1,a+1):\n        result *= i\n        result %= 1000000007\n    return result\nN, M = map(int, input().split())\nif N == M:\n    ans = 2*(factorial(N)**2) %1000000007\nelif abs(N-M) == 1:\n    ans = max(N,M)*(factorial(min(N,M))**2) %1000000007\nelse:\n    ans =0\nprint(ans)", "passed": true, "time": 0.15, "memory": 14140.0, "status": "done"}, {"code": "import math\n\nN, M = map(int, input().split())\n\ndef mod(num):\n    return num % (10 ** 9 + 7)\n\ndef calc():\n    dp[1] = 1\n    for i in range(2, maxmn + 1):\n        dp[i] = mod(dp[i-1] * i)\n\nabsnm = abs(N - M)\n\nmaxmn = max(N, M)\ndp = [0]*(maxmn + 1)\n\nif absnm > 1:\n    print(0)\n\nelse:\n    calc()\n\n    if absnm == 1:\n        r = mod(dp[M] * dp[N])\n\n    elif absnm == 0:\n        r = mod(dp[M] * dp[N] * 2)\n\n    else:\n        r = 0\n\n    print(r)", "passed": true, "time": 0.16, "memory": 17276.0, "status": "done"}, {"code": "N,M =map(int,input().split())\na = abs(N-M)\nmod = 10**9 + 7\nn = 1\nfor i in range(N):\n    n *= N-i\n    n %= mod\nm = 1\nfor i in range(M):\n    m *= M-i\n    m %= mod\nif a > 1:\n    print(0)\nelif a == 1:\n    print(n * m % mod)\nelse:\n    print(n*m*2%mod)", "passed": true, "time": 0.17, "memory": 14156.0, "status": "done"}, {"code": "import math\n\n\ndef main():\n    N, M = list(map(int, input().split()))\n    mod = 10 ** 9 + 7\n    if abs(N - M) > 1:\n        ans = 0\n    elif N - M == 1:\n        ans = (math.factorial(M)**2 * N) % mod\n    elif N - M == -1:\n        ans = (math.factorial(N)**2 * M) % mod\n    else:\n        ans = (math.factorial(N)**2 * 2) % mod\n\n    print(ans)\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.42, "memory": 14220.0, "status": "done"}, {"code": "N, M = list(map(int, input().split()))\nfrom math import factorial\nmod = 10**9+7\n\nif abs(N-M) > 1:\n    print((0))\nelif abs(N-M) == 1:\n    print((factorial(N)*factorial(M)%mod))\nelse:\n    print((2*factorial(N)*factorial(M)%mod))\n\n\n", "passed": true, "time": 0.64, "memory": 14424.0, "status": "done"}, {"code": "import math\nn,m = list(map(int,input().split()))\nif abs(n-m)>1:\n    print((0))\nelif abs(n-m)==1:\n    print(((math.factorial(n) * math.factorial(m))%(10**9+7)))\nelse:\n    print(((2 * math.factorial(n) * math.factorial(m))%(10**9+7)))\n", "passed": true, "time": 0.6, "memory": 14804.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nmod = 10 ** 9 + 7\n\n\ndef permitation(x):\n    res = 1\n    for i in range(1, x + 1):\n        res = res * i % mod\n    return res\n\n\npn = permitation(n)\npm = permitation(m)\n\nif n == m:\n    res = pn * pm * 2 % mod\n    print(res)\nelif n == m - 1 or n == m + 1:\n    res = pn * pm % mod\n    print(res)\nelse:\n    print((0))\n", "passed": true, "time": 0.16, "memory": 14212.0, "status": "done"}, {"code": "N,M = map(int,input().rstrip().split(\" \"))\nif abs(N - M) > 1:\n    print(0)\nelse:\n    ans = 1\n    for i in range(1,N + 1):\n        ans *= i\n        ans %= 10 ** 9 + 7\n    for i in range(1,M + 1):\n        ans *= i\n        ans %= 10 ** 9 + 7\n    if N == M:\n        ans *= 2\n        ans %= 10 ** 9 + 7\n    print(ans)", "passed": true, "time": 0.24, "memory": 14132.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nn, m = max(n, m), min(n, m)\ndiv = 10 ** 9 + 7\nres = 1\nif n - m == 0:\n  for i in range(1, n + 1):\n    res *= i\n    res %= div\n  res = res * res * 2\n  print(res % div)\nelif n - m == 1:\n  for i in range(1, n + 1):\n    res *= i\n    res %= div\n  for i in range(1, m + 1):\n    res *= i\n    res %= div\n  print(res)\nelse:\n  print(0)", "passed": true, "time": 0.15, "memory": 14104.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\nif n < m: # n >= m\n    n, m = m, n\n\nif m + 1 == n or m == n:\n    # m! * 1 or 2 * n!\n    if m + 1 == n:\n        ans = 1\n    else:\n        ans = 2\n    k = 1\n    for i in range(1, n + 1):\n        k *= i\n        if i == m:\n            ans *= k\n        k = k % (10**9 + 7)\n    ans *= k\n    print(ans % (10**9 + 7))\nelse:\n    print(0)", "passed": true, "time": 0.15, "memory": 14220.0, "status": "done"}, {"code": "import math\nn,m = map(int, input().split())\na = math.factorial(m)\nb = math.factorial(n)\nif 1 < abs(n-m):\n    print(0)\nelif abs(n-m) == 0:\n    print((a*b*2)%1000000007)\nelif abs(m-n) == 1:\n    print((a*b)%1000000007)", "passed": true, "time": 0.6, "memory": 14644.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nif abs(n - m) > 1:\n    print((0))\n    return\nans = 1\nfor i in range(1, n + 1):\n    ans *= i\n    ans %= 10**9 + 7\nfor i in range(1, m + 1):\n    ans *= i\n    ans %= 10**9 + 7\nif abs(n - m) == 0:\n    ans *= 2\n    ans %= 10**9 + 7\nprint(ans)\n", "passed": true, "time": 0.17, "memory": 14308.0, "status": "done"}, {"code": "MOD=1000000007\n\ndef fac(x):\n    ret=1\n    for i in range(1,x+1):\n        ret*=i\n        ret%=MOD\n    return ret\n\nN,M=list(map(int,input().split()))\n\nif N==M:\n    print((fac(N)**2*2%MOD))\nelif abs(N-M)==1:\n    print((fac(N)*fac(M)%MOD))\nelse:\n    print((0))\n", "passed": true, "time": 0.16, "memory": 14252.0, "status": "done"}, {"code": "#79 C - Reconciled?\nN,M = map(int,input().split())\nMOD = 10**9 + 7\n\nif abs(N-M) >= 2:\n    ans = 0\nelse:\n    # M! * N!\n    Mfact = 1\n    for m in range(1,M+1):\n        Mfact = (Mfact * m)%MOD\n    Nfact = 1\n    for n in range(1,N+1):\n        Nfact = (Nfact * n)%MOD\n    ans = (Nfact*Mfact)%MOD\n    if abs(N-M) == 0:\n        ans = (ans * 2)%MOD\nprint(ans)", "passed": true, "time": 0.16, "memory": 14356.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\n# from numba import njit\n\n# input = stdin.readline\n\nMOD = 10**9 + 7\n\ndef modFact(x):\n  if x < 1:\n    raise ValueError\n  res = 1\n  for i in range(x):\n    res = res * (i+1) % MOD\n  return res\n\n# @njit\ndef solve(n,m):\n  if abs(n-m) > 1:\n    return 0\n  elif abs(n-m) == 1:\n    return modFact(n) * modFact(m) % MOD\n  else:\n    return modFact(n) * modFact(m) * 2 % MOD\n\n\ndef main():\n  N,M = list(map(int,input().split()))\n  # a = list(map(int,input().split()))\n  print((solve(N,M)))\n  return\n\ndef __starting_point():\n  main()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14276.0, "status": "done"}, {"code": "import math\nN, M = map(int, input().split())\n\nmod = 10 ** 9 + 7\n\nif abs(N - M) > 1:\n  ans = 0\nelif abs(N - M) == 1:\n  ans = (math.factorial(N) % mod) * (math.factorial(M) % mod)\nelse:\n  ans = (math.factorial(N) % mod) * (math.factorial(M) % mod) * 2\n  \nprint(ans % mod)", "passed": true, "time": 0.61, "memory": 14124.0, "status": "done"}, {"code": "def solve():\n  N, M = map(int, input().split())\n  if abs(N-M)>1:\n    return 0\n  mod = 10**9+7\n  ans = 2-abs(N-M)\n  for i in range(N):\n    ans *= i+1\n    ans %= mod\n  for i in range(M):\n    ans *= i+1\n    ans %= mod\n  return ans\nprint(solve())", "passed": true, "time": 0.17, "memory": 14268.0, "status": "done"}, {"code": "n,m = list(map(int, input().split()))\nif n > m:\n    n,m = m,n\nans = 1\nif m==n:\n\n    while n > 0:\n        ans *= n\n        ans %= 10**9+7\n        n -= 1\n    ans = (2*(ans**2))%(10**9+7)\n    print(ans)\n\nelif m - n == 1:\n    while n > 0:\n        ans *= n\n        ans %= 10**9+7\n        n -= 1\n    \n    \n    ans = (ans * (ans*m % (10**9+7))) % (10**9+7)\n    print(ans)\nelse:\n    print((0))\n", "passed": true, "time": 0.16, "memory": 14280.0, "status": "done"}, {"code": "import math\nN,M=map(int,input().split())\np=10**9 +7\ndog=math.factorial(N)\nmon=math.factorial(M)\n\nif N==M:\n  ans = ((dog*mon)*2) % p\nelif abs(N-M) == 1:\n  ans = (dog*mon) % p\nelse:\n  ans=0\nprint(ans)", "passed": true, "time": 0.61, "memory": 14896.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nmod = 10**9+7\n\"\"\"\nabs(n-m)>1\u306e\u6642\u3001\u5fc5\u305a\u96a3\u308a\u5408\u3063\u3066\u3057\u307e\u3046\u306e\u30670\nn>m\u3068\u3057\u3066\u3082\u4e00\u822c\u6027\u3092\u5931\u308f\u306a\u3044\nif n<m: n, m = m, n\nn==mn\u306e\u6642\u306f\u3001\u3069\u3061\u3089\u3092\u5de6\u7aef\u306b\u7f6e\u304f\u304b\u9078\u3079\u308b\u306e\u30672\u500d\n\"\"\"\n\nif abs(n-m)>1: print(0)\nelse:\n    if n<m: n, m = m, n\n    n_parm = 1\n    for i in range(n, 0, -1):\n        n_parm = (n_parm*i)%mod\n    m_parm = 1\n    for i in range(m, 0, -1):\n        m_parm = (m_parm*i)%mod\n    ans = (n_parm * m_parm)%mod\n    if m==n:\n        ans = (ans*2)%mod\n    print(ans)", "passed": true, "time": 0.16, "memory": 14104.0, "status": "done"}, {"code": "N,M=map(int,input().split())\nt=10**9+7\nimport math\nn=math.factorial(N)%t\nm=math.factorial(M)%t\n\nif 2<=abs(N-M):\n    print(0)\nelif abs(N-M)==1:\n    print((n*m)%t)\nelse:\n    print((n*m*2)%t)", "passed": true, "time": 0.43, "memory": 14196.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\n\nimport math\nif n == m:\n    dog = math.factorial(n)\n    mon = math.factorial(m)\n    ans = dog * mon * 2\nelif n == m + 1 or n == m - 1:\n    dog = math.factorial(n)\n    mon = math.factorial(m)\n    ans = dog * mon\nelse:\n    ans = 0\n\nprint((ans % (10 ** 9 + 7)))\n", "passed": true, "time": 0.6, "memory": 14328.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nmod = 10**9+7\n\ndef fact(n, mod):\n    ans = 1\n    for i in range(2, n + 1):\n        ans = ans * i\n        ans = ans % mod\n\n    return ans\n\n\nif abs(n - m) >= 2:\n    print((0))\nelif abs(n - m) == 1:\n    print((fact(n,mod)*fact(m,mod) % mod))\nelif abs(n - m) == 0:\n    print((2 * fact(n, mod)*fact(m, mod) % mod))\n", "passed": true, "time": 0.17, "memory": 14360.0, "status": "done"}, {"code": "n,m = list(map(int,input().split()))\n\nans = 0\nrd = 10**9 + 7\nif(abs(n-m) > 1):\n    ans = 0\n    print(ans)\nelif(abs(n-m) == 1):\n    tmp = min(n,m)\n    tmp_mx = max(n,m)\n    sm = 1\n    for i in range(tmp):\n        sm = (sm * (i+1))%rd\n    \n    ans = (sm * sm * tmp_mx)%rd\n    print(ans)\nelse:\n    sm = 1\n    for i in range(n):\n        sm = (sm * (i+1))%rd\n    \n    ans = (2*sm * sm)%rd\n    print(ans)\n\n", "passed": true, "time": 0.15, "memory": 14196.0, "status": "done"}, {"code": "N,M=list(map(int,input().split()))\nif N==M+1:\n    A=N\n    B=M\n    ans=1\nelif N+1==M:\n    A=M\n    B=N\n    ans=1\nelif N==M:\n    A=N\n    B=M\n    ans=2\nelse:\n    print((0))\n    return\nansa=1\nansb=1\nfor i in range(1,A+1):\n    ansa=(ansa*i)%(10**9+7)\nfor j in range(1,B+1):\n    ansb=(ansb*j)%(10**9+7)\n\nprint(((ansa*ansb*ans)%(10**9+7)))\n\n    \n", "passed": true, "time": 0.16, "memory": 14300.0, "status": "done"}, {"code": "def factorial(n, mod=10**9 + 7):\n    a = 1\n    for i in range(1, n + 1):\n        a = a * i % mod\n    return a\n\n\ndef main():\n    N, M = list(map(int, input().split()))\n    mod = 10 ** 9 + 7\n    if abs(N - M) > 1:\n        ans = 0\n    elif abs(N - M) == 1:\n        ans = (factorial(min(N, M))**2 * max(N, M)) % mod\n    else:\n        ans = (factorial(N)**2 * 2) % mod\n\n    print(ans)\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14208.0, "status": "done"}, {"code": "n,m = map(int, input().split())\n\nif abs(n-m) > 1:\n  print(0)\n  return\n\nmod = 10**9+7\nans = 1\nfor i in range(1,n+1):\n  ans *= i\n  ans %= mod\nfor i in range(1,m+1):\n  ans *= i\n  ans %= mod\nif (n+m)%2 == 0:\n  ans *= 2\n  ans %= mod\nprint(ans)", "passed": true, "time": 0.17, "memory": 14288.0, "status": "done"}, {"code": "import sys\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\nMOD = 10 ** 9 + 7\n\n\ndef fac(k):\n    res = 1\n    for i in range(2, k + 1):\n        res = (res * i) % MOD\n    return res\n\n\ndef solve():\n    n, m = inl()\n    if n < m:\n        n, m = m, n\n    if n - m > 1:\n        return 0\n    if n - m == 1:\n        return fac(n) * fac(m) % MOD\n    assert n == m\n    a = fac(n)\n    a = 2 * a * a % MOD\n    return a\n\n\nprint(solve())\n", "passed": true, "time": 0.15, "memory": 14156.0, "status": "done"}, {"code": "mod = 10 ** 9 + 7\n\ndef factorial(n, mod):\n    fact = 1\n    for integer in range(1, n + 1):\n        fact *= integer\n        fact %= mod\n    return fact\n\nN, M = map(int,input().split())\nif abs(N - M) > 1:\n    print(0)\nelse:\n    ans = 1\n    ans *= factorial(N, mod)\n    ans *= factorial(M, mod)\n    ans *= 2 - abs(N - M)\n    ans %= mod\n    print(ans)", "passed": true, "time": 0.16, "memory": 14240.0, "status": "done"}, {"code": "N,M=map(int,input().split())\nabs_NM=abs(N-M)\nif abs_NM>1:\n    print(0)\n    return\n\np=10**9+7\nmin_=min(N,M)\nmax_=max(N,M)\nans=1\nfor i in range(1,min_+1):\n    ans=(ans*i)%p\n    ans=(ans*i)%p\n\nif abs_NM==1:\n    ans=(ans*max_)%p\nelse:\n    ans=(ans*2)%p\n\nprint(ans)", "passed": true, "time": 0.16, "memory": 14108.0, "status": "done"}, {"code": "#\n# abc065 c\n#\nimport sys\nfrom io import StringIO\nimport unittest\nimport math\n\n\nclass TestClass(unittest.TestCase):\n    def assertIO(self, input, output):\n        stdout, stdin = sys.stdout, sys.stdin\n        sys.stdout, sys.stdin = StringIO(), StringIO(input)\n        resolve()\n        sys.stdout.seek(0)\n        out = sys.stdout.read()[:-1]\n        sys.stdout, sys.stdin = stdout, stdin\n        self.assertEqual(out, output)\n\n    def test_\u5165\u529b\u4f8b_1(self):\n        input = \"\"\"2 2\"\"\"\n        output = \"\"\"8\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_2(self):\n        input = \"\"\"3 2\"\"\"\n        output = \"\"\"12\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_3(self):\n        input = \"\"\"1 8\"\"\"\n        output = \"\"\"0\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_4(self):\n        input = \"\"\"100000 100000\"\"\"\n        output = \"\"\"530123477\"\"\"\n        self.assertIO(input, output)\n\n\ndef resolve():\n    N, M = list(map(int, input().split()))\n\n    if abs(N-M) > 1:\n        print(\"0\")\n    elif N == M:\n        print((2*math.factorial(N)*math.factorial(M) % (10**9+7)))\n    else:\n        print((math.factorial(N)*math.factorial(M) % (10**9+7)))\n\n\ndef __starting_point():\n    # unittest.main()\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.59, "memory": 14896.0, "status": "done"}, {"code": "import math\nn, m = map(int, input().split())\np = 10**9 + 7\n\n\n\nnf = math.factorial(n) % p\nmf = math.factorial(m) % p\n\nif abs(n-m) > 1:\n  ans = 0\n\nelif n == m:\n  ans = nf * mf * 2\n  \nelse:\n  ans = nf * mf\n  \nprint(ans % p)", "passed": true, "time": 0.42, "memory": 14320.0, "status": "done"}, {"code": "from math import factorial\nn,m=map(int,input().split())\nl=10**9+7\nif abs(n-m)>1:\n  print(0)\n  return\nif abs(n-m)==1:\n  print((factorial(n)*factorial(m))%l)\nelse:\n  print(((factorial(n)**2)*2)%l)", "passed": true, "time": 0.41, "memory": 14420.0, "status": "done"}, {"code": "import sys\n\n\ndef LI():\n    return list(map(int, input().split()))\n\n\nN, M = LI()\nif abs(N-M) >= 2:\n    print((0))\n    return\nmod = pow(10, 9)+7\nx = 1\nif N == M:\n    for i in range(1, N+1):\n        x = (x*i) % mod\n    ans = (x*x*2) % mod\nelse:\n    A = max(N, M)\n    B = min(N, M)\n    for i in range(1, B+1):\n        x = (x*i) % mod\n    y = (x*A) % mod\n    ans = (x*y) % mod\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14136.0, "status": "done"}, {"code": "n,m=[int(i) for i in input().split()]\nnew_n=min(n,m)\nnew_m=max(n,m)\nmod=10**9+7\ndef ans(n,m):\n\n    if n==m:\n        return 2*kaijyou(n,mod)*kaijyou(m,mod)\n    elif m-n==1:\n        return kaijyou(n,mod)*kaijyou(m,mod)\n    else:\n        return 0\n\n\ndef kaijyou(n,mod):\n    ans=1\n    for i in range(1,n+1):\n        ans*=i\n        ans=ans%mod\n    return ans\nprint(ans(new_n,new_m)%mod)", "passed": true, "time": 0.16, "memory": 14300.0, "status": "done"}, {"code": "import math\nmod=10**9+7\nn,m=list(map(int,input().split()))\nif n+1<m or m+1<n:\n    print((0))\n    return\nelif n==m:\n    print(((2*math.factorial(n)**2)%mod))\nelse:\n    print(((math.factorial(n)*math.factorial(m))%mod))\n\n", "passed": true, "time": 0.42, "memory": 14628.0, "status": "done"}, {"code": "from math import factorial\ndef count(n, r):\n    if n == r:\n        return 2\n    else:\n        return 1\n\nN, M = map(int, input().split())\nmod = 10**9 + 7\nprint(((factorial(N) % mod) * (count(N, M) % mod) * (factorial(M) % mod)) % mod if abs(N - M) < 2 else 0)", "passed": true, "time": 0.54, "memory": 14072.0, "status": "done"}, {"code": "n,m = list(map(int, input().split()))\nf = [1] \np = 10**9 + 7\nfor i in range(1, max(n,m) + 1):\n  f.append(f[-1] * i % p)\n\nif abs(n-m) == 1:\n  print((f[n] * f[m] % p))\nelif abs(n-m) == 0:\n  print((f[n] * f[m] * 2 % p))\nelse:\n  print((0))\n", "passed": true, "time": 0.16, "memory": 17160.0, "status": "done"}, {"code": "import math\n\nN, M = list(map(int, input().split()))\nif abs(N - M) >= 2:\n    print((0))\n    return\n\n\nN = math.factorial(N) % (10 ** 9 + 7)\nM = math.factorial(M) % (10 ** 9 + 7)\nif N == M:\n    print(((N * M * 2) % (10 ** 9 + 7)))\nelse:\n    print(((N * M) % (10 ** 9 + 7)))\n", "passed": true, "time": 0.73, "memory": 14048.0, "status": "done"}, {"code": "import math\n\nn, m = map(int, input().split())\nif n==m:\n    print((math.factorial(n)*math.factorial(m)*2)%1000000007)\nelif abs(n-m)==1:\n    print((math.factorial(n)*math.factorial(m))%1000000007)\nelse:\n    print(0)", "passed": true, "time": 0.76, "memory": 14460.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\n\n\ndef facmod(a, mod):\n    res = 1\n    for i in range(1, a+1):\n        res = (res*i) % mod\n    return res\n\n\nmod = 10**9+7\nmn = min(m, n)\nmx = max(m, n)\nif abs(mn-mx) > 1:\n    ans = 0\nelse:\n    if n == m:\n        ans = (2*facmod(m, mod)*facmod(n, mod)) % mod\n    else:\n        ans = (facmod(mx, mod)*facmod(mn, mod)) % mod\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14244.0, "status": "done"}, {"code": "def main():\n  N, M = [int(n) for n in input().split(\" \")]\n\n  if abs(N - M) >= 2:\n    print((0))\n  elif abs(N - M) == 1:\n    print(((factorial(N) * factorial(M)) % 1000000007))\n  else:\n    print(((factorial(N) * factorial(M) * 2) % 1000000007))\n\ndef factorial(n):\n  ret = 1\n  for i in range(1, n + 1):\n    ret = (ret * i) % 1000000007\n  return ret\n    \nmain()\n", "passed": true, "time": 0.33, "memory": 14032.0, "status": "done"}, {"code": "N,M=list(map(int,input().strip().split()))\ninf=10**9+7\nans=1\nfor n in range(1,N+1):\n    ans*=n\n    ans%=inf\nfor m in range(1,M+1):\n    ans*=m\n    ans%=inf\n\nif abs(N-M)>=2:\n    print((0))\nelif abs(N-M)==1:\n    print(ans)\nelse:\n    print((ans*2%inf))\n", "passed": true, "time": 0.27, "memory": 14172.0, "status": "done"}, {"code": "import math\n\nn, m = map(int, input().split())\nn_f = math.factorial(n)\nm_f = math.factorial(m)\nmod = 1000000007\n\nif abs(n-m) > 1:\n    print(0)\n    return\nif n == m:\n    print((n_f * m_f * 2) % mod)\nelse:\n    print((n_f * m_f) % mod)", "passed": true, "time": 0.6, "memory": 14664.0, "status": "done"}, {"code": "def mod1(x):\n  mod=10**9+7\n  ans=1\n  y=1\n  while y<=x:\n    ans=ans*y\n    y+=1\n    ans=ans%mod\n    \n  return ans%mod\n\nn,m=map(int,input().split())\nif n==m:\n  print((2*mod1(n)*mod1(m))%(10**9+7))\nelif abs(n-m)==1:\n  print((mod1(n)*mod1(m))%(10**9+7))\nelse:\n  print(0)", "passed": true, "time": 0.16, "memory": 14228.0, "status": "done"}, {"code": "from math import factorial\nn,m=list(map(int,input().split()))\nif abs(n-m)>1:\n    print((0))\n    return\nmod=10**9+7\nif n==m:\n    print(((2*factorial(n)*factorial(m))%mod))\nelse:\n    print(((factorial(n)*factorial(m))%mod))\n", "passed": true, "time": 0.59, "memory": 14600.0, "status": "done"}, {"code": "from math import factorial\nn,m=map(int,input().split())\nl=10**9+7\nif abs(n-m)>1:\n  print(0)\n  return\nif abs(n-m)==1:\n  print((factorial(n)*factorial(m))%l)\nelse:\n  print(((factorial(n)**2)*2)%l)", "passed": true, "time": 0.41, "memory": 14408.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\np=10**9+7\nif abs(n-m)>=2:\n    print((0))\nelif n==m:\n    ans=1\n    for i in range(1,n+1):\n        ans=(ans*i)%p\n    print(((2*ans*ans)%p))\nelse:\n    ans=1\n    for i in range(1,n+1):\n        ans=(ans*i)%p\n    for i in range(1,m+1):\n        ans=(ans*i)%p\n    print((ans%p))\n", "passed": true, "time": 0.16, "memory": 14292.0, "status": "done"}, {"code": "def factorial(n, mod):\n    num = 1\n    for i in range(1, n + 1):\n        i %= mod\n        num *= i\n        num %= mod\n    return num\n\n\ndef main():\n    n, m = map(int, input().split())\n    md = 10 ** 9 + 7\n\n    if abs(n - m) >= 2:\n        ans = 0\n    elif abs(n - m) == 1:\n        ans = (factorial(n, md) * factorial(m, md))\n        ans %= md\n    else:\n        ans = (factorial(n, md) * factorial(m, md)) * 2\n        ans %= md\n\n    print(ans)\n\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.16, "memory": 14320.0, "status": "done"}, {"code": "from math import factorial\nn, m = map(int, input().split())\nif n == m:\n    print(factorial(n)*factorial(m)*2 % (10**9+7))\nelif abs(n-m) <= 1: \n    print(factorial(n)*factorial(m) % (10**9+7))\nelse:\n    print(0)", "passed": true, "time": 0.59, "memory": 14292.0, "status": "done"}, {"code": "def gyakugen(x,p):\n  binp = str(bin(p-2))[::-1]\n  ruijou = x\n  \n  result = 1\n  for i in range(len(binp)-2):\n    if binp[i] == \"1\":\n      result *= ruijou\n      result %= p\n    ruijou *= ruijou\n    ruijou %= mod\n  return result\n\nN, M = [int(i) for i in input().split()]\nmod = 10**9+7\n\nif abs(N-M) > 1 :\n  print(0)\n  return\nelif N == M:\n  ans = 1\n  for i in range(1,N+1):\n    ans *= i\n    ans %= mod\n    ans *= i\n    ans %= mod\n  ans *= 2\n  ans %= mod\n  print(ans)\nelse:\n  ans = 1\n  m = min(N,M)\n  for i in range(1,m+1):\n    ans *= i\n    ans %= mod\n    ans *= i\n    ans %= mod\n  ans *= max(N,M)\n  ans %= mod\n  print(ans)", "passed": true, "time": 0.16, "memory": 14288.0, "status": "done"}, {"code": "from math import factorial\n\nn, m = map(int, input().split())\nif n == m:\n    ans = factorial(n) % (10 ** 9 + 7)\n    ans = ans ** 2 % (10 ** 9 + 7)\n    print(ans * 2 % (10 ** 9 + 7))\nelif abs(n - m) == 1:\n    ans1 = factorial(n) % (10 ** 9 + 7)\n    ans2 = factorial(m) % (10 ** 9 + 7)\n    print(ans1 * ans2 % (10 ** 9 + 7))\nelse:\n    print(0)", "passed": true, "time": 0.28, "memory": 14228.0, "status": "done"}, {"code": "N, M = map(int,input().split())\nans = 1\nif abs(N-M) >= 2:\n    ans = 0\nelif N == M:\n    for i in range(1,M+1):\n        ans = (ans*i) % (10**9+7)\n    for i in range(1,M+1):\n        ans = (ans*i) % (10**9+7)\n    ans = (ans*2) % (10**9+7)\nelse:\n    for i in range(1,M+1):\n        ans = (ans*i) % (10**9+7)\n    for i in range(1,N+1):\n        ans = (ans*i) % (10**9+7)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "# C - Reconciled?\ndef main():\n    from math import factorial\n\n    n, m = map(int, input().split())\n    p = 10**9+7\n\n    if abs(n-m) < 2:\n        if n == m:\n            print(2*factorial(n)*factorial(m)%p)\n        else:\n            print(factorial(n)*factorial(m)%p)\n    else:\n        print(0)\n\nif __name__ ==  \"__main__\":\n    main()", "passed": true, "time": 0.59, "memory": 14820.0, "status": "done"}]