#B2020. Candy Distribution Game
Candy Distribution Game
Candy Distribution Game
In a kindergarten, there are 5 children numbered \(1,2,3,4,5\) sitting around a circular table in order. Initially, each child has a certain number of candies. They play the following game in one round: starting with child 1 and proceeding in order to child 5, each child performs the following operation:
- Let \(D\) be the current number of candies the child has.
- Divide \(D\) into 3 equal parts. To do so, compute \(q=\lfloor D/3 \rfloor\) and the remainder \(r=D \mod 3\). The child immediately eats the \(r\) leftover candies.
- The child keeps one share (i.e. \(q\) candies) for himself/herself and gives one share each (i.e. \(q\) candies) to the left and right neighbors. Note that the neighboring indices wrap around: for child 1, the left neighbor is child 5; for child 5, the right neighbor is child 1.
After all 5 children have taken their turn, determine the final number of candies each child has.
inputFormat
The input consists of a single line containing 5 space-separated integers \(c_1, c_2, c_3, c_4, c_5\), where \(c_i\) is the initial number of candies for child \(i\) (\(1 \leq i \leq 5\)).
outputFormat
Output a single line containing 5 space-separated integers, representing the final number of candies held by child 1 to child 5, respectively, after one round of the game.
sample
9 6 3 18 15
14 5 8 14 8