#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
    freopen("genom.in", "r", stdin);
    freopen("genom.out", "w", stdout);
    long long x, y, z, k;
    cin >> x >> y >> z >> k;
    for (long long i = 0; i < k; i++)
    {
        long long a = y + z, b = x + z, c = x + y;
        x = a, y = b, z = c;
    }
    cout << x - y << endl;
    return 0;
}