#include using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using pll = pair; using tlll = tuple; constexpr ll INF = 1LL << 60; template bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll safemod(ll A, ll M) {ll res = A % M; if (res < 0) res += M; return res;} ll divfloor(ll A, ll B) {if (B < 0) A = -A, B = -B; return (A - safemod(A, B)) / B;} ll divceil(ll A, ll B) {if (B < 0) A = -A, B = -B; return divfloor(A + B - 1, B);} ll pow_ll(ll A, ll B) {if (A == 0 || A == 1) {return A;} if (A == -1) {return B & 1 ? -1 : 1;} ll res = 1; for (int i = 0; i < B; i++) {res *= A;} return res;} ll mul_limited(ll A, ll B, ll M = INF) { return B == 0 ? 0 : A > M / B ? M : A * B; } ll pow_limited(ll A, ll B, ll M = INF) { if (A == 0 || A == 1) {return A;} ll res = 1; for (int i = 0; i < B; i++) {if (res > M / A) return M; res *= A;} return res;} template void unique(vector &V) {V.erase(unique(V.begin(), V.end()), V.end());} template void sortunique(vector &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) template void printvec(const vector &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " ");cout << '\n';} template void printvect(const vector &V) {for (auto v : V) cout << v << '\n';} template void printvec2(const vector> &V) {for (auto &v : V) printvec(v);} //* #include using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; //using mint = modint; //*/ /* x[0] = start, x[i+1] = next_index(x[i]) の漸化式で定まるインデックス列に対して get(x[0]) op … op get(x[K-1]) を求める (K はクエリで渡される) Index: x_i の型 Data: 求める値の型、モノイド op: 結合則を満たす演算 e: 単位元 power(b, t) = b^t = b op … op b (t 回) 計算量: 前計算 O(周期)、クエリ O(1) */ template struct Period { private: vector dat, prod_head, prod_tail; int lambda, mu; Data head, tail; public: Period(Index start) { Index a = start, b = start; do { dat.emplace_back(get(a)); a = next_index(a); b = next_index(next_index(b)); } while (a != b); mu = dat.size(); Index c = start; while (a != c) { dat.emplace_back(get(a)); a = next_index(a); c = next_index(c); } lambda = (int)dat.size() - mu; prod_head.resize((int)dat.size() + 1); prod_tail.resize((int)dat.size() + 1); prod_head[0] = e(), prod_tail[lambda] = e(); for (int i = 1; i < (int)prod_head.size(); i++) prod_head[i] = op(prod_head[i - 1], dat[i - 1]); for (int i = lambda + 1; i < (int)prod_tail.size(); i++) prod_tail[i] = op(prod_tail[i - 1], dat[i - 1]); head = prod_head[lambda]; tail = prod_tail[lambda + mu]; } Data query(ll k) { if (k <= (int)dat.size()) return prod_head[k]; Data mid = prod_tail[lambda + (k - lambda) % mu]; return op(op(head, power(tail, (k - lambda) / mu)), mid); } }; array V; using state = pair>; state next_index(state s) { auto [i, v] = s; ll j = (i + 1) % 4; ll k = min(v.at(i), V.at(j) - v.at(j)); v.at(i) -= k, v.at(j) += k; return {j, v}; } state get(state s) { return s; } state e() { return {-1, {{-1, -1, -1, -1}}}; } state op(state a, state b) { return b == e() ? a : b; } state power(state a, ll t) { return a; } int main() { for (ll i = 0; i < 4; i++) { cin >> V.at(i); } ll N; cin >> N; Period pe({0, {{V.at(0), 0, 0, 0}}}); auto ans = pe.query(N + 1).second; for (ll i = 0; i < 4; i++) { cout << ans.at(i) << (i == 3 ? '\n' : ' '); } }