You are given an integer array prices, where prices[i] is the price of the ith item in a shop.
The shop has a special discount. If you buy item i, you get a discount equal to prices[j], where j is the first index after i (so j > i) with prices[j] <= prices[i]. If there is no such j, item i gets no discount.
Return an array answer, where answer[i] is what you pay for item i after its discount.
Examples
Example 1
Input: prices = [8,4,6,2,3]
Output: [4,2,4,2,3]
Item 0 costs 8. The first price after it that is 8 or less is 4, so you pay 8 - 4 = 4. Item 1 costs 4: the next price, 6, is too high, so its discount is the 2 after that, and you pay 4 - 2 = 2. Item 2 pays 6 - 2 = 4. Items 3 and 4 have no price after them that is low enough, so they cost full price.
Example 2
Input: prices = [1,2,3,4,5]
Output: [1,2,3,4,5]
Prices only go up, so no item gets a discount.
Example 3
Input: prices = [10,1,1,6]
Output: [9,0,1,6]
Item 1's discount comes from item 2, which costs the same, so item 1 ends up free.
Example 4
Input: prices = [5,5,5]
Output: [0,0,5]
An equal price counts. Each item is discounted by the one right after it, except the last item, which has nothing after it.
Example 5
Input: prices = [6,9,7,3]
Output: [3,2,4,3]
For item 0, the 9 and the 7 are both more than 6, so its discount is the 3 at the end.
Constraints
1 <= prices.length <= 5001 <= prices[i] <= 1000