#include <iostream>
#include <cstdio>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c,k;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
    ll t1=a,t2=b,t3=c;
    for(ll i=1;i<=k;i++)
    {
        a=t2+t3;
        b=t1+t3;
        c=t1+t2;
    }
    printf("%lld\n",a-b);
}
