# The Queue

In the ABT ("Amortized Binary Trees") market, there are $n$ customers standing in a queue in positions from $1$ to $n$. The time needed for the cashier to serve the $i$-th customer is $t_{i}$.

The time that a customer needs to spend in a queue is the sum of times needed for the cashier to serve all the customers before them, added to the time needed to serve this customer. That is, in a queue of $3$ people with $t=[1,4,2]$ the times for each person are $1$, $1+4=5$ and $1+4+2=7$ respectively.

To minimize the sum of times needed for customers to stand in a queue before they get served, they agreed to be reordered. However, the $i$-th customer does not want to be moved more than $a_{i}$ positions back from their original position (however, they are fine with moving forward for any number of positions). What is the minimal sum of times these customers can reach?

## Input

The first line consists of one integer $n$ $(1≤n≤10_{5})$ — the number of customers in the queue.

The second line contains $n$ integers $t_{1},t_{2},…,t_{n}$ $(1≤t_{i}≤10_{9})$ — the amount of time needed for the cashier to serve each customer.

The third line contains $n$ integers $a_{1},a_{2},…,a_{n}$ $(0≤a_{i}≤n−i)$ — the maximum number of positions which each customer is agreed to move back.

## Output

In the only line, you need to output the minimal sum of waiting times that can be reached.

## Examples

## Note

In the first sample, there are two valid ways of rearranging the customers:

The $1$-st one, the $2$-nd one and the $3$-rd one (not moving anyone);

The $2$-nd one, the $1$-st one and the $3$-rd one;

The $2$-nd one, the $3$-rd one and the $1$-st one;

The $3$-rd one, the $2$-nd one and the $1$-st one.

The sums of times in these cases are:

$2+(2+4)+(2+4+1)=2+6+7=15$;

$4+(4+2)+(4+2+1)=17$;

$4+(4+1)+(4+1+2)=16$;

$1+(1+4)+(1+4+2)=13$.

As we can see, the best answer here is $13$. It can be shown that there no other possible arrangements of people in this queue.

In the second sample, both people can be at any position, so both their possible arrangements are valid and they give equal answers of $1+(1+1)=3$.

In the third sample, it can be shown that you cannot move any of the people, and their only valid arrangement is the initial one. The sum of times that people will be waiting in this queue is $1+3+6+10+15=35$.

## Scoring

($3$ points): $a_{i}=0$ for all $i$ $(1≤i≤n)$;

($7$ points): $n≤10$;

($8$ points): $n≤20$;

($6$ points): $a_{i}=n−i$ for all $i$ $(1≤i≤n)$;

($18$ points): $n≤4000$;

($13$ points): $t_{i}≤100$ for all $i$ $(1≤i≤n)$;

($20$ points): no additional constraints.