#include #define REP(i, n) for(int i = 0; i < (int)(n); i++) using ll = long long; using namespace std; struct S { int id = 0; ll v1, v2, v3, v4; S(ll mv1, ll mv2, ll mv3, ll mv4) : v1(mv1), v2(mv2), v3(mv3), v4(mv4) {} bool operator<(const S &r) const { if(v1 != r.v1) return v1 < r.v1; if(v2 != r.v2) return v2 < r.v2; if(v3 != r.v3) return v3 < r.v3; if(v4 != r.v4) return v4 < r.v4; return id < r.id; } }; int main() { ll v1, v2, v3, v4, N; cin >> v1 >> v2 >> v3 >> v4 >> N; map mp; S now(v1, 0, 0, 0); bool skip = false; REP(i, N) { now.id = i % 4; if(!skip && mp.count(now)) { cerr << "hoge" << endl; ll dist = i - mp[now]; ll remain = N - i; remain = (remain / dist) * dist; i += remain; skip = true; } if(i % 4 == 0) { { // 1 ll add = v2 - now.v2; add = min(add, now.v1); now.v1 -= add, now.v2 += add; } } if(i % 4 == 1) { { // 2 ll add = v3 - now.v3; add = min(add, now.v2); now.v2 -= add, now.v3 += add; } } if(i % 4 == 2) { { // 3 ll add = v4 - now.v4; add = min(add, now.v3); now.v3 -= add, now.v4 += add; } } if(i % 4 == 3) { { // 1 ll add = v1 - now.v1; add = min(add, now.v4); now.v4 -= add, now.v1 += add; } } mp[now] = i; } printf("%lld %lld %lld %lld\n", now.v1, now.v2, now.v3, now.v4); }