You are given a permutation p_1, p_2, ... , p_n (an array where each integer from 1 to n appears exactly once). The weight of the i-th element of this permutation is a_i.

At first, you separate your permutation into two non-empty sets — prefix and suffix. More formally, the first set contains elements p_1, p_2, ... , p_k, the second — p_{k+1}, p_{k+2}, ... , p_n, where 1 ≤ k < n.

After that, you may move elements between sets. The operation you are allowed to do is to choose some element of the first set and move it to the second set, or vice versa (move from the second set to the first). You have to pay a_i dollars to move the element p_i.

Your goal is to make it so that each element of the first set is less than each element of the second set. Note that if one of the sets is empty, this condition is met.

For example, if p = [3, 1, 2] and a = [7, 1, 4], then the optimal strategy is: separate p into two parts [3, 1] and [2] and then move the 2-element into first set (it costs 4). And if p = [3, 5, 1, 6, 2, 4], a = [9, 1, 9, 9, 1, 9], then the optimal strategy is: separate p into two parts [3, 5, 1] and [6, 2, 4], and then move the 2-element into first set (it costs 1), and 5-element into second set (it also costs 1).

Calculate the minimum number of dollars you have to spend.

Input

The first line contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the length of permutation.

The second line contains n integers p_1, p_2, ... , p_n (1 ≤ p_i ≤ n). It's guaranteed that this sequence contains each element from 1 to n exactly once.

The third line contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ 10^9).

Output

Print one integer — the minimum number of dollars you have to spend.

Examples

Input


3
3 1 2
7 1 4


Output


4


Input


4
2 4 1 3
5 9 8 3


Output


3


Input


6
3 5 1 6 2 4
9 1 9 9 1 9


Output


2
import java.io.*;
import java.util.*;

public class E {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] p = new int[n];
		int[] pos = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt()-1;
			pos[p[i]] = i;
		}
		long[] arr = new long[n];
		for(int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		long[] acc = new long[n+1];
		for(int i = 0; i < n; i++) {
			acc[i+1] = acc[i] + arr[pos[i]];
		}
		SegmentTree st = new SegmentTree(acc);
		long res = Long.MAX_VALUE;
		ArrayList<Long> ress = new ArrayList<>();
		for(int i = 0; i < n-1; i++) {
			st.update(0, p[i], arr[i]);
			st.update(p[i]+1, n, -arr[i]);
			long val = st.queryMin(0, n);
			ress.add(val);
			res = Math.min(res, val);
		}
		System.out.println(res);
		
	}
	
	static class SegmentTree { /* Author: Po-Chun Chiu */
		int size;
		private long[] min;
		private long[] lazy;

		public SegmentTree(long[] array){
			size = array.length;
			min = new long[array.length*4];
			lazy = new long[array.length*4];
			buildTree(array, 1, 0, size - 1);
		}

		private void buildTree(long[] array, int position, int front, int end){
			//Basis case for returning the elements itself
			if(front == end){
				min[position] = array[front];
				return;
			}
			//Building trees by dividing into two subtrees
			buildTree(array, position * 2, front, (front+end)/2);
			buildTree(array, position * 2 + 1, (front+end)/2 + 1, end);

			recalc(position, front, end);
		}

		private void recalc(int position, int front, int end) {
			min[position] = Math.min(getMin(position * 2), getMin(position * 2 + 1));
		}

		private long getMin(int position){
			return min[position] + lazy[position];
		}

		public long queryMin(int queryFront, int queryEnd) {
			return queryMin(1,0,size-1,queryFront,queryEnd);
		}

		private long queryMin(int position,int front,int end, int queryFront, int queryEnd){
			//Case for entirely inclusive
			if(front>=queryFront&&queryEnd>=end){
				return getMin(position);
			}
			//Case for entirely exclusive
			if(end<queryFront||queryEnd<front){
				return Long.MAX_VALUE;
			}
			propagate(position,front,end);
			long leftAns = queryMin(position*2,front,(front+end)/2,queryFront,queryEnd);
			long rightAns = queryMin(position*2+1,(front+end)/2+1,end,queryFront,queryEnd);
			return Math.min(leftAns, rightAns);
		}



		private void propagate(int position,int front, int end){
			lazy[position * 2] += lazy[position];
			lazy[position * 2 + 1] += lazy[position];
			min[position] = getMin(position);
			lazy[position] = 0;
			//Set the propagation to 0 so that it will not propagate the value again and again
		}

		public void update(int updateFront, int updateEnd, long delta){
			update(1, 0, size - 1, updateFront, updateEnd, delta);
		}

		private void update(int position, int front, int end, int updateFront, int updateEnd, long value){
			//Case for entirely inclusive
			if(front >= updateFront && updateEnd >= end){
				lazy[position]+=value;
				return;
			}
			//Case for entirely exclusive
			if(end < updateFront || updateEnd < front){
				return;
			}
			propagate(position, front, end);
			update(position * 2, front, (front+end)/2, updateFront, updateEnd, value);
			update(position * 2 + 1, (front+end)/2 + 1, end, updateFront, updateEnd, value);
			recalc(position, front, end);
		}
	}
	
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch(IOException e) {
				throw new RuntimeException(e);
			}
		}
	}


}
