#include using namespace std; long mod = 0; long getDublicatedPatterns(int cubes, int colors); inline long getCombination(int all, int select); int main(){ int n,m; cin >> n; cin >> m; //s << "n " << n << " m " << m << endl; int numInkBottol = m; int numWanabePainted =n; long patterns = 1; mod = (long)pow(10,9)+7; //long tmp = getCombination(45,43); //cout << tmp << endl; //return 0; if (numWanabePainted > numInkBottol) { patterns = getDublicatedPatterns(numWanabePainted,numInkBottol); //cout << patterns << endl; int plusMinus = 1; for(int i = numInkBottol;i > 0; i--){ patterns = patterns - (plusMinus * getCombination(numInkBottol,i -1) * getDublicatedPatterns(numWanabePainted,i-1)); patterns = patterns % mod; plusMinus *= -1; //cout <<"i " < 0; i--){ patterns = patterns * i; patterns = patterns % mod; } } cout << patterns << endl; } inline long getDublicatedPatterns(int cubes, int colors){ long ret = 1; for(int i = cubes;i>0;i--){ ret = ret*colors; ret = ret % mod; //cout << "i " << i << " colors " < top; vector bottom; for(int i = select;i > 0; i--){ top.push_back(all-(select-i)); bottom.push_back(i); } for(int i = 0; i < select;i++){ //cout << " " << top[i]; } //cout << endl; for(int i = 0; i < select;i++){ //cout << " " << bottom[i]; } //cout << endl; for(int i = 0; i< select;i++){ if(bottom[i]!=1){ for(int j =0 ; j < select; j++){ if(top[j]%bottom[i]==0){ top[j] = (top[j]/bottom[i]); bottom[i] = 1; } } } } long topTmp = 1; long bottomTmp = 1; for(int i = 0; i < select;i++){ //cout << " " << top[i]; topTmp*=top[i]; bottomTmp*=bottom[i]; topTmp %= mod; bottomTmp %= mod; } //cout << endl; for(int i = 0; i < select;i++){ //cout << " " << bottom[i]; } //cout << bottomTmp << endl; ret = topTmp/bottomTmp; //cout << "conbination " << ret << " all " << all << " select " << select<< endl; return ret; }