#include using namespace std; #define rep(i, n) for(int i = 0; i < int(n); i++) using ll = long long; using P = pair; // MODINT const int MOD = 1000000007; struct mint { long long x; mint(long long x = 0):x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } bool operator==(const mint& a) const { return x == a.x; } }; mint modpow(mint x, ll t) { return x.pow(t); } mint modinv(mint x) {return x.inv(); } istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll a, b, c, d; cin >> a >> b >> c >> d; ll n; cin >> n; mint so = modpow(16, n / 8); n %= 8; ll w = 1, x = 0, y = 0, z = 1; rep(i, n) { ll nw = w - y, nx = x - z, ny = w + y, nz = x + z; w = nw, x = nx, y = ny, z = nz; } // XはAの係数、YはBの係数 mint X = w + y, Y = x + z; X *= (w + y > 0 ? b : a); Y *= (x + z > 0 ? d : c); mint ans = (X + Y) * so; cout << ans << endl; return 0; }