408411: GYM103115 E is the order a rabbit ??
Description
In a remote place, there is a rabbits market where rabbits can be bought and sold in every day. The trading rules in this market are as follows:
1.The market is available only in morning and afternoon in one day. And the rabbit transaction price may be different every day even different between morning and afternoon in a day.
2.It is prohibited that purchasing more than once in a day. And only one rabbit can be purchased at a time.
3. You can only sell once in a day, but you can sell rabbits unlimited quantities (provided that you have so many rabbits)
Mr.Cocktail has traded in this market for N days, suppose he has unlimited money to buy rabbits. Before the first day and after the last day, he has no rabbits. Now, in these N days, how much money did he earn the most?
InputThe first line contains a positive integer N, which means there are N days in total $$$(1 \leq n \leq 10^5)$$$
Next, there are N lines, each line contains two positive integers, representing the rabbit price in the morning and afternoon of the day $$$a_i,b_i(1 \leq a_i ,b_i \leq 10^9)$$$.
OutputOutput an integer on a line to indicate the answer.
ExamplesInput3 1 6 2 3 7 1Output
11Input
2 5 4 3 2Output
0Note
In example 1, a rabbit was purchased for $1 in the morning of the first day, and a rabbit was purchased for $2 in the afternoon of the second day. On the morning of the third day, the two rabbits were sold, a total profit of $11.
The price of the rabbit in sample 2 continues to decrease, and it is impossible to make money through buying and selling, so choose not to make any buying and selling, and output the answer 0.