798. Profit From Gold II

0

Easy

Given an array of stock prices, you can buy and sell the stock on different days. However, you can only hold one share at a time. Determine the maximum profit that can be achieved.

Input Format

The first line contains an integer n, representing the size of the array.

The next line contains n space-separated integers, representing the stock prices.

The next line contains n space-separated integers, representing the stock prices.

Output Format

Print a single integer representing the maximum possible profit.

Example

Input

6
7 1 5 3 6 4

Output

7

Constraints

1 <= N <= 10^6

0 <= A

0 <= A

_{i}<= 10^4Loading...

View Submissions

Console