Ritu tracked the price of 1 gram of gold for n days. She can buy once and sell once later (selling must happen after buying).
Find the maximum profit she can make. If no profit is possible, print 0.
Input Format
The first line has n.
The second line has n prices.
Output Format
Print the maximum profit.
Constraints
• 1 ≤ n ≤ 10^5
• 1 ≤ price ≤ 10^4
Examples
Example 1
Input
6
7 1 5 3 6 4
Output
5
Explanation Buy at 1 (day 2) and sell at 6 (day 5): profit 5.
Example 2
Input
5
7 6 4 3 1
Output
0
Explanation Prices only fall, so don't trade: 0.
Example 3
Explanation Buy at 1, sell at 2.
Acceptance
—
Accepted
0
Submissions
0