V1, V2, V3, V4, N = map(int, input().split()) v = [V1, V2, V3, V4] a = [v[0], 0, 0, 0] current_step = 0 next_op = 1 # after 0 steps, the first operation is 1 state_map = {} state_key = (tuple(a), next_op) state_map[state_key] = current_step found_cycle = False while current_step < N: # Perform the current operation current_op = next_op if current_op == 1: # Pour from 1 to 2 (indices 0 to 1) transfer = min(a[0], v[1] - a[1]) a[0] -= transfer a[1] += transfer elif current_op == 2: # Pour from 2 to 3 (indices 1 to 2) transfer = min(a[1], v[2] - a[2]) a[1] -= transfer a[2] += transfer elif current_op == 3: # Pour from 3 to 4 (indices 2 to 3) transfer = min(a[2], v[3] - a[3]) a[2] -= transfer a[3] += transfer else: # Pour from 4 to 1 (indices 3 to 0) transfer = min(a[3], v[0] - a[0]) a[3] -= transfer a[0] += transfer current_step += 1 if current_step == N: break # Determine next_op for the next step next_op = (current_step % 4) + 1 new_key = (tuple(a), next_op) # Check for cycle if new_key in state_map: prev_step = state_map[new_key] cycle_len = current_step - prev_step remaining_steps = N - current_step cycles = remaining_steps // cycle_len current_step += cycles * cycle_len # Update to the state that started the cycle a = list(new_key[0]) next_op = new_key[1] # Handle remaining steps after cycles if current_step < N: steps_rem = N - current_step for _ in range(steps_rem): curr_op = next_op if curr_op == 1: transfer = min(a[0], v[1] - a[1]) a[0] -= transfer a[1] += transfer elif curr_op == 2: transfer = min(a[1], v[2] - a[2]) a[1] -= transfer a[2] += transfer elif curr_op == 3: transfer = min(a[2], v[3] - a[3]) a[2] -= transfer a[3] += transfer else: transfer = min(a[3], v[0] - a[0]) a[3] -= transfer a[0] += transfer current_step += 1 if current_step >= N: break next_op = (current_step % 4) + 1 break else: state_map[new_key] = current_step print(' '.join(map(str, a)))