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
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double eps = 1e-8;
const int INF32 = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const int mod = 30 + 7;
const unsigned long long mod2 = 1;
const int N = 2e5 + 5;
const int sz = (1 << 20);
long long yu1[N], yu2[N];
int a[N], yu3[N];
namespace data_struct {
class segment_tree {
 public:
  struct segment_node {
    int l, r;
    long long val, tag;
    void update(long long x) {
      tag += x;
      val += x;
    }
  };
  int nn;
  vector<segment_node> node;
  void pushup(int now) {
    node[now].val = min(node[now << 1].val, node[now << 1 | 1].val);
  }
  void pushdown(int now) {
    if (node[now].tag) {
      node[now << 1].update(node[now].tag);
      node[now << 1 | 1].update(node[now].tag);
      node[now].tag = 0;
    }
  }
  void build(int s, int t, int now = 1) {
    node[now].l = s, node[now].r = t;
    if (s == t) {
      node[now].val = yu1[s];
      return;
    }
    build(s, (s + t) >> 1, now << 1);
    build(((s + t) >> 1) + 1, t, now << 1 | 1);
    pushup(now);
  }
  void update(int s, int t, long long x, int now = 1) {
    if (s <= node[now].l && t >= node[now].r) {
      node[now].update(x);
      return;
    }
    pushdown(now);
    if (s <= ((node[now].l + node[now].r) >> 1)) update(s, t, x, now << 1);
    if (t > ((node[now].l + node[now].r) >> 1)) update(s, t, x, now << 1 | 1);
    pushup(now);
  }
  long long query(int s, int t, int now = 1) {
    if (s <= node[now].l && t >= node[now].r) {
      return node[now].val;
    }
    pushdown(now);
    long long ret = INF64;
    if (s <= ((node[now].l + node[now].r) >> 1)) {
      ret = query(s, t, now << 1);
    }
    if (t > ((node[now].l + node[now].r) >> 1)) {
      ret = min(ret, query(s, t, now << 1 | 1));
    }
    return ret;
  }
  explicit segment_tree(int nnn) {
    nn = nnn;
    node.resize(nn << 2 | 3);
    build(0, nn);
  }
};
}  // namespace data_struct
using namespace data_struct;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> yu3[i];
    yu1[a[i]] = yu3[i];
  }
  for (int i = 1; i <= n; ++i) {
    yu1[i] += yu1[i - 1];
  }
  segment_tree tree(n);
  long long ans = INF64;
  for (int i = 1; i < n; ++i) {
    tree.update(0, a[i] - 1, yu3[i]);
    tree.update(a[i], n, -yu3[i]);
    ans = min(ans, tree.query(0, n));
  }
  cout << ans << '\n';
  return 0;
}
