Last active
June 25, 2017 02:00
-
-
Save mi6112ogit/9f349f69752880ac0279afa731d1fb9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define FOR(i, j, k) for(int i = j; i < k; ++i) | |
#define rep(i, j) FOR(i, 0, j) | |
#define FORr(i, j, k) for(int i = j; i >= k; --i) | |
#define repr(i, j) FOR(i, j, 0) | |
#define INF (1 << 30) | |
typedef long long ll; | |
typedef unsigned long long ull; | |
typedef pair<int, int> P; | |
typedef pair<P, int> Pi; | |
const ll MOD = 1e9 + 7; | |
const int dy[]={0, 0, 1, -1}; | |
const int dx[]={1, -1, 0, 0}; | |
template <class T> void chmin(T& a, const T& b) { a = min(a, b); } | |
template <class T> void chmax(T& a, const T& b) { a = max(a, b); } | |
ll modnPr(ll n, ll r) { | |
int res = 1; | |
for(ll i = 0; i < r; ++i) { | |
res = res * (n - i) % MOD; | |
} | |
return res; | |
} | |
int main() { | |
ll N, M; | |
scanf("%lld %lld", &N ,&M); | |
if(abs(N - M) > 1) printf("%d\n", 0); | |
else { | |
if(N == M) { | |
ll dog = modnPr(N, N) % MOD; | |
ll monkey = modnPr(M, M) % MOD; | |
ll ans = dog * monkey * 2 % MOD; | |
printf("%lld\n", ans); | |
} | |
else { | |
ll dog = modnPr(N, N) % MOD; | |
ll monkey = modnPr(M, M) % MOD; | |
ll ans = dog * monkey % MOD; | |
printf("%lld\n", ans); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment