#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
inline long long read() {
  long long num = 0, fu = 1;
  char c = getchar();
  while (c != '-' && (c > '9' || c < '0')) c = getchar();
  if (c == '-') fu = -1, c = getchar();
  while (c >= '0' && c <= '9')
    num = (num << 3) + (num << 1) + (c ^ 48), c = getchar();
  return fu * num;
}
long long n, m, a[500010], p[500010], b[500010], f[500010], c[500010],
    bt[500010], ans = -inf, Sum;
inline long long lowbit(long long x) { return x & (-x); }
inline void update(long long x, long long k) {
  for (; x <= n; x += lowbit(x)) c[x] += k;
}
inline long long query(long long x) {
  long long res = 0;
  for (; x; x -= lowbit(x)) res += c[x];
  return res;
}
bool dfs(long long x, long long now) {
  if (now > n && x <= m) return 0;
  if (x > m) return 1;
  if (a[now] == b[x])
    dfs(x + 1, now + 1);
  else
    dfs(x, now + 1);
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= n; i++) p[i] = read(), Sum += p[i];
  m = read();
  for (long long i = 1; i <= m; i++) b[i] = read();
  if (!dfs(1, 1)) {
    puts("NO");
    return 0;
  }
  update(1, -inf);
  for (long long i = 1; i <= n; i++) {
    long long j = lower_bound(b + 1, b + 1 + m, a[i]) - b;
    if (j <= m && b[j] == a[i]) {
      f[i] = p[i] + query(b[j - 1]);
      long long tmp = query(a[i]) + (p[i] > 0 ? p[i] : 0);
      if (f[i] > tmp) update(a[i], f[i] - tmp), update(a[i] + 1, tmp - f[i]);
    }
    if (p[i] > 0) update(a[i], p[i]);
  }
  ans = query(b[m]);
  printf("YES\n%lld\n", Sum - ans);
  return 0;
}
