#define _USE_MATH_DEFIMES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const int MOD = 1'000'000'007; const int MOD2 = 998'244'353; const int INF = 1'000'000'000; //1e9 const int NIL = -1; const long long LINF = 1'000'000'000'000'000'000; // 1e18 const long double EPS = 1E-10; template inline bool chmax(T &a, const S &b){ if(a < b){ a = b; return true; } return false; } template inline bool chmin(T &a, const S &b){ if(b < a){ a = b; return true; } return false; } long long power(long long a, unsigned long long b, long long m){ long long ret(1); while(b){ if(b & 1) ret = (ret * a) % m; a = (a * a) % m; b /= 2; if(ret < 0) ret += m; if(a < 0) a += m; } return ret; } long long rec(long long a, long long b, int n){ for(int i{0}; i < n; ++i){ a -= b; b += a + b; } return a + b; } int main(){ long long A, B, C, D; std::cin >> A >> B >> C >> D; long long N; std::cin >> N; long long prd{power(16, N / 8, MOD)}; long long ans{std::max({rec(A, C, N%8), rec(A, D, N%8), rec(B, C, N%8), rec(B, D, N%8)}) % MOD}; (ans *= prd) %= MOD; if(ans < 0) ans += MOD; std::cout << ans << std::endl; return 0; }