#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct matran{
ll a[2][2];
void print(){
for(ll i=0;i<2;i++){
for(ll j=0;j<2;j++) cout<<a[i][j]<<" ";
cout<<'\n';
}
}
};
matran mot;
struct cap{
ll u,u_plus_1;
void print(){
cout<<u<<" "<<u_plus_1<<'\n';
}
};
matran prod(matran A,matran B){
matran anss;
anss.a[0][0]=A.a[0][0]*B.a[0][0] + A.a[0][1] * B.a[1][0];
anss.a[0][1]=A.a[0][0]*B.a[0][1] + A.a[0][1] * B.a[1][1];
anss.a[1][0]=A.a[1][0]*B.a[0][0] + A.a[1][1] * B.a[1][0];
anss.a[1][1]=A.a[1][0]*B.a[0][1] + A.a[1][1] * B.a[1][1];
return anss;
}
matran po(matran X,ll n){
matran res = X, ans = mot;
while(n){
if(n%2) ans = prod(ans,res);
res = prod(res,res);
n/=2;
}
return ans;
}
cap prod1(cap pp, matran X){
cap ans;
ans.u = pp.u * X.a[0][0]+pp.u_plus_1 * X.a[1][0];
ans.u_plus_1 = pp.u * X.a[1][0]+pp.u_plus_1 * X.a[1][1];
return ans;
}
int main(){
ll a,b,nn;
cin>>a>>b;
cin>>nn;
cap init;
init.u = a;
init.u_plus_1 = b;
matran M;
M.a[0][0]=0;
M.a[0][1]=-1;
M.a[1][0]=1;
M.a[1][1]=2;
mot.a[0][0]=1;
mot.a[0][1]=0;
mot.a[1][0]=0;
mot.a[1][1]=1;
matran res = po(M,nn-1);
cap ansss = prod1(init,res);
cout<<ansss.u<<'\n';
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcgCnN0cnVjdCBtYXRyYW57CiAgICBsbCBhWzJdWzJdOwogICAgdm9pZCBwcmludCgpewogICAgICAgICAgICBmb3IobGwgaT0wO2k8MjtpKyspewogICAgICAgICAgICAgICAgICAgIGZvcihsbCBqPTA7ajwyO2orKykgY291dDw8YVtpXVtqXTw8IiAiOwogICAgICAgICAgICAgICAgICAgIGNvdXQ8PCdcbic7CiAgICAgICAgICAgIH0KICAgIH0KfTsKbWF0cmFuIG1vdDsKc3RydWN0IGNhcHsKICAgbGwgdSx1X3BsdXNfMTsKICAgdm9pZCBwcmludCgpewogICAgICAgICAgIGNvdXQ8PHU8PCIgIjw8dV9wbHVzXzE8PCdcbic7CiAgIH0KfTsKbWF0cmFuIHByb2QobWF0cmFuIEEsbWF0cmFuIEIpewogICAgICAgIG1hdHJhbiBhbnNzOwogICAgICAgIGFuc3MuYVswXVswXT1BLmFbMF1bMF0qQi5hWzBdWzBdICsgQS5hWzBdWzFdICogQi5hWzFdWzBdOwogICAgICAgIGFuc3MuYVswXVsxXT1BLmFbMF1bMF0qQi5hWzBdWzFdICsgQS5hWzBdWzFdICogQi5hWzFdWzFdOwogICAgICAgIGFuc3MuYVsxXVswXT1BLmFbMV1bMF0qQi5hWzBdWzBdICsgQS5hWzFdWzFdICogQi5hWzFdWzBdOwogICAgICAgIGFuc3MuYVsxXVsxXT1BLmFbMV1bMF0qQi5hWzBdWzFdICsgQS5hWzFdWzFdICogQi5hWzFdWzFdOwogICAgICAgIHJldHVybiBhbnNzOwp9Cm1hdHJhbiBwbyhtYXRyYW4gWCxsbCBuKXsKICAgICAgICBtYXRyYW4gcmVzID0gWCwgYW5zID0gbW90OwogICAgICAgIHdoaWxlKG4pewogICAgICAgICAgICAgICAgaWYobiUyKSBhbnMgPSBwcm9kKGFucyxyZXMpOwogICAgICAgICAgICAgICAgcmVzID0gcHJvZChyZXMscmVzKTsKICAgICAgICAgICAgICAgIG4vPTI7CiAgICAgICAgfQogICAgICAgIHJldHVybiBhbnM7Cn0KY2FwIHByb2QxKGNhcCBwcCwgbWF0cmFuIFgpewogICAgICAgIGNhcCBhbnM7CiAgICAgICAgYW5zLnUgPSBwcC51ICogWC5hWzBdWzBdK3BwLnVfcGx1c18xICogWC5hWzFdWzBdOwogICAgICAgIGFucy51X3BsdXNfMSA9ICBwcC51ICogWC5hWzFdWzBdK3BwLnVfcGx1c18xICogWC5hWzFdWzFdOwogICAgICAgIHJldHVybiBhbnM7Cn0KaW50IG1haW4oKXsKICAgIAogICAgICAgIGxsIGEsYixubjsKICAgICAgICBjaW4+PmE+PmI7CiAgICAgICAgY2luPj5ubjsKICAgICAgCiAgICAgICAgY2FwIGluaXQ7CiAgICAgICAgaW5pdC51ID0gYTsKICAgICAgICBpbml0LnVfcGx1c18xID0gYjsKICAgICAgICBtYXRyYW4gTTsKICAgICAgICBNLmFbMF1bMF09MDsKICAgICAgICBNLmFbMF1bMV09LTE7CiAgICAgICAgTS5hWzFdWzBdPTE7CiAgICAgICAgTS5hWzFdWzFdPTI7CiAgICAgICAgbW90LmFbMF1bMF09MTsKICAgICAgICBtb3QuYVswXVsxXT0wOwogICAgICAgIG1vdC5hWzFdWzBdPTA7CiAgICAgICAgbW90LmFbMV1bMV09MTsKICAgICAgIAogICAgICAgIG1hdHJhbiByZXMgPSBwbyhNLG5uLTEpOwogICAgICAgIGNhcCBhbnNzcyA9IHByb2QxKGluaXQscmVzKTsKICAgICAgICBjb3V0PDxhbnNzcy51PDwnXG4nOwogICAKCgp9