#include #if __has_include() #include #endif using namespace std; #define done(...) return pp(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range(0,__VA_ARGS__);ivoid pp(const auto&...a){[[maybe_unused]]const char*c="";((o<(a...);} #define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{ #define use_ml1000000007 using ml=atcoder::modint1000000007; namespace my{ auto&operator<<(ostream&o,const atcoder::modint1000000007&x){return o<<(int)x.val();} void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} void lin(auto&...a){(cin>>...>>a);} constexpr auto pow(auto x,ll n,auto e){assert(n>=0);decltype(x)r=e;for(;n;x*=x,n>>=1)if(n&1)r*=x;return r;} templateusing pack_back_t=tuple_element_t>; } namespace my{ templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ using vector::vector; ll size()const{return vector::size();} }; templaterequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; } namespace my{ templatestruct matrix:vec>{ ll H,W; matrix()=default; matrix(ll n):H(n),W(n){this->resize(n,vec(n));} matrix(ll n,ll m,T x={}):H(n),W(m){this->resize(n,vec(m,x));} matrix(const vec>&v):H(v.size()),W(v[0].size()){vector>::operator=(v);} auto&operator*=(const matrix&a){ assert(W==a.H); matrix r(H,a.W); fo(i,H)fo(k,W)fo(j,a.W)r[i][j]+=(*this)[i][k]*a[k][j]; swap(*this,r); return*this; } friend vecoperator*(const vec&v,const matrix&a){ assert(v.size()==a.H); vecr(a.W); fo(i,a.H)fo(j,a.W)r[j]+=v[i]*a[i][j]; return r; } auto pow(ll n)const{matrix e(H);fo(i,H)e[i][i]=1;return my::pow(*this,n,e);} }; } namespace my{entry void main(){ LL(a,b,N); if(N==0)done(2); use_ml1000000007 matrixA({{2*a,1},{-a*a+b,0}}); A=A.pow(N-1); pp((vec{2*a,2}*A)[0]); }}