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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            SegmentTree seg = new SegmentTree(N + 1);
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = in.nextInt();
            }
            int[] cost = new int[N];
            for (int i = 0; i < N; i++) {
                cost[i] = in.nextInt();
            }
            seg.add(0, arr[0] - 1, cost[0]);
            for (int i = 1; i < N; i++) {
                seg.add(arr[i], N, cost[i]);
            }
            long res = Long.MAX_VALUE;
            for (int i = 1; i < N; i++) {
                res = Math.min(res, seg.query(0, N).min);
                seg.add(arr[i], N, -cost[i]);
                seg.add(0, arr[i] - 1, cost[i]);
            }
            out.println(res);
        }

        public class SegmentTree {
            Node[] tree;
            int size = 0;

            public Node none() {
                //return a node that will do nothing while merging: ex. Infinity for min query, -Infinity for max query, 0 for sum
                Node res = new Node();
                res.min = Long.MAX_VALUE;
                return res;
            }

            public SegmentTree(int N) {
                tree = new Node[4 * N];
                size = N;
                for (int i = 0; i < 4 * N; i++) {
                    tree[i] = new Node();
                }
            }

            Node combine(Node a, Node b) {
                //change when doing different operations
                Node res = new Node();
                res.min = Math.min(a.min, b.min);
                return res;
            }

            void push(int n, int l, int r) {
                int m = (l + r) / 2;
                tree[2 * n].update(l, m, tree[n].lzy);
                tree[2 * n + 1].update(m + 1, r, tree[n].lzy);
                tree[n].lzy = 0;
            }

            public Node query(int l, int r) {
                return queryUtil(1, 0, size - 1, l, r);
            }

            public Node queryUtil(int n, int tl, int tr, int l, int r) {
                //node number, cur range of node, cur range of query
                if (l > r) {
                    return none();
                }
                if (tl == l && tr == r) {
                    return tree[n];
                }
                int tm = (tl + tr) / 2;
                push(n, tl, tr);
                return combine(queryUtil(2 * n, tl, tm, l, Math.min(r, tm)), queryUtil(2 * n + 1, tm + 1, tr, Math.max(tm + 1, l), r));
            }

            public void add(int l, int r, long val) {
                //change query, not assignment
                addUtil(1, 0, size - 1, l, r, val);
            }

            public void addUtil(int n, int tl, int tr, int l, int r, long val) {
                if (l > r) {
                    return;
                }
                if (tl == l && tr == r) {
                    tree[n].update(l, r, val);
                } else {
                    push(n, tl, tr);
                    int tm = (tl + tr) / 2;
                    addUtil(2 * n, tl, tm, l, Math.min(tm, r), val);
                    addUtil(2 * n + 1, tm + 1, tr, Math.max(l, tm + 1), r, val);
                    tree[n] = combine(tree[2 * n], tree[2 * n + 1]);
                }
            }

            class Node {
                long min = 0;
                long lzy = 0;

                void update(int l, int r, long val) {
                    min += val;
                    lzy += val;
                }

            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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());
        }

    }
}

