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 A {

	static int n;

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		n = sc.nextInt();
		int p[] = new int[n], c[] = new int[n + 1];
		for (int i = 0; i < n; i++)
			p[i] = sc.nextInt();
		for (int i = 0; i < n; i++)
			c[p[i]] = sc.nextInt();
		SegmentTree st = new SegmentTree();
		for (int i = 1; i <= n; i++)
			st.update(i, n, c[i]);
		long ans = Long.MAX_VALUE;
		for (int k = 0; k + 1 < n; k++) {
			st.update(0, p[k] - 1, c[p[k]]);
			st.update(p[k], n, -c[p[k]]);

			ans = Math.min(ans, st.query(0, n));

		}
		System.out.println(ans);

		out.close();

	}

	static class SegmentTree {
		long[] min, lazy;

		SegmentTree() {
			min = new long[4 * n];
			lazy = new long[4 * n];
		}

		void update(int l, int r, int v) {
			update(1, 0, n, l, r, v);
		}

		void update(int node, int tl, int tr, int l, int r, int v) {
			if (tr < l || r < tl)
				return;
			if (tl >= l && tr <= r) {
				lazy[node] += v;
				min[node] += v;
				return;
			}
			int mid = tl + tr >> 1, left = node << 1, right = left | 1;
			propagate(node);
			update(left, tl, mid, l, r, v);
			update(right, mid + 1, tr, l, r, v);
			min[node] = Math.min(min[left], min[right]);
		}

		long query(int l, int r) {
			return query(1, 0, n, l, r);

		}

		long query(int node, int tl, int tr, int l, int r) {
			if (r < tl || tr < l)
				return Long.MAX_VALUE;
			if (tl >= l && tr <= r)
				return min[node];
			int mid = tl + tr >> 1, left = node << 1, right = left | 1;

			propagate(node);
			return Math.min(query(left, tl, mid, l, r), query(right, mid + 1, tr, l, r));
		}

		private void propagate(int node) {
			// TODO Auto-generated method stub
			int child = node << 1;
			lazy[child] += lazy[node];
			min[child] += lazy[node];
			child++;
			lazy[child] += lazy[node];
			min[child] += lazy[node];
			lazy[node] = 0;
		}
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}