local ffi = require("ffi") local C = ffi.C ffi.cdef[[ long long atoll(const char*); ]] local function lltonumber(str) return C.atoll(str) end local mod = 1000000007 local mfl = math.floor local function bmul(x, y) local x1, y1 = mfl(x / 31623), mfl(y / 31623) local x0, y0 = x - x1 * 31623, y - y1 * 31623 return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod end local function modpow(src, pow) local res = 1 while 0LL < pow do if pow % 2LL == 1LL then res = bmul(res, src) end src = bmul(src, src) pow = pow / 2LL end return res end local a, b, c, d = io.read("*n", "*n", "*n", "*n", "*l") local n = lltonumber(io.read()) local n2 = n % 8LL local retmax = false local as = {a, a, b, b} local bs = {c, d, c, d} for i = 1, 4 do local az = as[i] local bz = bs[i] local j = 0LL while j < n2 do az, bz = az - bz, az + bz j = j + 1LL end local v = az + bz if i == 1 or retmax < v then retmax = v end end while retmax < 0 do retmax = retmax + mod end retmax = retmax % mod local rep = n / 8LL local mul = modpow(16, rep) print(bmul(retmax, mul))