This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 200030
#define mod 1000000007
using namespace std;
typedef long long ll;
ll n, m, ans, pot[N], fat[N];
ll Pow(ll x, ll p)
{
	if(!p) return 1LL;
	ll ans = Pow(x, p/2);
	ans = (ans*ans)%mod;
	if(p & 1) return (ans*x)%mod;
	return ans;
}
ll inverse(ll x){
	return Pow(x, mod - 2)%mod;
}
ll Choose(ll a, ll b)
{
	ll B = (fat[b]*fat[a - b])%mod;
	return (fat[a]*inverse(B))%mod;
}
int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m;
	pot[0] = fat[0] = 1;
	m--;
	for(int i = 1; i < N; i++) fat[i] = (i*fat[i - 1])%mod;
	for(int k = 0; k <= m + 1; k++)
	{
		ll sign = (k%2 == 0 ? 1 : -1);
		ans = (ans + ((sign*Choose(n + 1, k)*Pow(m + 1 - k, n))%mod) )%mod;
	}
	cout<<(mod + ans)%mod<<'\n';
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |