Training Site
Sideways banner

Duckstop

Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 128 megabytes
Time limit: 1.0 seconds

Albert is an investor at the Nefarious Zesty Investing Collective (NZIC) and wants to start trading in the new lucrative market: crypto rubber ducks. Albert has designed a master strategy that is sure to create record profits, and as such has been given C dollars of capital to start trading.

Albert's strategy is as follows: they will WAIT until the price of rubber ducks drops to less than or equal to A dollars (and less than or equal to the amount of money they currently have), then BUY as many rubber ducks as they can, and HOLD the rubber ducks until they can SELL all of them for more than they bought the rubber ducks. Albert will repeat this strategy over D days, and has high hopes for great profit. Albert must also make sure that they do not have any leftover rubber ducks on the final day, and so knowing the prices ahead of time Albert will not buy rubber ducks if they will not be able to sell them by the final day according to their strategy.

Albert has heard of algorithmic trading, and has asked you to write a program to simulate their strategy.

Input

The first line contains three space separated integers D, C, A: the number of days, your initial capital and the highest price at which you wish to buy rubber ducks.

The second line contains D space separated integers: the price of rubber ducks on each day.

Output

The first D lines should each contain the action you will perform on the i-th day, which should have one of the four formats (where x is the number of rubber ducks bought or sold):

  • WAIT
  • BUY x
  • HOLD
  • SELL x

The final line of output should contain the total profit that you have made compared to the initial capital.

Constraints

  • 2 \le D \le 100,000
  • 1 \le C, A \le 100,000
  • It is guaranteed that you will not have more than 10^9 dollars or rubber ducks at any point.

Subtasks

  • Subtask 1 (20%): D = 2
  • Subtask 2 (40%): D \le 1,000
  • Subtask 3 (40%): No additional constraints.

Sample Explanation

Sample 1

In this sample there are 4 days, you start with \$7 of capital, and will buy rubber ducks costing up to \$3.

  • On the first day ducks cost \$4 so you WAIT.
  • On the second day ducks cost \$2 (which is less than A = 3) so you BUY 3 ducks using \$6 and have \$1 remaining.
  • On the third day ducks cost \$2 which is not more than the price you last bought at, so you HOLD.
  • On the fourth and final day you sell all the ducks for \$7 each, and so have a total of \$22 dollars.

Since you started with a capital of \$7 you have made a total of 22 - 7 = \$15 of profit.

Sample 2

In this sample there are 5 days, you start with \$9 of capital, and will buy rubber ducks costing up to \$3.

  • On the first day ducks cost \$2 (which is less than A=3) so you BUY 4 ducks using \$8 and have \$1 remaining.
  • On the second day ducks cost \$1 which is not more than the price you last bought at, so you HOLD.
  • On the third day ducks cost \$3 which is more than the price you last bought at so you sell all your ducks for \$3 each, and so you have a total of \$13.
  • On the fourth day ducks cost \$4 so you WAIT.
  • On the fifth day ducks cost \$1. Although this is less than A=3, you do not buy any because you would not be able to sell them by the final day. Instead, you WAIT.

Since you started with a capital of \$9 you made a total of 13 - 9 = \$4 of profit.

  • Sample Input 1

    4 7 3
    4 2 2 7
    

    Sample Output 1

    WAIT
    BUY 3
    HOLD
    SELL 3
    15
    
  • Sample Input 2

    5 9 3
    2 1 3 4 1
    

    Sample Output 2

    BUY 4
    HOLD
    SELL 4
    WAIT
    WAIT
    4