#P1108. Buy Low, Buy Lower

    ID: 13136 Type: Default 1000ms 256MiB

Buy Low, Buy Lower

Buy Low, Buy Lower

This problem is inspired by the adage "Buy low; buy lower" from the stock market. To be a great investor, you must adhere to the following advice: every time you buy the stock, the price must be strictly lower than the price at which you made your previous purchase. The goal is to buy as many times as possible under this constraint.

You are given the prices of a stock over n days. You can choose on which days to buy the stock, but if you decide to buy on day i after having bought at a previous price p, then the price on day i must satisfy:

pnew<p  .p_{\text{new}} < p \;.

For example, consider the following stock price list:

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline \textsf{Date} & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ \hline \textsf{Price} & 68 & 69 & 54 & 64 & 68 & 64 & 70 & 67 & 78 & 62 & 98 & 87 \\ \hline \end{array} $$

The best strategy in this example allows you to buy up to 4 times. One valid purchasing plan is:

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|}\hline \textsf{Date} & 2 & 5 & 6 & 10 \\ \hline \textsf{Price} & 69 & 68 & 64 & 62 \\ \hline \end{array} $$

Your task is to determine the maximum number of times you can purchase the stock while obeying the "buy lower" rule.

inputFormat

The first line contains an integer n representing the number of days. The second line contains n integers representing the stock prices on each day.

outputFormat

Output a single integer, the maximum number of times you can buy the stock while following the rule that each new purchase must be at a strictly lower price than the last purchase.

sample

12
68 69 54 64 68 64 70 67 78 62 98 87
4