MOD = 10**9+7 A,B,C,D = map(int,input().split()) N = int(input()) if N%8>=4: A,B,C,D = -B,-A,-D,-C if N%4==0: print((B+D)*pow(4,N//4,MOD)%MOD) elif N%4==1: print((2*B)*pow(4,N//4,MOD)%MOD) elif N%4==2: print(2*(B-C)*pow(4,N//4,MOD)%MOD) elif N%4==3: print(-4*C*pow(4,N//4,MOD)%MOD)