//https://yukicoder.me/submissions/753613 #include #include #include using namespace std; #define N 4 int main() { arrayV; for (int i = 0; i < N; cin >> V[i++]); long long X; cin >> X; auto next = [&](pair, int>A) { int from = A.second, to = (from + 1) % N; const int move = min(A.first[from], V[to] - A.first[to]); A.first[from] -= move, A.first[to] += move; A.second = to; return A; }; auto slv = [&](pair, int>A, long long cnt, auto slv) { if (cnt == 0)return A; static map, int>, long long>memo; if (memo.count(A)) { cnt %= memo[A] - cnt; while (cnt--)A = next(A); return A; } else { memo[A] = cnt; return slv(next(A), --cnt, slv); } }; arraystart = { 0 }; start[0] = V[0]; auto ans = slv(make_pair(start, 0), X, slv); for (int i = 0; i < N; i++)cout << ans.first[i] << (i != N - 1 ? ' ' : '\n'); return 0; }