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:
/**
 * @author derrick20
 */

import java.io.*;
import java.util.*;
/*
30
1 2 1 5 1 2 3 1 3 1 3 5 3 5 3 5 1 3 5 7 3 8 3 2 1 6 20 5 3 5
-20 -30 100 -3 2 -50 5 -1 -6 4 -3 10 -1 -3 -5 -2 7 5 3 3 6 2 1 4 -3 50 3 100 3 20
5
1 2 3 5 7

7
1 2 2 3 3 5 7
-20 -30 -50 5 -3 10 -3
5
1 2 3 5 7
 */
public class StrangeFunction {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        int[] arr = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            arr[i] = sc.nextInt();
        }
        int[] posCosts = new int[N + 1];
        long[] negPrefix = new long[N + 1];
        BIT full = new BIT(new int[N + 1]);
        for (int i = 1; i <= N; i++) {
            int cost = sc.nextInt();
            negPrefix[i] = negPrefix[i - 1];
            if (cost > 0) {
                posCosts[i] = cost;
                full.update(arr[i], cost);
            }
            else {
                negPrefix[i] += cost;
            }
        }

        int M = sc.nextInt();
        int[] seq = new int[M + 1];
        int[] valToIdx = new int[N + 1]; // max val is N
        Arrays.fill(valToIdx, -1); // note that many values aren't part of the seq
        valToIdx[0] = 0;
        // seq[0] = 0, valToIdx[0] = 0. Add this padding as a base case
        for (int i = 1; i <= M; i++) {
            seq[i] = sc.nextInt();
            valToIdx[seq[i]] = i;
        }
        // Maintain the current topography of the numbers with the bit to
        // sum costs higher than a number (the cost to force that number into
        // the array)
        BIT bit = new BIT(new int[N + 1]);
        long[] dpCost = new long[M + 1];
        // dp[idx] = minimum cost at the current state of our sweep,
        // to make the array turn into a sequence ending with the val at idx
        int[] dpPos = new int[M + 1];
        Arrays.fill(dpPos, -1);
        dpPos[0] = 0;
        // dpPos[idx] = the position that the associated minimum cost in dpCost[idx]
        // went up to WITHIN THE ARRAY.
        for (int i = 1; i <= N; i++) {
            int val = arr[i];
            if (valToIdx[val] != -1) {
                // this is part of the sequence, so we track it in our DP
                int idx = valToIdx[val];
                int prevVal = seq[idx - 1]; // we need to help out the old value
                int prevPos = dpPos[idx - 1];
                // if prevPos is -1, then we didn't get to that state, so we
                // most certainly cannot get to this state!
                if (prevPos != -1) {
                    // Never got this far before, so let's just take what we can get
                    long cost = bit.query(prevVal + 1, val);
                    // we need to delete anything added so far so that the
                    // space between the previous value and us is CLEANSED
                    // OF NUMBERS THAT ONLY AFFECT US. Hence, in between the old val and our val
                    // [prevVal + 1, val]. We will aggregate the costs based on position in sequence
                    long free = negPrefix[i - 1] - negPrefix[prevPos];
                    // also, we can collect all the free negative values STRICTLY
                    // between the last pos and i. That is, [prevPos + 1, i - 1]
                    long buildCost = dpCost[idx - 1] + cost + free;

                    if (dpPos[idx] == -1) {
                        if (idx <= M - 1) {
                            // We can always build on top of some previous state
                            dpCost[idx] = buildCost;
                            dpPos[idx] = i;
                        }
                        else {
                            // we need to find the cost from here to the end!
                            long newCost = bit.query(prevVal + 1, val) + full.query(val + 1, N);
                            long fullFree = negPrefix[N] - negPrefix[i] + negPrefix[i - 1] - negPrefix[prevPos];
                            long fullBuildCost  = dpCost[idx - 1] + newCost + fullFree;
                            dpCost[idx] = fullBuildCost;
                            dpPos[idx] = i;
                        }
                    }
                    else if (dpPos[idx] != -1) {
                        if (idx <= M - 1) {
                            // however, if this much of the sequence has been achieved
                            // before, we might try extending that!
                            // In fact, extending might be much better than building,
                            int nextVal = seq[idx + 1];
                            // If we aren't the last (Mth idx), then we sum everything up to the next
                            // otherwise, we just go until N (the max possible)
                            int oldPos = dpPos[idx];
                            long extendFree = negPrefix[i] - negPrefix[oldPos]; // it has to go THROUGH i too!
                            // it DOESN'T HAVE TO PAY THE COST AT THE POS, since it's the same value!
                            long extendCost = dpCost[idx] + extendFree;
                            if (buildCost < extendCost) {
                                // only if it's better than extending what we had do
                                // we actually update
                                dpCost[idx] = buildCost;
                                dpPos[idx] = i;
                            }
                        }
                        else if (idx == M) {
                            // we need to find the cost from here to the end!
                            long oldFullCost = dpCost[idx];
                            long newCost = bit.query(prevVal + 1, val) + full.query(val + 1, N);
                            long fullFree = negPrefix[N] - negPrefix[i] + negPrefix[i - 1] - negPrefix[prevPos];
                            long fullBuildCost  = dpCost[idx - 1] + newCost + fullFree;
                            if (fullBuildCost < oldFullCost) {
                                dpCost[idx] = fullBuildCost;
                                dpPos[idx] = i;
                            }
                        }
                    }
                }
            }
            bit.update(val, posCosts[i]);
        }
        // at this point, dpCost[M] should store the cost of building the
        // entire sequence through the Mth idx. However, if dpPos[M] equals 0,
        // then it wasn't reachable
        if (dpPos[M] == -1) {
            out.println("NO");
        }
        else {
            // Actually, we have a bit more work to do, since the sequence
            // might end much less than N, so we need to account for the last bit
            // of cost
            out.println("YES");
            out.println(dpCost[M]);
        }

        out.close();
    }

    static class BIT {
        int[] arr;
        long[] tree;

        public BIT(int[] arr) {
            this.arr = arr;
            this.tree = new long[arr.length];
            constructBIT(arr, tree);
        }

        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append("Index: ");
            for (int i = 1; i < tree.length; i++) {
                sb.append(i + " ");
            }
            sb.append("\nValue: ");
            for (int i = 1; i < tree.length; i++) {
                sb.append(this.query(i, i) + " ");
            }
            return sb.toString();
        }

        public int leastSignificantBit(int x) {
            return x & (-x);
        }

        public void constructBIT(int[] arr, long[] tree) {
            for (int i = 1; i < tree.length; i++) {
                tree[i] += arr[i];
                int j = i + leastSignificantBit(i);
                if (j < arr.length) {
                    tree[j] += tree[i];
                }
            }
        }

        public long query(int i, int j) {
            if (i <= j) {
                return prefixSum(j) - prefixSum(i - 1);
            }
            else {
                return 0;
            }
        }

        public long prefixSum(int i) {
            long sum = 0;
            while (i > 0) {
                sum += tree[i];
                i -= leastSignificantBit(i);
            }
            return sum;
        }

        public void update(int i, long val) {
            while (i < tree.length) {
                tree[i] += val;
                i += leastSignificantBit(i);
            }
        }

        public void set(int i, int k) {
            long val = query(i, i);
            update(i, k - val);
        }
    }

    static class FastScanner {
        private int BS = 1 << 16;
        private char NC = (char) 0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            } catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar() {
            while (bId == size) {
                try {
                    size = in.read(buf);
                } catch (Exception e) {
                    return NC;
                }
                if (size == -1) return NC;
                bId = 0;
            }
            return (char) buf[bId++];
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt = 1;
            boolean neg = false;
            if (c == NC) c = getChar();
            for (; (c < '0' || c > '9'); c = getChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = getChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                cnt *= 10;
            }
            return neg ? -res : res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c != '.' ? cur : cur + nextLong() / cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c > 32) {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c != '\n') {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if (c > 32) return true;
            while (true) {
                c = getChar();
                if (c == NC) return false;
                else if (c > 32) return true;
            }
        }
    }
}