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 JAVA):

Solution:
import java.util.*;
import java.io.*;

public class F {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		int[] A = new int[n];
		int[][] At = new int[n][2];
		StringTokenizer token = new StringTokenizer(in.readLine());
		for (int a = 0; a < n; a++) {
			A[a] = Integer.parseInt(token.nextToken());
			At[a][0] = A[a];
			At[a][1] = a;
		}
		int[] P = new int[n];
		token = new StringTokenizer(in.readLine());
		for (int a = 0; a < n; a++)
			P[a] = Integer.parseInt(token.nextToken());
		int m = Integer.parseInt(in.readLine());
		int[] B = new int[m];
		token = new StringTokenizer(in.readLine());
		for (int a = 0; a < m; a++)
			B[a] = Integer.parseInt(token.nextToken());
		HashMap<Integer, Integer> valtoid = new HashMap<Integer, Integer>(m * 4 / 3 + 1);
		for (int a = 0; a < m; a++)
			valtoid.put(B[a], a);
		ArrayList<Integer>[] levels = new ArrayList[m];
		for (int a = 0; a < m; a++)
			levels[a] = new ArrayList<Integer>();
		for (int a = 0; a < n; a++)
			if (valtoid.containsKey(A[a]))
				levels[valtoid.get(A[a])].add(a);
		long[] dp = new long[n];
		Arrays.fill(dp, Long.MIN_VALUE);
		for (int a = 0; a < levels[0].size(); a++)
			dp[levels[0].get(a)] = P[levels[0].get(a)];
		SegmentTree seg = new SegmentTree(n);
		int idx = 0;
		Arrays.sort(At, (a, b) -> a[0] - b[0]);
		for (int a = 1; a < levels.length; a++) {
			while (idx != n && At[idx][0] <= B[a - 1]) {
				if (P[At[idx][1]] > 0)
					seg.updateValue(n, At[idx][1], P[At[idx][1]]);
				idx++;
			}
			int lower = 1;
			int higher = 0;
			if (levels[a].size() == 0)
				break;
			if (levels[a - 1].size() == 0)
				break;
			long max = dp[levels[a - 1].get(0)];
			int lastid = levels[a - 1].get(0);
			while (lower < levels[a - 1].size() && higher < levels[a].size()) {
				if (levels[a - 1].get(lower) < levels[a].get(higher)) {
					max = Math.max(
							max + seg.getSum(n, lastid + 1, levels[a - 1].get(lower)),
							dp[levels[a - 1].get(lower)]);
					lastid = levels[a - 1].get(lower);
					lower++;
				} else {
					if (levels[a - 1].get(0) > levels[a].get(higher)) {
						higher++;
						continue;
					}
					dp[levels[a].get(higher)] = max + seg.getSum(n, lastid + 1, levels[a].get(higher) - 1)
							+ P[levels[a].get(higher)];
					higher++;
				}
			}
			while (higher < levels[a].size()) {
				if (levels[a - 1].get(0) > levels[a].get(higher)) {
					higher++;
					continue;
				}
				dp[levels[a].get(higher)] = max + seg.getSum(n, lastid + 1, levels[a].get(higher) - 1)
						+ P[levels[a].get(higher)];
				higher++;
			}
		}
		int eee = 0;
		for (int a = 0; a < n; a++)
			if (eee != m && A[a] == B[eee])
				eee++;
		long answer = Long.MIN_VALUE;
		if (eee == m) {
			while (idx != n && At[idx][0] <= B[m - 1]) {
				if (P[At[idx][1]] > 0)
					seg.updateValue(n, At[idx][1], P[At[idx][1]]);
				idx++;
			}
			for (int a = 0; a < levels[levels.length - 1].size(); a++) {
				answer = Math.max(answer, dp[levels[levels.length - 1].get(a)]
						+ seg.getSum(n, levels[levels.length - 1].get(a) + 1, n - 1));
			}
			long total = 0;
			for (int a = 0; a < n; a++)
				total += P[a];
			System.out.println("YES");
			System.out.println(total - answer);
		} else
			System.out.println("NO");
	}

	static class SegmentTree {
		long st[];

		SegmentTree(int n) {
			int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
			int max_size = 2 * (int) Math.pow(2, x) - 1;
			st = new long[max_size];
		}

		int getMid(int s, int e) {
			return s + (e - s) / 2;
		}

		long getSumUtil(int ss, int se, int qs, int qe, int si) {
			if (qs <= ss && qe >= se)
				return st[si];
			if (se < qs || ss > qe)
				return 0;
			int mid = getMid(ss, se);
			return getSumUtil(ss, mid, qs, qe, 2 * si + 1) + getSumUtil(mid + 1, se, qs, qe, 2 * si + 2);
		}

		void updateValueUtil(int ss, int se, int i, int diff, int si) {
			if (i < ss || i > se)
				return;
			st[si] = st[si] + diff;
			if (se != ss) {
				int mid = getMid(ss, se);
				updateValueUtil(ss, mid, i, diff, 2 * si + 1);
				updateValueUtil(mid + 1, se, i, diff, 2 * si + 2);
			}
		}

		void updateValue(int n, int i, int diff) {
			if (i < 0 || i > n - 1) {
				return;
			}
			updateValueUtil(0, n - 1, i, diff, 0);
		}

		long getSum(int n, int qs, int qe) {
			if (qs < 0 || qe > n - 1 || qs > qe) {
				return 0;
			}
			return getSumUtil(0, n - 1, qs, qe, 0);
		}
	}
}