#include #define base ll(1e9+7) using namespace std; typedef long long ll; struct Matrix{int r,c;ll matr[2][2];}; Matrix operator*(Matrix a,Matrix b) { Matrix ans = a; for(int i = 0 ; i < a.r ; i++) for(int j = 0 ; j < b.c ; j++) { ans.matr[i][j] = 0; for(int k = 0 ; k < a.c ; k++) ans.matr[i][j] = (ans.matr[i][j]+a.matr[i][k]*b.matr[k][j])%base; } return ans; } Matrix operator^(Matrix a,ll y) { Matrix ans = a; y--; while(y > 0) { if(y%2) ans = ans*a; a = a*a; y >>= 1; } return ans; } ll Pow(ll x, int y) { if(!y) return 1; ll ans = Pow(x,y/2); ans = (ans*ans)%base; if(y%2) ans = (ans*x)%base; return ans; } int main() { ll a, b, p; cin >> a >> b >> p; a = (a*Pow(2,base-2))%base; b = (b*Pow(2,base-2))%base; Matrix matr; matr.r = 2; matr.c = 2; matr.matr[0][0] = a; matr.matr[0][1] = b; matr.matr[1][0] = a; matr.matr[1][1] = b; matr = matr ^ p; cout << (matr.matr[0][0]+matr.matr[0][1])%base; }