cswork / OAOpen practice workspace

AmazonOA #225

Get Minimal Cost

Estimated HardJudge-ready

Topics (AI-labelled)Stacks & HeapsGreedy

Each product's size can only increase, and each unit of increase costs that product's cost. In the end all product sizes must be distinct; find the minimum total cost. Products cannot be removed.

Input

The first line contains n, the second line the sizes, and the third line the unit costs. 1≤n≤200000, 1≤size≤10^9, 1≤cost≤10000.

Output

Output a single integer, the answer.

Example 1

Input:

5
3 7 9 7 8
5 2 5 7 5

Output:

6

Example 2

Input:

4
2 3 3 2
2 4 5 1

Output:

7

Example 3

Input:

2
1 1
1 10

Output:

1

Example notes

The answers are 6, 7 and 1. In the second example the 3 with cost 4 rises to 4 and the 2 with cost 1 rises to 5, total 7.

Editorial

Loading solution…