#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long LL;

class SumOfPowers
{
public:
	int value(int n, int k) 
	{
		//  2^m - 1^m = (1+1)^m - 1^m = mC1 1^(m-1) + ... + mCi 1^(m-i) + ... + mCm 1^0
		//  3^m - 2^m = (2+1)^m - 1^m = mC1 2^(m-1) + ... + mCi 2^(m-i) + ... + mCm 2^0
		//+ ...
		//--------------------------------------------------------------------------------
		//  (n+1)^m - 1  = mC1 \Sigma n^(m-1) + ... + mCi \Sigma n^(m-i) + ... + mCm \Sigma n^0

		vector<LL> vals;
		for(int m=1; m<=k+1; ++m)
		{
			LL x = SUB(POW(n+1, m), 1);
			for(int i=2; i<=m; ++i)
				x = SUB( x, MUL(C(m, i), vals[m-i]) );
			x = DIV(x, m);
			vals.push_back(x);
		}
		return (int)vals.back();
	}
	LL ADD(LL x, LL y) { return (x+y)%1000000007; }
	LL SUB(LL x, LL y) { return (x-y+1000000007)%1000000007; }
	LL MUL(LL x, LL y) { return (x*y)%1000000007; }
	LL C(LL n, LL k) {
		LL v = 1;
		for(LL i=1; i<=k; ++i)
			v = DIV(MUL(v, n-i+1), i);
		return v;
	}
	LL POW(LL x, LL e) {
		LL v = 1;
		for(;e;x=MUL(x,x),e>>=1)
			if(e&1)
				v = MUL(v, x);
		return v;
	}
	LL DIV(LL x, LL y) {
		LL iy, _;
		xgcd(y, 1000000007, &iy, &_);
		return MUL(x, (iy+1000000007)%1000000007);
	}
	LL xgcd(LL a, LL b, LL* x, LL* y) { // ax+by=g
		if(b) {
			LL yy, g = xgcd(b,a%b,&yy,x);
			*y = yy - a/b**x;
			return g;
		}
		else {
			*x=1, *y=0;
			return a;
		}
	}

// BEGIN CUT HERE
	public:
	void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); }
	private:
	template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
	void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
	void test_case_0() { int Arg0 = 5; int Arg1 = 1; int Arg2 = 15; verify_case(0, Arg2, value(Arg0, Arg1)); }
	void test_case_1() { int Arg0 = 4; int Arg1 = 2; int Arg2 = 30; verify_case(1, Arg2, value(Arg0, Arg1)); }
	void test_case_2() { int Arg0 = 13; int Arg1 = 5; int Arg2 = 1002001; verify_case(2, Arg2, value(Arg0, Arg1)); }
	void test_case_3() { int Arg0 = 123456789; int Arg1 = 1; int Arg2 = 383478132; verify_case(3, Arg2, value(Arg0, Arg1)); }

// END CUT HERE
};
// BEGIN CUT HERE 
int main() {
	SumOfPowers().run_test(-1);
}
// END CUT HERE
