#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } #include using mint = atcoder::modint1000000007; using mat = array, 3>; constexpr mat e = {{ { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, }}; mat mmul(mat x, mat y, int64_t mod) { mat z = {}; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { z[i][j] += (x[i][k] * y[k][j]) % mod; z[i][j] %= mod; } } } return z; } mat mpow(mat m, int64_t x, int64_t mod) { mat ans = e; while (x != 0) { if (x & 1) { ans = mmul(ans, m, mod); } m = mmul(m, m, mod); x >>= 1; } return ans; } int main() { int64_t a, b, c, k; cin >> a >> b >> c >> k; mat m = {{ { 0, 1, 1 }, { 1, 0, 1 }, { 1, 1, 0 }, }}; m = mmul(mpow(m, k, 1000000007 - 1), e, 1000000007 - 1); mint ans = 1; for (int i = 0; i < 3; ++i) { ans *= mint(a).pow(m[i][0]); ans *= mint(b).pow(m[i][1]); ans *= mint(c).pow(m[i][2]); } cout << ans.val() << endl; }