#include using namespace std; using ll = long long; const ll MOD = 1000000007; struct mint { ll x; mint(ll x = 0) : x(x % MOD) {} mint& operator+=(const mint rh) { if((x += rh.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint rh) { if((x += MOD-rh.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint rh) { (x *= rh.x) %= MOD; return *this; } mint operator+(const mint rh) const { return mint(*this) += rh; } mint operator-(const mint rh) const { return mint(*this) -= rh; } mint operator*(const mint rh) const { return mint(*this) *= rh; } mint pow(ll k) const { if(!k) return 1; mint a = x; mint res = 1; while(k) { if(k & 1) res *= a; k >>= 1; a *= a; } return res; } mint inv() const { return pow(MOD-2); } mint& operator/=(const mint rh) { return *this *= rh.inv(); } mint operator/(const mint rh) { return mint(*this) /= rh; } }; template struct matrix { int r, c; vector> mat; //単位行列 static matrix e(int n) { matrix res(n, n); for(int i=0; i(c,val)) {} matrix(vector> mat) : r((int)mat.size()), c((int)mat[0].size()), mat(mat) {} matrix operator-() const { matrix B = mat; for(int i=0; i operator[](const int i) const { return mat[i]; } vector& operator[](const int i) { return mat[i]; } //比較演算子 bool operator==(matrix B) { if(r != B.r || c != B.c) return false; for(int i=0; i> m(r, vector(B.c, 0)); for(int i=0; i= 0); assert(c == r); matrix x = mat; matrix res = e(r); while(k) { if(k & 1) res = (res * x); k >>= 1; x *= x; } return res; } matrix inv() const {} matrix& operator/=(const matrix B) { (*this) *= B.inv(); return *this; } matrix& operator/(const matrix B) const { return matrix(*this) /= B; } //変形する操作 matrix& transpose() { vector> res(c, vector(r)); for(int i=0; i size() const { return make_pair(r, c); } void show(int wid = 2) const { for(int i=0; i> a >> b >> n; mint a1(2), a2(2*a); matrix t(2, 2); t[0][0] = 2*a; t[0][1] = mint(mint(b) - mint(a*a)); t[1][0] = mint(1); t[1][1] = mint(0); t = t.pow(n); mint ans = t[1][0] * a2 + t[1][1] * a1; cout << ans.x << endl; return 0; }