Problem: Let's denote the following function f. This function takes an array a of length n and returns an array. Initially the result is an empty array. For each integer i from 1 to n we add element a_i to the end of the resulting array if it is greater than all previous elements (more formally, if a_i > max_{1 ≤ j < i}a_j). Some examples of the function f:

  1. if a = [3, 1, 2, 7, 7, 3, 6, 7, 8] then f(a) = [3, 7, 8]; 
  2. if a = [1] then f(a) = [1]; 
  3. if a = [4, 1, 1, 2, 3] then f(a) = [4]; 
  4. if a = [1, 3, 1, 2, 6, 8, 7, 7, 4, 11, 10] then f(a) = [1, 3, 6, 8, 11]. 



You are given two arrays: array a_1, a_2, ... , a_n and array b_1, b_2, ... , b_m. You can delete some elements of array a (possibly zero). To delete the element a_i, you have to pay p_i coins (the value of p_i can be negative, then you get |p_i| coins, if you delete this element). Calculate the minimum number of coins (possibly negative) you have to spend for fulfilling equality f(a) = b.

Input

The first line contains one integer n (1 ≤ n ≤ 5 ⋅ 10^5) — the length of array a.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the array a.

The third line contains n integers p_1, p_2, ..., p_n (|p_i| ≤ 10^9) — the array p.

The fourth line contains one integer m (1 ≤ m ≤ n) — the length of array b.

The fifth line contains m integers b_1, b_2, ..., b_m (1 ≤ b_i ≤ n, b_{i-1} < b_i) — the array b.

Output

If the answer exists, in the first line print YES. In the second line, print the minimum number of coins you have to spend for fulfilling equality f(a) = b.

Otherwise in only line print NO.

Examples

Input


11
4 1 3 3 7 8 7 9 10 7 11
3 5 0 -2 5 3 6 7 8 2 4
3
3 7 10


Output


YES
20


Input


6
2 1 5 3 6 5
3 -9 0 16 22 -14
4
2 3 5 6


Output


NO

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct segTree {
 private:
  int n;
  vector<T> mx, mn, lazySet, sum, lazyAdd;
  void update(int i) {
    mx[i] = max(mx[2 * i], mx[2 * i + 1]);
    mn[i] = min(mn[2 * i], mn[2 * i + 1]);
    sum[i] = sum[2 * i] + sum[2 * i + 1];
  }
  void init(int l, int r, int i, vector<int> &vals) {
    if (l == r) {
      mn[i] = mx[i] = sum[i] = vals[l];
      return;
    }
    int m = (l + r) / 2;
    init(l, m, 2 * i, vals);
    init(m + 1, r, 2 * i + 1, vals);
    update(i);
  }
  void prop(int i, int l, int m, int r) {
    if (lazySet[i] != numeric_limits<T>::max()) {
      mx[2 * i] = mx[2 * i + 1] = mn[2 * i] = mn[2 * i + 1] = lazySet[2 * i] =
          lazySet[2 * i + 1] = lazySet[i];
      sum[2 * i] = (long long)(m - l + 1) * lazySet[i];
      sum[2 * i + 1] = (long long)(r - m) * lazySet[i];
      lazyAdd[2 * i] = 0;
      lazyAdd[2 * i + 1] = 0;
      lazySet[i] = numeric_limits<T>::max();
    }
    if (lazyAdd[i]) {
      mx[2 * i] += lazyAdd[i];
      mx[2 * i + 1] += lazyAdd[i];
      mn[2 * i] += lazyAdd[i];
      mn[2 * i + 1] += lazyAdd[i];
      sum[2 * i] += (long long)(m - l + 1) * lazyAdd[i];
      sum[2 * i + 1] += (long long)(r - m) * lazyAdd[i];
      lazyAdd[2 * i] += lazyAdd[i];
      lazyAdd[2 * i + 1] += lazyAdd[i];
      lazyAdd[i] = 0;
    }
  }
  void setSingle(int pos, int x, int l, int r, int i) {
    if (l == r) {
      mx[i] = x;
      mn[i] = x;
      sum[i] = x;
      return;
    }
    int m = (l + r) / 2;
    prop(i, l, m, r);
    if (pos <= m)
      setSingle(pos, x, l, m, 2 * i);
    else
      setSingle(pos, x, m + 1, r, 2 * i + 1);
    update(i);
  }
  void addSingle(int pos, int x, int l, int r, int i) {
    if (l == r) {
      mx[i] += x;
      mn[i] += x;
      sum[i] += x;
      return;
    }
    int m = (l + r) / 2;
    prop(i, l, m, r);
    if (pos <= m)
      addSingle(pos, x, l, m, 2 * i);
    else
      addSingle(pos, x, m + 1, r, 2 * i + 1);
    update(i);
  }
  void setRange(int qs, int qe, int x, int l, int r, int i) {
    if (qs > r || qe < l) return;
    if (qs <= l && qe >= r) {
      lazyAdd[i] = 0;
      mx[i] = mn[i] = lazySet[i] = x;
      sum[i] = (long long)(r - l + 1) * x;
      return;
    }
    int m = (l + r) / 2;
    prop(i, l, m, r);
    setRange(qs, qe, x, l, m, 2 * i);
    setRange(qs, qe, x, m + 1, r, 2 * i + 1);
    update(i);
  }
  void addRange(int qs, int qe, int x, int l, int r, int i) {
    if (qs > r || qe < l) return;
    if (qs <= l && qe >= r) {
      lazyAdd[i] += x;
      mx[i] += x;
      mn[i] += x;
      sum[i] += (long long)(r - l + 1) * x;
      return;
    }
    int m = (l + r) / 2;
    prop(i, l, m, r);
    addRange(qs, qe, x, l, m, 2 * i);
    addRange(qs, qe, x, m + 1, r, 2 * i + 1);
    update(i);
  }
  int getMx(int qs, int qe, int l, int r, int i) {
    if (qs > r || qe < l) return numeric_limits<T>::min();
    if (qs <= l && qe >= r) return mx[i];
    int m = (l + r) / 2;
    prop(i, l, m, r);
    return max(getMx(qs, qe, l, m, 2 * i), getMx(qs, qe, m + 1, r, 2 * i + 1));
  }
  int getMn(int qs, int qe, int l, int r, int i) {
    if (qs > r || qe < l) return numeric_limits<T>::max();
    if (qs <= l && qe >= r) return mn[i];
    int m = (l + r) / 2;
    prop(i, l, m, r);
    return min(getMn(qs, qe, l, m, 2 * i), getMn(qs, qe, m + 1, r, 2 * i + 1));
  }
  long long getSum(int qs, int qe, int l, int r, int i) {
    if (qs > r || qe < l) return 0;
    if (qs <= l && qe >= r) return sum[i];
    int m = (l + r) / 2;
    prop(i, l, m, r);
    return getSum(qs, qe, l, m, 2 * i) + getSum(qs, qe, m + 1, r, 2 * i + 1);
  }

 public:
  void init(int N) {
    n = N;
    int pwr = 1;
    while (pwr < 2 * n) pwr *= 2;
    mx.resize(pwr);
    mn.resize(pwr);
    sum.resize(pwr);
    lazyAdd.resize(pwr);
    lazySet.resize(pwr);
    for (int i = 0; i < pwr; i++)
      mx[i] = mn[i] = sum[i] = lazyAdd[i] = 0,
      lazySet[i] = numeric_limits<T>::max();
  }
  void init(vector<int> &vals) {
    init(vals.size());
    init(0, n - 1, 1, vals);
  }
  void singleSet(int pos, int x) { setSingle(pos, x, 0, n - 1, 1); }
  void singleAdd(int pos, int x) { addSingle(pos, x, 0, n - 1, 1); }
  void rangeSet(int qs, int qe, int x) { setRange(qs, qe, x, 0, n - 1, 1); }
  void rangeAdd(int qs, int qe, int x) { addRange(qs, qe, x, 0, n - 1, 1); }
  int getMax(int qs, int qe) { return getMx(qs, qe, 0, n - 1, 1); }
  int getMin(int qs, int qe) { return getMn(qs, qe, 0, n - 1, 1); }
  long long getSum(int qs, int qe) { return getSum(qs, qe, 0, n - 1, 1); }
};
segTree<long long> svi, neg;
const long long oo = LLONG_MAX / 2;
int main() {
  int n;
  scanf("%i", &n);
  vector<int> a(n + 2), pr(n + 2), b;
  for (int i = 1; i <= n; i++) scanf("%i", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%i", &pr[i]);
  int m;
  scanf("%i", &m);
  b.resize(m + 1);
  vector<int> pos(n + 1, -1);
  for (int i = 1; i <= m; i++) scanf("%i", &b[i]), pos[b[i]] = i;
  a[n + 1] = b[m];
  vector<int> last(n + 1, -1);
  last[0] = 0;
  vector<long long> dp(n + 2), veci(n + 2), manji(n + 2);
  svi.init(n + 1);
  neg.init(n + 1);
  for (int i = 1; i <= n + 1; i++) {
    dp[i] = oo;
    if (pos[a[i]] == -1) {
      svi.singleAdd(a[i], pr[i]);
      if (pr[i] < 0) neg.singleAdd(a[i], pr[i]);
      continue;
    }
    veci[i] = svi.getSum(a[i] + 1, n);
    manji[i] = neg.getSum(1, a[i] - 1);
    int p = pos[a[i]];
    if (last[b[p]] != -1) {
      int g = last[b[p]];
      long long tada = dp[g] + veci[i] - veci[g] + manji[i] - manji[g];
      if (pr[i] < 0) tada += pr[i];
      dp[i] = min(dp[i], tada);
    }
    if (i != n + 1 && last[b[p - 1]] != -1) {
      int g = last[b[p - 1]];
      int koji = b[p - 1];
      long long tada = dp[g] + svi.getSum(koji + 1, n) - veci[g] +
                       neg.getSum(1, koji - 1) - manji[g];
      dp[i] = min(dp[i], tada);
    }
    svi.singleAdd(a[i], pr[i]);
    if (pr[i] < 0) neg.singleAdd(a[i], pr[i]);
    last[a[i]] = i;
  }
  if (dp[n + 1] >= oo / 2)
    printf("NO\n");
  else
    printf("YES\n%lld\n", dp[n + 1]);
  return 0;
}