import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }
 
void main() {
    long a,b,c,k;
    readf("%d %d %d %d\n",&a,&b,&c,&k);
    foreach (i; 0..k) {
        long na = b+c, nb = a+c, nc = a+b;
        a = na; b = nb; c = nc;
        if (a==b && b==c) break;
    }
    writeln(a - b);
}

