Mixing Milk#10393

Mixing Milk

1 second
128 megabytes
Very easy

Farming is a competitive business—particularly milk production. Farmer John realizes that if he doesn't innovate in his milk production methods, his dairy business could get creamed!

Fortunately, Farmer John has come up with a good idea. His three prize dairy cows, Bessie, Elsie, and Mildred, each produce milk with a slightly different taste. He plans to combine their milk to create the perfect blend of flavors.

To do this, he takes three buckets containing milk from the three cows. The buckets may have different capacities and may not be completely full. He then pours milk from bucket into bucket , then from bucket into bucket , then from bucket into bucket , then from bucket into bucket , and so on, repeating this cycle for a total of pouring operations (so the -th pour is from bucket into bucket ).

When Farmer John pours milk from bucket into bucket , he transfers as much milk as possible, stopping when either bucket becomes empty or bucket becomes full.

Please help Farmer John determine how much milk will remain in each bucket after all pouring operations have been completed.

Input

The first line contains two integers: the capacity c_1 of the first bucket and the amount of milk m_1 initially in it. Both c_1 and m_1 are positive integers not exceeding 10^9, and c_1 \ge m_1. The second and third lines have the same format, describing the capacity and initial amount of milk in the second and third buckets, respectively.

Output

Print three lines, each containing the final amount of milk in the corresponding bucket after all pouring operations.

Examples

The following example illustrates how the amounts of milk in the three buckets change during the pouring process:

Initial State: 3 4 5
1. Pour 1->2:  0  7  5
2. Pour 2->3:  0  0 12
3. Pour 3->1: 10  0  2
4. Pour 1->2:  0 10  2
5. Pour 2->3:  0  0 12

(The last three states then repeat in a cycle ...)

Example 1

Loading
Loading