#include using namespace std; typedef long long ll; typedef pair P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) templateostream& operator<<(ostream& os,const pair& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; ll const mod = 1e9+7; vector> prod(vector>& a, vector>& b, ll mod) { vector> ret(a.size(),vector(b[0].size(),0)); for (int i = 0;i < a.size();++i) for (int j = 0;j < b[0].size();++j) for (int k = 0;k < a[0].size();++k) { ret[i][j] += a[i][k]*b[k][j]; ret[i][j] %= mod; } return ret; } int main() { ll a,b,n; cin >> a >> b >> n; vector> ans(2,vector(1,0)),c(2,vector(2)); ans[0][0] = 2*a; ans[1][0] = 2; c[0][0] = 2*a; c[0][1] = (-a*a+b)%mod; c[1][0] = 1; c[1][1] = 0; if (n == 0) { cout << 2 << newl; return 0; } n--; while (n) { if (n&1) ans = prod(c,ans,mod); c = prod(c,c,mod); n /= 2; } cout << (ans[0][0]+mod)%mod << newl; }