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



Sample input:
2 2


Sample output:
8

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
from math import factorial
mod = 10**9+7

if abs(N-M) > 1:
    print(0)
else:
    print(2*factorial(N)*factorial(M)%mod)

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

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

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

n,m = MI()

a = factorial(n)%mod
b = factorial(m)%mod
c = 2
ans = a*b*c % mod
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
if n==m:
  x=1
  for i in range(1,n+1):
    x*=i
    x=x%(10**9+7)
  print((2*x**2)%(10**9+7))
elif abs(n-m)==1:
  s=max(n,m)
  x=1
  for i in range(1,s+1):
    x*=i
    x=x%(10**9+7)
  print((x**2//s)%(10**9+7))
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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


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))

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
new_n=min(n,m)
new_m=max(n,m)

def ans(n,m):
    mod=10**9+7
    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))

Submission status: Wrong Answer

Solution code:
def factorial(n):
    f=1
    for i in range(1,n+1):
        f*=i%(10**9+7)
    return f
n,m=map(int,input().split())
N=factorial(n)
if abs(n-m)>1:
    print(0)
elif abs(n-m)==0:
    print(2*N*N%(10**9+7))
elif n>m:
    print((N*N//n)%(10**9+7))
else:
    print(N*N*m*m%(10**9+7))

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
div = int(10e9+7)

if abs(a-b)>1:
    print(0)
else:
    if a != b:
        x = 1
        y = 1
        for i in range(2,a+1):
            x *= i
            x %= div
        for i in range(2,b+1):
            y *= i
            y %= div
        print(x*y%div)
    else:
        print(a*b*2%div)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
div = 1000000007

if abs(a-b)>1:
    print(0)
else:
    print(a*b*2%div)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
div = 10e9+7

if abs(a-b)>1:
    print(0)
else:
    print(a*b*2//div)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

Solution code:
import math
N,M=map(int,input().split())
p=10**9 +7
ans=(math.factorial(N)+math.factorial(M))*2 % p
print(ans)

Submission status: Wrong Answer

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

import math
if n == m:
    dog = math.factorial(n)
    mon = math.factorial(m)
    ans = dog * mon * 2
elif n == m + 1 or n == m - 1:
    dog = math.factorial(n)
    mon = math.factorial(m)
    ans = dog * mon
else:
    ans = 0

print(ans // (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
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()

Submission status: Wrong Answer

Solution code:
from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

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

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7


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


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

if abs(N - M) < 2:
    ans *= fact(N, MOD) * fact(M, MOD) % MOD
    if N == M:
        ans *= 2
        ans %= MOD
print(ans)

Submission status: Wrong Answer

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

if abs(n - m) < 2:
  res = 2 * math.factorial(n) * math.factorial(m)
  print(res % mod)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import math
n, m = map(int, input().split())
mod = 10 ** 9 + 7
res = 2 * math.factorial(n) * math.factorial(m)
print(res % mod)

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

Solution code:
import math
N,M = map(int,input().split())
if abs(N-M) > 1:
    print(0)
    exit()

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)

Submission status: Wrong Answer

Solution code:
import math


def main():
    N, M = 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 * N) % mod
    else:
        ans = (math.factorial(N)**2 * 2) % mod

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import *
N,M = map(int,input().split())
if abs(N - M):
    print(0)
    exit(0)

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

Submission status: Wrong Answer

Solution code:
from math import *
N,M = map(int,input().split())
if N == M:
    print(2 * factorial(N) * factorial(M) % (10**9+7))
else:
    print(factorial(N) * factorial(M) % (10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

Solution code:
# C - Reconciled?
N, M = map(int,input().split())

S = 1
for i in range(1,min(N,M)):
    S *= i

ans = 0
if abs(N-M) > 1:
    ans = 0
elif abs(N-M) == 1:
    ans = S*S*max(N,M)
else:
    ans = S*S*2

ans = ans % 1000000007

print(ans)

Submission status: Wrong Answer

Solution code:
# C - Reconciled?
N, M = map(int,input().split())

S = 1
for i in range(1,min(N,M)):
    S *= i % 1000000007

ans = 0
if abs(N-M) > 1:
    ans = 0
elif abs(N-M) == 1:
    ans = S*S*max(N,M)
else:
    ans = S*S*2

ans = ans % 1000000007

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')

def fmod(x):
    ans = 1
    for i in range(1, x + 1):
        ans *= i
        ans %= MOD
    return ans

def solve():
    n, m = [int(x) for x in input().split()]
    n, m = min(n,m), max(n,m)
    x = m - n
    if x > 1:
        print(0)
    elif x == 1:
        print((fmod(n) * fmod(m)*2)%MOD)
    else:
        print((fmod(n) * fmod(m))%MOD)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

Submission status: Wrong Answer

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

x = max(n,m)
y = min(n,m)

ans = 1

if x-y>2:
    print(0)
else:
    if x == y:
        ans = 2
        for i in range(1,x+1):
            ans *= i
        for i in range(1,y+1):
            ans *= i
        print(ans%1000000009)
    else:
        ans = 2
        for i in range(1,x+1):
            ans *= i
        for i in range(1,y+1):
            ans *= i
        print(ans%1000000009)

Submission status: Wrong Answer

Solution code:
import math
N,M=map(int,input().split())
X=math.factorial(N)
Y=math.factorial(M)
if abs(N-M)>=2:
  print(0)
elif N==M:
  print(X*Y*2)
else:
  print(X*Y)

Submission status: Wrong Answer

Solution code:
from math import factorial as f

n, m = (int(i) for i in input().split())
if n == m:
    print((f(n) * f(m) * 2) % (10 ^ 9 + 7))
elif abs(n - m) == 1:
    print((f(n) * f(m)) % (10 ^ 9 + 7)) 
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from math import factorial as f

n, m = (int(i) for i in input().split())
if n == m:
    print(f(n) * f(m) * 2 % (10 ^ 9 + 7))
elif abs(n - m) == 1:
    print(f(n) * f(m) % (10 ^ 9 + 7)) 
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
n, m = map(int, input().split())
div = 10**9 + 7

if abs(n-m)>1:
    print(0)
    exit()
elif n == m:
    ans1 = math.factorial(n)
    ans = 2 * ans1 * ans1 
else:
    ma = max(n,m)
    mi = max(n,m)
    ans1 = math.factorial(mi)
    ans = ans1*ans1*ma

print(ans % div)

Submission status: Wrong Answer

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

if abs(n - m) > 1:
    print(0)
if n == m:
    ans = 1
    for i in range(2, n + 1):
        ans *= i
        ans %= MOD
    # xoxoxo... とoxoxox... 、どっちを先にするかで2種類
    print(2 * ans * ans % MOD)
else:
    ans = 1
    for i in range(2, n + 1):
        ans *= i
        ans %= MOD
    for i in range(2, m + 1):
        ans *= i
        ans %= MOD
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

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

if abs(n-m) == 1:
    m = min(n,m)
    M = max(n,m)
    print(math.factorial(m)*math.factorial(M) % mod)
    sys.exit()

print(math.factorial(n)**2*2 % mod)

Submission status: Wrong Answer

Solution code:
from math import factorial as f;N,M=sorted(map(int,input().split()));print(f(N)*f(M)*max(0,2-N+M)%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if abs(N-M) >= 2:
  print(0)
  exit()
  
N,M = max(N,M),min(N,M)
fctr_M = 1
for i in range(1,M+1):
  fctr_M *= i
  fctr_M %= MOD

ans = fctr_M * fctr_M
ans %= MOD
ans *= N
if N == M:
  ans *= 2
  ans %= MOD
else:
  ans *= N
  ans %= MOD

print(ans)

Submission status: Wrong Answer

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

if abs(n-m) >= 2:
  print(-1)
  exit()

mod = 10**9+7
ans = 1
# 犬の組み合わせを取得
for i in range(1, n+1):
  ans *= i
  ans %= mod

# 犬の組み合わせに猿の組み合わせを入れる
for j in range(1, m+1):
  ans *= j
  ans %= mod

# 犬と猿が同数の場合は組み合わせが倍になる
# （例） 
# 同数の場合 ⚪⚫⚪⚫ or ⚫⚪⚫⚪
# 片方が多い場合 ⚪⚫⚪⚫⚪
if n == m:
  ans *= 2
  ans %= mod
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n, m = map(int, input().rstrip().split())
    if abs(n - m) > 2:
        print("0")
        return
    if n == m:
        print(math.factorial(n) * math.factorial(m) * 2 % (pow(10, 9) + 7))
    else:
        print(math.factorial(n) * math.factorial(m) % (pow(10, 9) + 7))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

import math

minx = min(n, m)
x = math.factorial(minx) % mod

if n == m:
   print(2*pow(x,2,mod)%mod)
else:
   print(pow(x,2,mod)*(x+1)%mod)

Submission status: Wrong Answer

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

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

import math

minx = min(n, m)
x = math.factorial(minx) % mod

if n == m:
   print(2*pow(x,2,mod)%mod)
else:
   print(2*pow(x,2,mod)*(x+1)%mod)

Submission status: Wrong Answer

Solution code:
def main():
    import math
    n, m = map(int, input().split())
    if n - m <= -2 or n - m >= 2:
        print(0)
        exit()

    else:
        if n != m:
            ans = math.factorial(n) % (10*9 + 7) * math.factorial(m) % (10**9 + 7)
        else:
            ans = math.factorial(n) * 2 % (10**9 + 7) * math.factorial(m) % (10**9 + 7)

    print(ans)


    

 
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

from math import factorial
mod =(10**9) + 7
# v_n = 1
# for i in range(1,n+1):
#     v_n*= i%mod
# v_m = 1
# for j in range(1,m+1):
#     v_m*= j%mod

v_n = factorial(n)
v_m = factorial(m)
if n==m:
    value = (v_n *v_m * 2)%mod
    print(value)

elif abs(n-m)>2:
    print(0)

else:
    ans = (v_n * v_m)%mod
    print(ans)

Submission status: Wrong Answer

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


def lp(animal, row):
    for i in range(1, n+1):
        row *= i
    return row

result = abs(n-m)
limit = 10**9+7
row = 1
if result >= 2:
    print(0)
    exit()
elif result == 1:
    row = lp(n, row)
    row = lp(m, row)
elif n == m:
    row = lp(n, row)
    row = lp(m, row)
    row *= 2

print(row%limit)

Submission status: Wrong Answer

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

def lp(animal, row):
    for i in range(1, n+1):
        row *= i
    return row

result = abs(n-m)
limit = 10**9+7
row = 1
if result >= 2:
    print(0)
elif result == 1:
    row = lp(n, row)
    row = lp(m, row)
elif n == m:
    row = lp(n, row)
    row = lp(m, row)
    row *= 2

print(row%limit)

Submission status: Wrong Answer

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

result = 1
for i in range(1,n+1):
  result = (result *i) % p
for j in range(1,m+1):
  result = (result *j)  % p
  
if n == m:
  result = (result *2) % p

print(result)

Submission status: Wrong Answer

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

result = 1
for i in range(1,n+1):
  result *= i % p
for j in range(1,m+1):
  result *= j % p
  
if n == m:
  result *= 2 % p

print(result)

Submission status: Wrong Answer

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

p=1
q=1
for i in range(1,n+1):
    p*=(i%(10**9+7))
for i in range(1,m+1):
    q*=(i%(10**9+7))


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

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

h_res = 1
for i in range(1,max(N,M)+1):
    h_res = i * h_res % MOD

if N == M:
    print((h_res * h_res * 2) % MOD)
else:
    print((h_res * h_res // max(N,M)) % MOD)

Submission status: Wrong Answer

Solution code:
def main():
    n, m = list(map(int, input().split()))
    mod = 1000000007
    def factorial(num, mod):
        ans = 1
        if num <= 1: return ans
        for i in range(2, n + 1):
            ans = (ans * i) % mod
        return ans

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




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def permutation(n, x, mod=10**9+7):
    # nPx
    # 順列
    # ex) permutaion(5, 2) = 20
    tmp = 1
    for i in range(n, n-x, -1):
        tmp = (tmp * i) % mod
    return tmp

N, M = map(int, sys.stdin.readline().strip().split())

if abs(N - M) > 1:
    print(0)
elif N - M == 1:
    print(permutation(N, N) * permutation(M, M) % (10**9+7))
else:
    print(2 * permutation(N, N) * permutation(M, M)  % (10**9+7))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ans1 = 1
ans2 = 1
mod = 10**9 + 7

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


for i in range(1, n+1):
    ans1 *= i
    ans1 %= mod
for j in range(1, m+1):
    ans2 *= j
    ans2 %= mod

if abs(m-n) == 1:
    print(ans1 * ans2 % mod)
else:
    print(2 * ans1 * ans2 % mod)

Submission status: Wrong Answer

Solution code:
import math
MOD = 10**9+7
n, m = map(int, input().split())

if n == m:
    print( (2 * (math.factorial(n)%MOD)**2) % MOD)
if abs(n-m) == 1:
    print((max(n, m)*(math.factorial(min(n, m))%MOD)**2) % MOD)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
MOD = 10**9+7
n, m = map(int, input().split())

if n == m:
    print( (2 * (math.factorial(n)%MOD)**2) % MOD)
elif abs(n-m) == 1:
    print((math.factorial(min(n, m))%MOD) * max(n, m))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
p = 10**9+7
N,M = map(int,input().split())
a = 1
for i in range(2,N+1):
    a = (a*i)%p
b = 1
for i in range(2,M+1):
    b = (b*i)%p
if M==N:
    n = (2*a*b)%p
else:
    n = (a*b)%p
print(n)

Submission status: Wrong Answer

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

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p) 階乗のmod
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans=(fact[N]*fact[M])%p
if N==M:
    ans*=2
    ans%=p
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

if abs(n - m) >= 2:
    print(0)
elif n - m == 1:
    a = reduce(lambda x, y: (x * y) % mod, range(1, n + 1))
    b = reduce(lambda x, y: (x * y) % mod, range(1, m + 1))
    ans = (a * b) % mod
    print(ans)
elif n == m:
    a = reduce(lambda x, y: (x * y) % mod, range(1, n + 1))
    b = reduce(lambda x, y: (x * y) % mod, range(1, m + 1))
    ans = (a * b * 2) % mod
    print(ans)

Submission status: Wrong Answer

Solution code:
def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp


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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N,M = map(int,input().split())
if(N == 1 or M == 1 or abs(N - M) >= 2):
  print("0")
else:
  if(N != M):
    print(str(((math.factorial(N) * math.factorial(M)) % (10 ** 9 + 7))))
  else:
    print(str(((math.factorial(N) * math.factorial(M))* 2 % (10 ** 9 + 7))))

Submission status: Wrong Answer

Solution code:
import math
N,M = map(int,input().split())
if(N == 1 or M == 1):
  print("0")
else:
  print(str(((math.factorial(N) * math.factorial(M)) % (10 ** 9 + 7))))

Submission status: Wrong Answer

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

if abs(N-M) > 2:
    print(0)
    exit()
sum = 1
count = 0
if N == M:
    sum *= N+M
    sum *= int(((N+M)/2))
    N = int((N+M)/2)-1
    M = N
else:
    sum *= max(N,M)

k = math.factorial(min(N,M))
sum *= k**2

print(sum%(10**9+7))

Submission status: Wrong Answer

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

N = math.factorial(n)
M = math.factorial(m)
INF = 10**9 + 7

if abs(n-m) == 1:
    print(N*M%INF)
else:
    print(2*N*M%INF)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
max = 10**5 + 1
facts = [1 for i in range(max)]
invs = [1 for i in range(max)]

def inv(x):
    return pow(x,MOD-2,MOD)

for i in range(1,max):
    facts[i] = facts[i-1]*i%MOD
    invs[i] = inv(facts[i])

def comb(n,r):
    return facts[n]*invs[r] * invs[n-r] % MOD

n,m = map(int,input().split())
if m > n:
    n,m = m,n
if n-m >= 2:
    print(0)
elif n-m == 1:
    print(facts[m]*facts[n])
else:
    print(facts[m]*facts[n]*2 % MOD)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=s*i
t=1
for j in range(2,M+1):
  t=t*j
if N-1==M:
  print((s*t)%MOD)
if N==M-1:
  print((s*t)%MOD)
if N==M:
  print((2*s*t)%MOD)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
MOD=10**9+7
if N>=M:
  s=1
  for i in range(2,N+1):
    s=s*i
  t=N-M+2
  for j in range(N-M+3,N+1):
    t=t*j
  print((s*t)%MOD)
else:
  s=1
  for i in range(2,M+1):
    s=s*i
  t=M-N+2
  for j in range(N-M+3,N+1):
    t=t*j
  print((s*t)%MOD)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
MOD=10**9+7
if N>=M:
  s=1
  for i in range(2,N+1):
    s=s*i
  s=s%MOD
  t=N-M+2
  for j in range(N-M+3,N+1):
    t=t*j
  t=t%MOD
  print((s*t)%MOD)
else:
  s=1
  for i in range(2,M+1):
    s=s*i
  s=s%MOD
  t=M-N+2
  for j in range(N-M+3,N+1):
    t=t*j
  t=t%MOD
  print((s*t)%MOD)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
if abs(N - M) > 2:
    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)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
if abs(N - M) > 2:
    print(0)
    quit()
MOD = 10 ** 9 + 7
fact = [0] * (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)

Submission status: Wrong Answer

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

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

    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))