#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include using namespace std; #include using namespace atcoder; #define REP(i, n) for(int i = 0; i < (int)n; i++) #define LREP(i, n) for(LL i = 0; i < (LL)n; i++) #define RREP(i, n) for(int i = (int)n-1; i >= 0; i--) #define V(T) vector //#define P pair #define LP pair #define T3 tuple #define T4 tuple #define INF 1000000007 #define SIZE 500100 #define MOD 1000000007 typedef long long LL; LL P, K; int main() { cin >> P >> K; LL ans = 1, s = 1; LREP(i, K) { LL next = (ans * P) % MOD; next = (next + (s - ans) + MOD) % MOD; next = (next + s) % MOD; s = (s * 2 * P) % MOD; ans = next; } cout << ans << endl; }