VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications.

The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of i-th category within t_i seconds. 

What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can't remove publications recommended by the batch algorithm.

Input

The first line of input consists of single integer n — the number of news categories (1 ≤ n ≤ 200 000).

The second line of input consists of n integers a_i — the number of publications of i-th category selected by the batch algorithm (1 ≤ a_i ≤ 10^9).

The third line of input consists of n integers t_i — time it takes for targeted algorithm to find one new publication of category i (1 ≤ t_i ≤ 10^5).

Output

Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.

Examples

Input


5
3 7 9 7 8
5 2 5 7 5


Output


6


Input


5
1 2 3 4 5
1 1 1 1 1


Output


0

Note

In the first example, it is possible to find three publications of the second type, which will take 6 seconds.

In the second example, all news categories contain a different number of publications.
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        # k+1ではなくkでは？
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

N, = map(int, input().split())
P = list(map(int, input().split()))
T = list(map(int, input().split()))

TT = [(t, i) for i, t in enumerate(T)]
TT.sort(key=lambda x:x[0])
#print(TT)
j2t = dict()
i2j = dict()
for j, (t, i) in enumerate(TT):
#    print(j+1, t, i)
    j2t[j+1] = t
    i2j[i] = j+1

X = list(zip(P, T))
X = [(p, t, i) for i, (p, t) in enumerate(X)]
X.sort(key=lambda x:x[0])


MM = 2*10**5+1
segtree = SegTree([0]*MM, MM, -1, max)
#print(X)
X.append((10**18, 10**8, N+1))
b = None
ss = 0
ans = 0
for p, t, i in X:
    if b is not None:
        for _ in range(p-b):
            tj = segtree.query(0, MM)
            if tj == 0:
                break
            segtree.update(tj, 0)
#            print("i, j2t[tj], ss, tj", i, j2t[tj], ss, tj)
            ss -= j2t[tj]
            ans += ss
#            print(i, ss)
    if p == 10**18:
        break
    ss += t
#    print(i, ss, i2j[i], j2t[i2j[i]])
    segtree.update(i2j[i], i2j[i])
    b = p
print(ans)
