#include #include using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ll mod=1000000007; ll inf=1000000000000000000; vector>mul(vector>&a,vector>&b){ vector>c(a.size(),vector(b[0].size(),0)); for (ll i = 0; i < a.size(); i++) { for (ll j = 0; j < b[0].size(); j++) { for (ll k = 0; k < a[0].size(); k++) { c[i][j]+=(a[i][k]*b[k][j])%mod; c[i][j]%=mod; } } } return c; } vector>matpow(vector>a,ll n){ vector>b(a.size(),vector(a.size(),0)); for (ll i = 0; i < a.size(); i++) { b[i][i]=1; } while (n>0) { if (n%2) { b=mul(a,b); n-=1; }else{ a=mul(a,a); n/=2; } } return b; } int main(){ ll a,b,n; cin >> a >> b >> n; vector>aa={{(2*a)%mod,(b+mod-(a*a)%mod)%mod},{1,0}}; vector>ans=matpow(aa,n); ll x=((2*a)%mod)*ans[1][0]; x%=mod; x+=(2*ans[1][1])%mod; x%=mod; cout << x << endl; }