Problem: There are two water tanks, the first one fits liters of water, the second one fits liters of water. The first tank has () liters of water initially, the second tank has () liters of water initially.
You want to perform operations on them. The -th operation is specified by a single non-zero integer . If , then you try to pour liters of water from the first tank into the second one. If , you try to pour liters of water from the second tank to the first one.
When you try to pour liters of water from the tank that has liters currently available to the tank that can fit more liters of water, the operation only moves liters of water.
For all pairs of the initial volumes of water such that and , calculate the volume of water in the first tank after all operations are performed.
Input Format: The first line contains three integers and (; ) — the number of operations and the capacities of the tanks, respectively.
The second line contains integers (; ) — the volume of water you try to pour in each operation.
Output Format: For all pairs of the initial volumes of water such that and , calculate the volume of water in the first tank after all operations are performed.
Print lines, each line should contain integers. The -th value in the -th line should be equal to the answer for and .
Note: Consider and from the first example:
- The first operation tries to move liters of water from the second tank to the first one, the second tank has liters available, the first tank can fit more liter. Thus, liter is moved, the first tank now contains liters, the second tank now contains liter.
- The second operation tries to move liter of water from the first tank to the second one. liter is moved, the first tank now contains liters, the second tank now contains liter.
- The third operation tries to move liter of water from the first tank to the second one. liters are moved, the first tank now contains liter, the second tank now contains liters.
There's liter of water in the first tank at the end. Thus, the third value in the fourth row is .