#include using namespace std; using ll = long long; #define BEGIN_STACK_EXTEND(size) \ void *stack_extend_memory_ = malloc(size); \ void *stack_extend_origin_memory_; \ char *stack_extend_dummy_memory_ = (char *)alloca((1 + (int)(((long long)stack_extend_memory_) & 127)) * 16); \ *stack_extend_dummy_memory_ = 0; \ asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp" \ : "=b"(stack_extend_origin_memory_) \ : "a"((char *)stack_extend_memory_ + (size)-1024)); #define END_STACK_EXTEND \ asm volatile("mov %%rax, %%rsp" ::"a"(stack_extend_origin_memory_)); \ free(stack_extend_memory_); #define mod 1000000007ll #define loop(i, n) for (int i = 0; i < n; i++) #define flagcount(bit) __builtin_popcount(bit) #define flag(x) (1ll << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1ll << i)) #define all(v) v.begin(), v.end() #define putout(a) cout << a << '\n' #define Sum(v) accumulate(all(v), 0ll) template bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } void AS(ll X, ll L, ll R) { assert(L <= X && X <= R); } using mint = long long; mint modpow(mint a, long long n) { mint res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { //cout << fixed << setprecision(10); ll A, B, C, D, N; cin >> A >> B >> C >> D >> N; N++; //答えはb_{N+1} ll x = N / 8; mint ans = modpow(16, x); N %= 8; if (N == 0) ans *= D; if (N == 1) ans *= (B + D) % mod; if (N == 2) ans *= 2 * B % mod; if (N == 3) ans *= 2 * (B - C) % mod; if (N == 4) ans *= -4 * C % mod; if (N == 5) ans *= (-4 * (A + C)) % mod; if (N == 6) ans *= -8 * A % mod; if (N == 7) ans *= -8 * (A - D) % mod; while (ans < 0) ans += mod; ans %= mod; putout(ans); return 0; }