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;
const int N = 5e5 + 10;
const int K = 23;
const long long INF = 1e18;
int id[N], a[N], b[N], w[N];
int n, m;
vector<int> pos[N];
long long dp[N];
int ls[N * K], rs[N * K], rootcnt = 0;
long long vs[N * K];
void copy(int root, int newroot) {
  ls[newroot] = ls[root];
  rs[newroot] = rs[root];
  vs[newroot] = vs[root];
}
void updates(int root, int& newroot, int l, int r, int pos, int v) {
  newroot = ++rootcnt;
  copy(root, newroot);
  vs[newroot] += v;
  if (l == r || v == 0) return;
  int m = (l + r) >> 1;
  if (pos <= m)
    updates(ls[root], ls[newroot], l, m, pos, v);
  else
    updates(rs[root], rs[newroot], m + 1, r, pos, v);
}
long long querys(int lt, int rt, int l, int r, int a, int b) {
  if (l == a && r == b) {
    return vs[rt] - vs[lt];
  }
  int m = (l + r) >> 1;
  if (b <= m)
    return querys(ls[lt], ls[rt], l, m, a, b);
  else if (a > m)
    return querys(rs[lt], rs[rt], m + 1, r, a, b);
  else {
    return querys(ls[lt], ls[rt], l, m, a, m) +
           querys(rs[lt], rs[rt], m + 1, r, m + 1, b);
  }
}
long long val[N << 2];
long long tag[N << 2];
void build(int root, int l, int r) {
  val[root] = -INF;
  tag[root] = 0;
  if (l == r) return;
  int m = (l + r) >> 1;
  build((root << 1), l, m);
  build((root << 1 | 1), m + 1, r);
}
void pushdown(int root) {
  long long c = tag[root];
  tag[root] = 0;
  val[(root << 1)] += c;
  tag[(root << 1)] += c;
  val[(root << 1 | 1)] += c;
  tag[(root << 1 | 1)] += c;
}
void setv(int root, int l, int r, int pos, long long v) {
  if (l == r) {
    val[root] = v;
    return;
  }
  pushdown(root);
  int m = (l + r) >> 1;
  if (pos <= m)
    setv((root << 1), l, m, pos, v);
  else
    setv((root << 1 | 1), m + 1, r, pos, v);
  val[root] = max(val[(root << 1)], val[(root << 1 | 1)]);
}
void update(int root, int l, int r, int a, int b, long long v) {
  if (v == 0) return;
  if (a > b) return;
  if (l == a && r == b) {
    val[root] += v;
    tag[root] += v;
    return;
  }
  pushdown(root);
  int m = (l + r) >> 1;
  if (b <= m)
    update((root << 1), l, m, a, b, v);
  else if (a > m)
    update((root << 1 | 1), m + 1, r, a, b, v);
  else {
    update((root << 1), l, m, a, m, v);
    update((root << 1 | 1), m + 1, r, m + 1, b, v);
  }
  val[root] = max(val[(root << 1)], val[(root << 1 | 1)]);
}
long long query(int root, int l, int r, int a, int b) {
  if (a > b) return -INF;
  if (l == a && r == b) return val[root];
  pushdown(root);
  int m = (l + r) >> 1;
  if (b <= m)
    return query((root << 1), l, m, a, b);
  else if (a > m)
    return query((root << 1 | 1), m + 1, r, a, b);
  else
    return max(query((root << 1), l, m, a, m),
               query((root << 1 | 1), m + 1, r, m + 1, b));
}
bool hasAns() {
  int len = 0;
  for (int i = 1; i <= n && len < m; i++) {
    if (a[i] == b[len + 1]) len++;
  }
  return len == m;
}
int root[N];
long long lessSum(int l, int r, int v) {
  if (l > r || v <= 0) return 0;
  return querys(root[l - 1], root[r], 1, n, 1, v);
}
void solve() {
  scanf("%d", &n);
  root[0] = 0;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) {
    scanf("%d", w + i);
    updates(root[i - 1], root[i], 1, n, a[i], max(0, w[i]));
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d", b + i), id[b[i]] = i;
  for (int i = 1; i <= n; i++) {
    if (id[a[i]]) pos[id[a[i]]].push_back(i);
  }
  if (!hasAns()) {
    printf("NO\n");
    return;
  }
  printf("YES\n");
  for (int i = 1; i <= n; i++) dp[i] = -INF;
  build(1, 1, n);
  for (auto p : pos[m]) {
    dp[p] = lessSum(p + 1, n, b[m]) + w[p];
    setv(1, 1, n, p, dp[p]);
  }
  for (int i = m - 1; i >= 1; i--) {
    vector<int> vec;
    for (auto j : pos[i + 1]) vec.push_back(j);
    for (auto j : pos[i]) vec.push_back(j);
    sort(vec.begin(), vec.end());
    for (int j = (int)vec.size() - 2; j >= 0; j--) {
      update(1, 1, n, vec[j + 1], n, lessSum(vec[j] + 1, vec[j + 1] - 1, b[i]));
      if (a[vec[j]] == b[i]) {
        dp[vec[j]] = query(1, 1, n, vec[j + 1], n) + w[vec[j]];
        if (w[vec[j]] > 0) {
          update(1, 1, n, vec[j + 1], n, w[vec[j]]);
        }
      }
    }
    for (int j = (int)vec.size() - 2; j >= 0; j--) {
      update(1, 1, n, vec[j + 1], n,
             -lessSum(vec[j] + 1, vec[j + 1] - 1, b[i]));
      if (a[vec[j]] == b[i]) {
        if (w[vec[j]] > 0) {
          update(1, 1, n, vec[j + 1], n, -w[vec[j]]);
        }
      }
    }
    for (auto j : pos[i + 1]) {
      setv(1, 1, n, j, -INF);
    }
    assert(val[1] == -INF);
    for (auto j : pos[i]) {
      setv(1, 1, n, j, dp[j]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += w[i];
  ans -= val[1];
  printf("%lld\n", ans);
}
int main() {
  solve();
  return 0;
}