package tryAndLean;

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	static final Integer MOD = Integer.valueOf(1000000007);

	public static Integer mul(Integer x, Integer y) {
		Long ret = Long.valueOf(x.intValue());
		ret = (ret * y) % MOD;
		return Integer.valueOf(ret.intValue());
	}

	public static int mul(int x, int y) {
		long ret = x;
		ret *= y;
		ret %= 1000000007;
		return (int) ret;
	}

	public static Integer power(Integer a, Integer b) {
		int basic = a.intValue(), times = b.intValue();
		int ret = 1;
		while(times > 0) {
			if((times & 1) == 1) ret = mul(ret, basic);
			basic = mul(basic, basic);
			times >>= 1;
		}
		return Integer.valueOf(ret);
	}

	public static Integer[] extGcd(Integer a, Integer b) {
		Integer [] ret = new Integer[3];
		if(b == 0) {
			ret[0] = Integer.valueOf(a.intValue());
			ret[1] = Integer.valueOf(1);
			ret[2] = Integer.valueOf(0);
		} else {
			Integer [] tmp = extGcd(b, a % b);
			Integer g = tmp[0], ta = tmp[2], tb = tmp[1] - a / b * tmp[2];
			if(ta < 0) {
				Integer t = ta / (b / g);
				ta -= t * (b / g);
				tb += t * (a / g);
			}
			if(ta < 0) {
				ta += b / g;
				tb -= a / g;
			}
			ret[0] = g;
			ret[1] = ta;
			ret[2] = tb;
		}
		return ret;
	}

	public static Integer inv(Integer x) {
//		0-> gcd   1->ta    2->tb
//		Integer [] results = extGcd(x, MOD);
//		return results[1];
		return power(x, MOD - 2);
	}

	public static Integer solve(Integer n, Integer m) {
//		System.out.println(n + " " + m);

		Integer [] f = new Integer[m + 3];
		f[0] = Integer.valueOf(0);
		for(int i = 1; i <= m + 2; i++) {
			f[i] = Integer.valueOf(f[i - 1] + power(i, m));
			if(f[i] >= MOD) f[i] -= MOD;
		}
//		System.out.println(power(Integer.valueOf(2), Integer.valueOf(100)));

//		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
//			System.out.print(f[i] + " ");
//		System.out.println("");

		if(n <= m + 2) return f[n];

		Integer [] lagrange = new Integer[m + 3];
		Integer [] fact = new Integer[m + 3];
		fact[0] = Integer.valueOf(1);
		for(int i = 1; i <= m + 2; i++)
			fact[i] = mul(fact[i - 1].intValue(), i);
		for(int i = 1; i <= m + 2; i++) {
			lagrange[i] = f[i];
			lagrange[i] = mul(lagrange[i], inv(mul(fact[i - 1], fact[m + 2 - i])));
			if(((m + 2 - i) & 1) == 1)
				lagrange[i] = MOD - lagrange[i];
//			System.out.print(lagrange[i] + " ");
		}
//		System.out.println("");

		Integer fullDenominator = Integer.valueOf(1);
		for(int i = 1; i <= m + 2; i++)
			fullDenominator = mul(fullDenominator.intValue(), n - i);
//		System.out.println(fullDenominator);

		Integer ret = Integer.valueOf(0);
		for(int i = 1; i <= m + 2; i++) {
			Integer denominator = Integer.valueOf(mul(fullDenominator, inv(n - i)));
//			System.out.print(denominator + " ");
			ret = ret + mul(denominator, lagrange[i]);
			if(ret >= MOD) ret -= MOD;
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {

		Scanner reader = new Scanner(System.in);
		Integer n = new Integer(reader.nextInt());
		Integer k = new Integer(reader.nextInt());

		Integer ans = solve(n, k);

		System.out.println(ans);

		reader.close();
	}
}


package tryAndLean;

import java.io.*;
import java.math.*;
import java.util.*;

import javax.swing.plaf.multi.MultiButtonUI;
import javax.xml.parsers.FactoryConfigurationError;

public class Main {
	static final Integer N = 1000010, MOD = new Integer(1000000009);

	public static Integer mul(Integer x, Integer y) {
		Long ret = new Long(x.intValue());
		ret = (ret * y) % MOD;
		return Integer.valueOf(ret.intValue());
	}

	public static Integer power(Integer basic, Integer times) {
		Integer ret = Integer.valueOf(1);
		while(times > 0) {
			if((times & 1) == 1)  ret = mul(ret, basic);
			basic = mul(basic, basic);
			times >>= 1;
		}
		return ret;
	}

	public static Integer[] extGcd(Integer a, Integer b) {
		Integer [] ret = new Integer[3];
		if(b == 0) {
			ret[0] = Integer.valueOf(a.intValue());
			ret[1] = Integer.valueOf(1);
			ret[2] = Integer.valueOf(0);
		} else {
			Integer [] tmp = extGcd(b, a % b);
			Integer g = tmp[0], ta = tmp[2], tb = tmp[1] - a / b * tmp[2];
			if(ta < 0) {
				Integer t = ta / (b / g);
				ta -= t * (b / g);
				tb += t * (a / g);
			}
			if(ta < 0) {
				ta += b / g;
				tb -= a / g;
			}
			ret[0] = g;
			ret[1] = ta;
			ret[2] = tb;
		}
		return ret;
	}

	public static Integer inv(Integer x) {
//		0-> gcd   1->ta    2->tb
		Integer [] results = extGcd(x, MOD);
		return results[1];
	}

	public static Integer solve(Integer n, Integer m) {
//		System.out.println(n + " " + m);

		Integer [] f = new Integer[m + 3];
		f[0] = Integer.valueOf(0);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
			f[i] = new Integer((f[i - 1] + power(i, m)) % MOD);

		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
//			System.out.print(f[i] + " ");
//		System.out.println("");

		if(n <= m + 2) return f[n];

		Integer [] lagrange = new Integer[m + 3];
		Integer [] fact = new Integer[m + 3];
		fact[0] = Integer.valueOf(1);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
			fact[i] = mul(fact[i - 1], i);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++) {
			lagrange[i] = f[i];
			lagrange[i] = mul(lagrange[i], inv(mul(fact[i - 1], fact[m + 2 - i])));
			if(((m + 2 - i) & 1) == 1)
				lagrange[i] = MOD - lagrange[i];
//			System.out.print(lagrange[i] + " ");
		}
//		System.out.println("");

		Integer fullDenominator = Integer.valueOf(1);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
			fullDenominator = mul(fullDenominator, n - i);
//		System.out.println(fullDenominator);

		Integer ret = Integer.valueOf(0);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++) {
			Integer denominator = Integer.valueOf(mul(fullDenominator, inv(n - i)));
//			System.out.print(denominator + " ");
			ret = (ret + mul(denominator, lagrange[i])) % MOD;
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {
		Scanner reader = new Scanner(System.in);
		Integer n = new Integer(reader.nextInt());
		Integer k = new Integer(reader.nextInt());

		Integer ans = solve(n, k);

		System.out.println(ans);

		reader.close();
	}
}


package tryAndLean;

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	static final Integer N = Integer.valueOf(1000010), MOD = Integer.valueOf(1000000007);

	public static Integer mul(Integer x, Integer y) {
		Long ret = Long.valueOf(x.intValue());
		ret = (ret * y) % MOD;
		return Integer.valueOf(ret.intValue());
	}

	public static Integer power(Integer basic, Integer times) {
		Integer ret = Integer.valueOf(1);
		while(times > 0) {
			if((times & 1) == 1) ret = mul(ret, basic);
			basic = mul(basic, basic);
			times >>= 1;
		}
		return ret;
	}

	public static Integer[] extGcd(Integer a, Integer b) {
		Integer [] ret = new Integer[3];
		if(b == 0) {
			ret[0] = Integer.valueOf(a.intValue());
			ret[1] = Integer.valueOf(1);
			ret[2] = Integer.valueOf(0);
		} else {
			Integer [] tmp = extGcd(b, a % b);
			Integer g = tmp[0], ta = tmp[2], tb = tmp[1] - a / b * tmp[2];
			if(ta < 0) {
				Integer t = ta / (b / g);
				ta -= t * (b / g);
				tb += t * (a / g);
			}
			if(ta < 0) {
				ta += b / g;
				tb -= a / g;
			}
			ret[0] = g;
			ret[1] = ta;
			ret[2] = tb;
		}
		return ret;
	}

	public static Integer inv(Integer x) {
//		0-> gcd   1->ta    2->tb
//		Integer [] results = extGcd(x, MOD);
//		return results[1];
		return power(x, MOD - 2);
	}

	public static Integer solve(Integer n, Integer m) {
//		System.out.println(n + " " + m);

		Integer [] f = new Integer[m + 3];
		f[0] = Integer.valueOf(0);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
			f[i] = Integer.valueOf((f[i - 1] + power(i, m)) % MOD);
//		System.out.println(power(Integer.valueOf(2), Integer.valueOf(100)));

//		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
//			System.out.print(f[i] + " ");
//		System.out.println("");

		if(n <= m + 2) return f[n];

		Integer [] lagrange = new Integer[m + 3];
		Integer [] fact = new Integer[m + 3];
		fact[0] = Integer.valueOf(1);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
			fact[i] = mul(fact[i - 1], i);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++) {
			lagrange[i] = f[i];
			lagrange[i] = mul(lagrange[i], inv(mul(fact[i - 1], fact[m + 2 - i])));
			if(((m + 2 - i) & 1) == 1)
				lagrange[i] = MOD - lagrange[i];
//			System.out.print(lagrange[i] + " ");
		}
//		System.out.println("");

		Integer fullDenominator = Integer.valueOf(1);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++)
			fullDenominator = mul(fullDenominator, n - i);
//		System.out.println(fullDenominator);

		Integer ret = Integer.valueOf(0);
		for(Integer i = Integer.valueOf(1); i <= m + 2; i++) {
			Integer denominator = Integer.valueOf(mul(fullDenominator, inv(n - i)));
//			System.out.print(denominator + " ");
			ret = (ret + mul(denominator, lagrange[i])) % MOD;
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {
		Scanner reader = new Scanner(System.in);
		Integer n = new Integer(reader.nextInt());
		Integer k = new Integer(reader.nextInt());

		Integer ans = solve(n, k);

		System.out.println(ans);

		reader.close();
	}
}


import java.util.*;

public class twoPlusTwoDoesNotEqualFour {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		int ans = 0, temp = 0;
		boolean flagged = true;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) >= '0' && s.charAt(i) <= '9') {
				temp = temp * 10 + s.charAt(i) - '0';
			} else {
				if (flagged)
					ans += temp;
				else
					ans -= temp;
				if (s.charAt(i) == '+')
					flagged = true;
				else
					flagged = false;
				temp = 0;
				temp = temp * 10 + s.charAt(i) - '0';
			}
		}
		if (flagged)
			ans += temp;
		else
			ans -= temp;
		System.out.println("" + ans);
	}
}


import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int ans = 0, tmp = 0, len = s.length();
        boolean flag = true;
        for (int i = 0; i < len; i++)
        {
            if (s.charAt(i) >= '0' && s.charAt(i) <= '9')
            {
                tmp = tmp * 10 + s.charAt(i) - '0';
            }
            else
            {
                if (flag) ans += tmp;
                else ans -= tmp;
                if (s.charAt(i) == '+') flag = true;
                else flag = false;
                tmp = 0;
                tmp = tmp * 10 + s.charAt(i) - '0';
            }
        }
        if (flag) ans += tmp;
        else ans -= tmp;
        System.out.println("" + ans);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            String s = in.next();
            int n = s.length();
            int a = 1;
            int b = 0;
            int ans = 0;

            for (int i = 0; i < n; ++i) {
                if (s.charAt(i) == '-') {
                    ans += a * b;
                    a = -1;
                    b = 0;
                } else if (s.charAt(i) == '+') {
                    ans += a * b;
                    a = 1;
                    b = 0;
                }
                b = b * 10 + s.charAt(i) - '0';
            }

            ans += a * b;
            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}


import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        String tkn = input.next();
        int val = 0
		int tmp = 0
		int qty = tkn.length();
        boolean flg = true;
        for (int i = 0; i < qty; i++)
        {
            if (tkn.charAt(i) >= '0' && tkn.charAt(i) <= '9')
            {
                tmp = tmp * 10 + tkn.charAt(i) - '0';
            }
            else
            {
                if (flg) val += tmp;
                else val -= tmp;
                if (tkn.charAt(i) == '+') flg = true;
                else flg = false;
                tmp = 0;
                tmp = tmp * 10 + tkn.charAt(i) - '0';
            }
        }
        if (flg) val += tmp;
        else val -= tmp;
        System.out.println("" + val);
    }
}


//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {
        public class Number {
            int factNum;
            int[] primeFactorCounts;
            int largestFactor;
            int S = 0;
            public Number(int f, int[] primeFactorCounts) {
                this.factNum = f;
                this.primeFactorCounts = primeFactorCounts;
                for (largestFactor = primeFactorCounts.length - 1; largestFactor >= 0; largestFactor--) {
                    if (primeFactorCounts[largestFactor] != 0) break;
                }
                for (int y: primeFactorCounts)S += y;
            }
            int getL() {
                if (largestFactor == -1) return -1;
                int r = largestFactor;
                primeFactorCounts[r]--;
                if (primeFactorCounts[r] == 0) largestFactor--;
                return r;
            }
        }

        List<Integer> primes;
        int[] factor;

        public void precompute() {
            int n = 5001;
            primes = new ArrayList<>();
            factor = new int[n];
            Arrays.fill(factor, -1);
            for (int i = 2; i < n; ++i) {
                if (factor[i] == -1) {
                    factor[i] = primes.size();
                    primes.add(i);
                }
                for (int j = 0; j < primes.size () && i * primes.get(j) < n; ++j) {
                    int p = primes.get(j);
                    factor[i * p] = j;
                    if (i % p == 0) {
                        break;
                    }
                }
            }
        }

        List<Integer> fact(int x) {
            List<Integer> retL = new ArrayList<>();
            while (x != 1) {
                retL.add(factor[x]);
                x /= primes.get(factor[x]);
            }
            return retL;
        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            precompute();
            int[] primeF = new int[700];
            Number[] numbers = new Number[5001];
            numbers[1] = new Number(1, Arrays.copyOf(primeF, 700));
            for (int i = 2; i <= 5000; i++) {
                List<Integer> f = fact(i);
                for (int y: f) primeF[y]++;
                numbers[i] = new Number(i, Arrays.copyOf(primeF, 700));
            }
//            pw.println(Arrays.toString(numbers[5000].primeFactorCounts));
//            System.err.println(numbers[5000].S);
            Map<Integer, Integer> numToCount = new HashMap<>();
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                numToCount.put(a, numToCount.getOrDefault(a, 0) + 1);
            }
            long total = 0;
            for (Map.Entry<Integer, Integer> en : numToCount.entrySet()) {
                total += (long) en.getValue() * numbers[en.getKey()].S;
            }
            outer:
            while (true) {
                Map<Integer, Integer> kG = new HashMap<>();
                for (Map.Entry<Integer, Integer> en : numToCount.entrySet()) {
                    int k = en.getKey();
                    int v = en.getValue();
                    int lf = numbers[k].largestFactor;
                    kG.put(lf, kG.getOrDefault(lf, 0) + v);
                }
                for (Map.Entry<Integer, Integer> en: kG.entrySet()) {
                    if (n - en.getValue() < en.getValue()) {
                        total -= en.getValue() - (n - en.getValue());
                        Map<Integer, Integer> nC = new HashMap<>();
                        for (Map.Entry<Integer, Integer> en1 : numToCount.entrySet()) {
                            int lf = numbers[en1.getKey()].getL();
                            if (lf == en.getKey()) {
                                nC.put(en1.getKey(), en1.getValue());
                            }
                        }
                        numToCount = nC;
                        continue outer;
                    }
                }
                pw.println(total);
                return;
            }
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("output"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}


/*
javac f.java && java f
*/

import java.io.*;
import java.util.*;

public class f {
	public static void main(String[] args) { new f(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int n;
	long[] a;

	int MAX = 5001;
	int pcnt, pr[];
	int[][] vp, cs;
	boolean[] isnt;

	f() {
		pcnt = 0;
		isnt = new boolean[MAX];
		isnt[0] = true; isnt[1] = true;
		for (int i = 2; i < MAX; i++)
			if (!isnt[i]) {
				pcnt++;
				for (int j = (i << 1); j < MAX; j += i)
					isnt[j] = true;
			}
		pr = new int[pcnt]; pcnt = 0;
		for (int i = 0; i < MAX; i++)
			if (!isnt[i])
				pr[pcnt++] = i;

		/*
		long ops = 0, gap3 = 0;
		for (int i = 0; i < pcnt; i++) {
			long del = i == 0 ? 1 : pr[i] - pr[i - 1];
			out.printf("del = %d | p = %d%n", del, pr[i]);
			ops += (del * del * del);
			gap3 = max(gap3, del * del * del);
		}
		out.println("--> " + ops + " OW3 " + gap3);
		*/

		vp = new int[MAX][pcnt];
		for (int i = 2; i < MAX; i++)
			for (int j = 0; j < pcnt; j++) {
				int k = i;
				while (k > 0) {
					vp[i][j] += (k / pr[j]);
					k /= pr[j];
				}
			}
		cs = new int[MAX][pcnt + 1];
		for (int i = 2; i < MAX; i++)
			for (int j = 1; j <= pcnt; j++)
				cs[i][j] = vp[i][j - 1] + cs[i][j - 1];

		n = in.nextInt();
		a = new long[MAX];
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			if (x == 0) x++;
			a[x]++;
		}
		long[] f = new long[MAX + 1];
		for (int i = 1; i <= MAX; i++)
			f[i] = f[i - 1] + a[i - 1];

		long[] dist = new long[MAX + 1];
		for (int i = 1; i <= MAX; i++)
			dist[i] = dist[i - 1] + a[i - 1] * cs[i - 1][pcnt];

		// F I X  T H I S
		long ans = dist[MAX];
		int l = 2, r;
		for (int i = 0; i < pcnt; i++) {
			r = i == pcnt - 1 ? MAX - 1 : pr[i + 1] - 1;
			// everybody outside this range of highest prime must travel to 1 first
			// then travel up to the lca we're trying at each step
			long blw = dist[MAX] - (dist[r + 1] - dist[l]);
			// so when trying lca(j, k) we need to know how many primes are on in it
			// and how far every person in the range [l, r] will need to travel
			for (int x = r; x >= l; x--)
				for (int y = x; y >= l; y--) {
					// lca will be gotten as (pIDX, cnt)
					int[] lca = {-1, 0};
					for (int z = i; z >= 0; z--)
						if (vp[x][z] != vp[y][z]) {
							lca[0] = z;
							lca[1] = min(vp[x][z], vp[y][z]);
							break;
						}

					long up = lca[1] + cs[x][pcnt] - cs[x][lca[0] + 1];
					up *= (f[MAX] - f[r + 1] + f[l]);

					long abv = 0;
					for (int z = r; z >= l; z--) {
						if (x == z && y == z) continue;
						// given lca(x, y) = {w, cnt}
						// if we get to w add in prefix of other primes in a[z] * cs[w - 1]
						// add a[z] * [abs(cnt - cnt[z]) to abv
						// if we dont get to w before they differ
						// add a[z] * (diff to here + here up)
						for (int w = i; w >= lca[0]; w--) {
							if (w == lca[0]) {
								abv += a[z] * cs[z][w];
								abv += a[z] * abs(vp[z][w] - lca[1]);
								break;
							}
							if (vp[z][w] != vp[x][w]) {
								abv += a[z] * cs[z][w];
								abv += a[z] * abs(vp[z][w] - vp[x][w]);
								abv += a[z] * (cs[x][w] - cs[x][lca[0] + 1]);
								abv += a[z] * lca[1];
								break;
							}
						}
					}
					ans = min(ans, abv + blw + up);
				}
			l = r + 1;
		}

		out.println(ans);
		out.close();
	}

	int abs(int x) { if (x < 0) return -x; return x; }
	long abs(long x) { if (x < 0) return -x; return x; }
	int max(int x, int y) { if (x < y) return y; return x; }
	int min(int x, int y) { if (x > y) return y; return x; }
	long max(long x, long y) { if (x < y) return y; return x; }
	long min(long x, long y) { if (x > y) return y; return x; }
	int gcd(int x, int y) { while (y != 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long gcd(long x, long y) { while (y != 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long lcm(int x, int y) { long xy = x; xy *= y; return xy / gcd(x, y); }
	long lcm(long x, long y) { return (x * y) / gcd(x, y); }

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }

		void intArr(int sz, int[] x) { for (int i = 0; i < sz; i++) x[i] = nextInt(); }
		void longArr(int sz, long[] x) { for (int i = 0; i < sz; i++) x[i] = nextLong(); }
		void doubleArr(int sz, double[] x) { for (int i = 0; i < sz; i++) x[i] = nextDouble(); }
	}
}


//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {
        public class Number {
            int factNum;
            int[] primeFactorCounts;
            int largestFactor;
            int S = 0;
            public Number(int f, int[] primeFactorCounts) {
                this.factNum = f;
                this.primeFactorCounts = primeFactorCounts;
                for (largestFactor = primeFactorCounts.length - 1; largestFactor >= 0; largestFactor--) {
                    if (primeFactorCounts[largestFactor] != 0) break;
                }
                for (int y: primeFactorCounts)S += y;
            }
            int getL() {
                if (largestFactor == -1) return -1;
                int r = largestFactor;
                primeFactorCounts[r]--;
                if (primeFactorCounts[r] == 0) largestFactor--;
                return r;
            }
        }

        List<Integer> primes;
        int[] factor;

        public void precompute() {
            int n = 5001;
            primes = new ArrayList<>();
            factor = new int[n];
            Arrays.fill(factor, -1);
            for (int i = 2; i < n; ++i) {
                if (factor[i] == -1) {
                    factor[i] = primes.size();
                    primes.add(i);
                }
                for (int j = 0; j < primes.size () && i * primes.get(j) < n; ++j) {
                    int p = primes.get(j);
                    factor[i * p] = j;
                    if (i % p == 0) {
                        break;
                    }
                }
            }
        }

        List<Integer> fact(int x) {
            List<Integer> retL = new ArrayList<>();
            while (x != 1) {
                retL.add(factor[x]);
                x /= primes.get(factor[x]);
            }
            return retL;
        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            precompute();
            int[] primeF = new int[700];
            Number[] numbers = new Number[5001];
//            numbers[0] = new Number(1, Arrays.copyOf(primeF, 700));
            numbers[1] = new Number(1, Arrays.copyOf(primeF, 700));
            for (int i = 2; i <= 5000; i++) {
                List<Integer> f = fact(i);
                for (int y: f) primeF[y]++;
                numbers[i] = new Number(i, Arrays.copyOf(primeF, 700));
            }
//            pw.println(Arrays.toString(numbers[5000].primeFactorCounts));
//            System.err.println(numbers[5000].S);
            Map<Integer, Integer> numToCount = new HashMap<>();
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                a = Math.max(a, 1);
                numToCount.put(a, numToCount.getOrDefault(a, 0) + 1);
            }
            long total = 0;
            for (Map.Entry<Integer, Integer> en : numToCount.entrySet()) {
                total += (long) en.getValue() * numbers[en.getKey()].S;
            }
            outer:
            while (true) {
                Map<Integer, Integer> kG = new HashMap<>();
                for (Map.Entry<Integer, Integer> en : numToCount.entrySet()) {
                    int k = en.getKey();
                    int v = en.getValue();
                    int lf = numbers[k].largestFactor;
                    if (lf == -1) continue ;
                    kG.put(lf, kG.getOrDefault(lf, 0) + v);
                }
                for (Map.Entry<Integer, Integer> en: kG.entrySet()) {
                    if (n - en.getValue() < en.getValue()) {
                        total -= en.getValue() - (n - en.getValue());
                        Map<Integer, Integer> nC = new HashMap<>();
                        for (Map.Entry<Integer, Integer> en1 : numToCount.entrySet()) {
                            int lf = numbers[en1.getKey()].getL();
                            if (lf == en.getKey()) {
                                nC.put(en1.getKey(), en1.getValue());
                            }
                        }
                        numToCount = nC;
                        continue outer;
                    }
                }
                pw.println(total);
                return;
            }
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("output"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}


import java.util.*;
import java.io.*;

public class f {
   public static FS sc;
   public static PrintWriter out;
   public static ArrayList<Integer>[] adj;
   public static int n;

   public static HashMap<Long, Long> memo, memoSize;

   public static void main(String[] Args) throws Exception {
      sc = new FS(System.in);
      out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
      int n = sc.nextInt();
      int MAX =5010;
      int[][] dist = new int[MAX][MAX];

      BIT bi = new BIT(MAX);
      int[] primes = new int[MAX];
      int[] factDivs = new int[MAX];
      int[] valDivs = new int[MAX];
      Arrays.fill(primes, 1);
      for (int i = 2; i < MAX; i++){
         if (primes[i] == 1){
            for (int j = i  * 2; j < MAX; j+=i)
               primes[j] = i;
            valDivs[i]=1;
            primes[i] = i;
         }else
            valDivs[i]=valDivs[i/primes[i]] + 1;
         factDivs[i] = factDivs[i-1] + valDivs[i];

      }/*
      for (int i = 0; i<10; i++)
      {
         System.out.println(primes[i] +" " +valDivs[i] +" " +factDivs[i]);
      }*/

      for (int i = 2; i < MAX; i++){
         int last = bi.sum(MAX-1) - bi.sum(primes[i]-1);
         int j = i - 1;
         dist[i][i] = factDivs[i];
         while (last != 0) {
            dist[i][j] = dist[j][i] = last;
            int last2 = dist[i-1][j-1];
            if (last > last2)
               last = last2;
            j--;
         }
         int ii = i;
         while (ii != 1) {
            bi.inc(primes[ii],1);
            ii /= primes[ii];
         }
      }/*
      for (int i = 1; i < 6; i++){
         for (int j = 1; j < 6;j++) {
            int actDist = factDivs[i] + factDivs[j] - dist[i][j]*2;
            System.out.print(actDist +" " );
         }
         System.out.println();
      }*/

      long[] count = new long[MAX];
      for (int i = 0; i<n; i++){
         int x = sc.nextInt();
         if (x == 0)
            x++;
         count[x]++;
      }
      long ans = Long.MAX_VALUE;
      for (int i = 1; i< MAX; i++){
         long tans = 0;
         for (int j = 1; j< MAX; j++){
            tans += count[j] * (factDivs[i] + factDivs[j] - dist[i][j]*2);
         }
         if(tans < ans)
            ans = tans;
      }
      out.println(ans);
      out.close();
   }
   public static class BIT {
      int n;
      int[] v;
      BIT(int N) { v = new int[n=N]; }
      int sum(int x) { return x<0?0:(v[x]+sum((x&(x+1))-1)); }
      void inc(int p, int x) { for(int i=p; i<n; i|=(i+1)) v[i]+=x; }
   }

   public static class FS {
      BufferedReader br;
      StringTokenizer st;
      FS(InputStream in) throws Exception {
         br = new BufferedReader(new InputStreamReader(in));
         st = new StringTokenizer(br.readLine());
      }
      String next() throws Exception {
         if(st.hasMoreTokens())
            return st.nextToken();
         st = new StringTokenizer(br.readLine());
         return next();
      }
      int nextInt() throws Exception {
         return Integer.parseInt(next());
      }
      long nextLong() throws Exception {
         return Long.parseLong(next());
      }
      double nextDouble() throws Exception {
         return Double.parseDouble(next());
      }
   }

   public class Pair implements Comparable<Pair> {
      int ind;
      long value;
      double value2;
      Pair(int ii, long vv) {
         ind=ii;value=vv;
         value2=0.0;
      }
      public int compareTo(Pair o) {
         if (o.value == value)
            return Double.compare(value2,o.value);
         return Long.compare(value, o.value);
      }
   }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.stream.IntStream;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            GCowAndExercise solver = new GCowAndExercise();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class GCowAndExercise {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();
            MakeDistanceFarthest mdf = new MakeDistanceFarthest(n);
            for (int i = 0; i < m; i++) {
                mdf.addEdge(in.readInt() - 1, in.readInt() - 1, in.readInt(), 1);
            }
            mdf.solve(new LongDijkstraV2MinimumCostFlow(n), 0, n - 1, (int) 1e5, (long) 1e18, (int) 1e9);
            int q = in.readInt();
            for (int i = 0; i < q; i++) {
                int x = in.readInt();
                double ans = mdf.queryByExpense(x);
                out.println(ans);
            }
        }

    }

    static interface LongMinimumCostFlow {
        long[] apply(List<LongCostFlowEdge>[] net, int s, int t, long send);

    }

    static interface IntegerStack {
        void addLast(int x);

        boolean isEmpty();

        void clear();

    }

    static class MakeDistanceFarthest {
        private List<LongCostFlowEdge>[] g;
        MakeDistanceFarthest.LinearFunction[] fs;

        public MakeDistanceFarthest(int n) {
            g = LongFlow.createCostFlow(n);
        }

        public void addEdge(int u, int v, long len, long cost) {
            LongFlow.addCostEdge(g, u, v, cost, len);
        }

        public void solve(LongAugmentMinimumCostFlow mcf, int s, int t, long budgeLimit, long distLimit, long flowLimit) {
            List<MakeDistanceFarthest.LinearFunction> list = new ArrayList<>();
            LongAugmentCallback callback = new LongAugmentCallback() {
                long sumFlow = 0;
                long sumCost = 0;

                public boolean callback(long flow, long pathCost) {
                    sumFlow += flow;
                    sumCost += flow * pathCost;

                    if (!list.isEmpty() && list.get(list.size() - 1).l == pathCost) {
                        list.remove(list.size() - 1);
                    }
                    MakeDistanceFarthest.LinearFunction func = new MakeDistanceFarthest.LinearFunction(pathCost, sumFlow, -sumCost);
                    list.add(func);
                    return func.getL() <= budgeLimit && func.l <= distLimit;
                }
            };
            mcf.setCallback(callback);
            mcf.apply(g, s, t, flowLimit);
            fs = list.toArray(new MakeDistanceFarthest.LinearFunction[0]);
        }

        public double queryByExpense(long x) {
            int l = 0;
            int r = fs.length - 1;
            while (l < r) {
                int mid = (l + r) / 2;
                boolean valid = mid + 1 >= fs.length ||
                        fs[mid + 1].getL() > x;
                if (valid) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            return fs[l].inverse(x);
        }

        private static class LinearFunction {
            long l;
            long a;
            long b;

            public LinearFunction(long l, long a, long b) {
                this.l = l;
                this.a = a;
                this.b = b;
            }

            long getL() {
                return a * l + b;
            }

            double inverse(double y) {
                return (y - b) / a;
            }

        }

    }

    static interface IntegerDeque extends IntegerStack {
        int removeFirst();

    }

    static interface LongAugmentCallback {
        public static LongAugmentCallback NIL = (a, b) -> {
            return true;
        };

        public boolean callback(long flow, long pathCost);

    }

    static class LongFlow {
        public static <T extends LongFlowEdge> void send(T edge, long flow) {
            edge.flow += flow;
            edge.rev.flow -= flow;
        }

        public static LongCostFlowEdge addCostEdge(List<LongCostFlowEdge>[] g, int s, int t, long cap, long cost) {
            LongCostFlowEdge real = new LongCostFlowEdge(t, 0, true, cost);
            LongCostFlowEdge virtual = new LongCostFlowEdge(s, cap, false, -cost);
            real.rev = virtual;
            virtual.rev = real;
            g[s].add(real);
            g[t].add(virtual);
            return real;
        }

        public static List<LongCostFlowEdge>[] createCostFlow(int n) {
            return createGraph(n);
        }

        private static List[] createGraph(int n) {
            return IntStream.range(0, n).mapToObj(i -> new ArrayList<>()).toArray(i -> new List[i]);
        }

    }

    static class LongFlowEdge<T extends LongFlowEdge<T>> extends DirectedEdge {
        public long flow;
        public boolean real;
        public T rev;

        public LongFlowEdge(int to, long flow, boolean real) {
            super(to);
            this.flow = flow;
            this.real = real;
        }

        public String toString() {
            return rev.to + "-[" + flow + "/" + (flow + rev.flow) + "]->" + to;
        }

    }

    static class LongDijkstraV2MinimumCostFlow implements LongAugmentMinimumCostFlow {
        private int m;
        private long[] lastDist;
        private long[] curDist;
        private LongCostFlowEdge[] prev;
        private boolean[] inq;
        private IntegerDeque dq;
        private static final long INF = Long.MAX_VALUE / 4;
        private List<LongCostFlowEdge>[] g;
        private LongAugmentCallback callback = LongAugmentCallback.NIL;

        public void setCallback(LongAugmentCallback callback) {
            this.callback = callback;
        }

        public LongDijkstraV2MinimumCostFlow(int m) {
            this.m = m - 1;
            lastDist = new long[m];
            curDist = new long[m];
            prev = new LongCostFlowEdge[m];
            inq = new boolean[m];
            dq = new IntegerDequeImpl(m);
        }

        private void bf(int s) {
            int n = g.length;
            dq.clear();
            for (int i = 0; i < n; i++) {
                lastDist[i] = INF;
                inq[i] = false;
            }
            lastDist[s] = 0;
            inq[s] = true;
            dq.addLast(s);
            while (!dq.isEmpty()) {
                int head = dq.removeFirst();
                inq[head] = false;
                for (LongCostFlowEdge e : g[head]) {
                    if (DigitUtils.equal(e.rev.flow, 0) || lastDist[e.to] <= lastDist[head] + e.cost) {
                        continue;
                    }
                    lastDist[e.to] = lastDist[head] + e.cost;
                    if (!inq[e.to]) {
                        inq[e.to] = true;
                        dq.addLast(e.to);
                    }
                }
            }
        }

        private void dijkstra(int s) {
            int n = g.length;
            for (int i = 0; i < n; i++) {
                curDist[i] = INF;
                prev[i] = null;
                inq[i] = false;
            }
            curDist[s] = 0;

            for (int i = 0; i < n; i++) {
                int head = -1;
                for (int j = 0; j < n; j++) {
                    if (!inq[j] && (head == -1 || curDist[j] < curDist[head])) {
                        head = j;
                    }
                }
                if (curDist[head] >= INF) {
                    break;
                }
                inq[head] = true;
                for (LongCostFlowEdge e : g[head]) {
                    long dist;
                    if (e.rev.flow == 0 || curDist[e.to] <= (dist = curDist[head] + e.cost - lastDist[e.to] + lastDist[head])) {
                        continue;
                    }
                    prev[e.to] = e.rev;
                    curDist[e.to] = dist;
                }
            }

            for (int i = 0; i < n; i++) {
                lastDist[i] = Math.min(curDist[i] + lastDist[i], INF);
            }
        }

        public long[] apply(List<LongCostFlowEdge>[] net, int s, int t, long send) {
            this.g = net;
            bf(s);
            long flow = 0;
            long cost = 0;
            while (flow < send) {
                dijkstra(s);
                if (prev[t] == null) {
                    break;
                }
                long remain = send - flow;
                for (LongCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {
                    remain = Math.min(remain, trace.flow);
                }
                long sumOfCost = 0;
                for (LongCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {
                    sumOfCost -= trace.cost;
                    LongFlow.send(trace, -remain);
                }
                cost += sumOfCost * -remain;
                flow += remain;
                if (!callback.callback(remain, sumOfCost)) {
                    break;
                }
            }
            return new long[]{flow, cost};
        }

    }

    static interface LongAugmentMinimumCostFlow extends LongMinimumCostFlow {
        public void setCallback(LongAugmentCallback callback);

    }

    static interface IntegerIterator {
        boolean hasNext();

        int next();

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class IntegerDequeImpl implements IntegerDeque {
        private int[] data;
        private int bpos;
        private int epos;
        private static final int[] EMPTY = new int[0];
        private int n;

        public IntegerDequeImpl(int cap) {
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
            bpos = 0;
            epos = 0;
            n = cap;
        }

        private void expandSpace(int len) {
            while (n < len) {
                n = Math.max(n + 10, n * 2);
            }
            int[] newData = new int[n];
            if (bpos <= epos) {
                if (bpos < epos) {
                    System.arraycopy(data, bpos, newData, 0, epos - bpos);
                }
            } else {
                System.arraycopy(data, bpos, newData, 0, data.length - bpos);
                System.arraycopy(data, 0, newData, data.length - bpos, epos);
            }
            epos = size();
            bpos = 0;
            data = newData;
        }

        public IntegerIterator iterator() {
            return new IntegerIterator() {
                int index = bpos;

                public boolean hasNext() {
                    return index != epos;
                }

                public int next() {
                    int ans = data[index];
                    index = IntegerDequeImpl.this.next(index);
                    return ans;
                }
            };
        }

        public int removeFirst() {
            int ans = data[bpos];
            bpos = next(bpos);
            return ans;
        }

        public void addLast(int x) {
            ensureMore();
            data[epos] = x;
            epos = next(epos);
        }

        public void clear() {
            bpos = epos = 0;
        }

        private int next(int x) {
            return x + 1 >= n ? 0 : x + 1;
        }

        private void ensureMore() {
            if (next(epos) == bpos) {
                expandSpace(n + 1);
            }
        }

        public int size() {
            int ans = epos - bpos;
            if (ans < 0) {
                ans += data.length;
            }
            return ans;
        }

        public boolean isEmpty() {
            return bpos == epos;
        }

        public String toString() {
            StringBuilder builder = new StringBuilder();
            for (IntegerIterator iterator = iterator(); iterator.hasNext(); ) {
                builder.append(iterator.next()).append(' ');
            }
            return builder.toString();
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(double c) {
            cache.append(new BigDecimal(c).toPlainString());
            return this;
        }

        public FastOutput println(double c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class LongCostFlowEdge extends LongFlowEdge<LongCostFlowEdge> {
        public long cost;

        public LongCostFlowEdge(int to, long flow, boolean real, long cost) {
            super(to, flow, real);
            this.cost = cost;
        }

    }

    static class DirectedEdge {
        public int to;

        public DirectedEdge(int to) {
            this.to = to;
        }

        public String toString() {
            return "->" + to;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static boolean equal(long a, long b) {
            return a == b;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            GCowAndExercise solver = new GCowAndExercise();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class GCowAndExercise {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();
            int[][] edges = new int[m][3];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < 3; j++) {
                    edges[i][j] = in.readInt();
                }
            }
            List<IntegerCostFlowEdge>[] g = IntegerFlow.createCostFlow(n);
            for (int[] e : edges) {
                int u = e[0] - 1;
                int v = e[1] - 1;
                int w = e[2];
                IntegerFlow.addCostEdge(g, u, v, 1, w);
            }

            List<LinearFunction> list = new ArrayList<>();
            IntegerAugmentCallback callback = new IntegerAugmentCallback() {
                int sumFlow = 0;
                int sumCost = 0;

                public void callback(int flow, int pathCost) {
                    sumFlow += flow;
                    sumCost += flow * pathCost;

                    if (!list.isEmpty() && list.get(list.size() - 1).l == pathCost) {
                        list.remove(list.size() - 1);
                    }
                    LinearFunction func = new LinearFunction(pathCost, sumFlow, -sumCost);
                    list.add(func);
                }
            };
            IntegerDijkstraV2MinimumCostFlow mcf = new IntegerDijkstraV2MinimumCostFlow(n);
            mcf.setCallback(callback);
            mcf.apply(g, 0, n - 1, (int) 1e8);
            LinearFunction[] fs = list.toArray(new LinearFunction[0]);

            int q = in.readInt();
            Query[] qs = new Query[q];
            for (int i = 0; i < q; i++) {
                qs[i] = new Query();
                qs[i].x = in.readInt();
            }

            Query[] sortedQs = qs.clone();
            Arrays.sort(sortedQs, (a, b) -> Integer.compare(a.x, b.x));
            int cur = -1;
            for (Query query : sortedQs) {
                while (cur + 1 < fs.length && fs[cur + 1].getL() <= query.x) {
                    cur++;
                }
                query.ans = fs[cur].getX(query.x);
            }

            for (Query query : qs) {
                out.println(query.ans);
            }
        }

    }

    static class Query {
        int x;
        double ans;

    }

    static interface IntegerDeque extends IntegerStack {
        int removeFirst();

    }

    static class IntegerDijkstraV2MinimumCostFlow implements IntegerMinimumCostFlow {
        private int m;
        private int[] lastDist;
        private int[] curDist;
        private IntegerCostFlowEdge[] prev;
        private boolean[] inq;
        private IntegerDeque dq;
        private static final int INF = Integer.MAX_VALUE / 4;
        private List<IntegerCostFlowEdge>[] g;
        private IntegerAugmentCallback callback = IntegerAugmentCallback.NIL;

        public void setCallback(IntegerAugmentCallback callback) {
            this.callback = callback;
        }

        public IntegerDijkstraV2MinimumCostFlow(int m) {
            this.m = m - 1;
            lastDist = new int[m];
            curDist = new int[m];
            prev = new IntegerCostFlowEdge[m];
            inq = new boolean[m];
            dq = new IntegerDequeImpl(m);
        }

        private void bf(int s) {
            int n = g.length;
            dq.clear();
            for (int i = 0; i < n; i++) {
                lastDist[i] = INF;
                inq[i] = false;
            }
            lastDist[s] = 0;
            inq[s] = true;
            dq.addLast(s);
            while (!dq.isEmpty()) {
                int head = dq.removeFirst();
                inq[head] = false;
                for (IntegerCostFlowEdge e : g[head]) {
                    if (DigitUtils.equal(e.rev.flow, 0) || lastDist[e.to] <= lastDist[head] + e.cost) {
                        continue;
                    }
                    lastDist[e.to] = lastDist[head] + e.cost;
                    if (!inq[e.to]) {
                        inq[e.to] = true;
                        dq.addLast(e.to);
                    }
                }
            }
        }

        private void dijkstra(int s) {
            int n = g.length;
            for (int i = 0; i < n; i++) {
                curDist[i] = INF;
                prev[i] = null;
                inq[i] = false;
            }
            curDist[s] = 0;

            for (int i = 0; i < n; i++) {
                int head = -1;
                for (int j = 0; j < n; j++) {
                    if (!inq[j] && (head == -1 || curDist[j] < curDist[head])) {
                        head = j;
                    }
                }
                if (curDist[head] >= INF) {
                    break;
                }
                inq[head] = true;
                for (IntegerCostFlowEdge e : g[head]) {
                    int dist;
                    if (e.rev.flow == 0 || curDist[e.to] <= (dist = curDist[head] + e.cost - lastDist[e.to] + lastDist[head])) {
                        continue;
                    }
                    prev[e.to] = e.rev;
                    curDist[e.to] = dist;
                }
            }

            for (int i = 0; i < n; i++) {
                lastDist[i] = Math.min(curDist[i] + lastDist[i], INF);
            }
        }

        public int[] apply(List<IntegerCostFlowEdge>[] net, int s, int t, int send) {
            this.g = net;
            bf(s);
            int flow = 0;
            int cost = 0;
            while (flow < send) {
                dijkstra(s);
                if (prev[t] == null) {
                    break;
                }
                int remain = send - flow;
                for (IntegerCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {
                    remain = Math.min(remain, trace.flow);
                }
                int sumOfCost = 0;
                for (IntegerCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {
                    sumOfCost -= trace.cost;
                    IntegerFlow.send(trace, -remain);
                }
                cost += sumOfCost * -remain;
                flow += remain;
                callback.callback(remain, sumOfCost);
            }
            return new int[]{flow, cost};
        }

    }

    static interface IntegerStack {
        void addLast(int x);

        boolean isEmpty();

        void clear();

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static interface IntegerMinimumCostFlow {
    }

    static class IntegerCostFlowEdge extends IntegerFlowEdge<IntegerCostFlowEdge> {
        public int cost;

        public IntegerCostFlowEdge(int to, int flow, boolean real, int cost) {
            super(to, flow, real);
            this.cost = cost;
        }

    }

    static class IntegerDequeImpl implements IntegerDeque {
        private int[] data;
        private int bpos;
        private int epos;
        private static final int[] EMPTY = new int[0];
        private int n;

        public IntegerDequeImpl(int cap) {
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
            bpos = 0;
            epos = 0;
            n = cap;
        }

        private void expandSpace(int len) {
            while (n < len) {
                n = Math.max(n + 10, n * 2);
            }
            int[] newData = new int[n];
            if (bpos <= epos) {
                if (bpos < epos) {
                    System.arraycopy(data, bpos, newData, 0, epos - bpos);
                }
            } else {
                System.arraycopy(data, bpos, newData, 0, data.length - bpos);
                System.arraycopy(data, 0, newData, data.length - bpos, epos);
            }
            epos = size();
            bpos = 0;
            data = newData;
        }

        public IntegerIterator iterator() {
            return new IntegerIterator() {
                int index = bpos;

                public boolean hasNext() {
                    return index != epos;
                }

                public int next() {
                    int ans = data[index];
                    index = IntegerDequeImpl.this.next(index);
                    return ans;
                }
            };
        }

        public int removeFirst() {
            int ans = data[bpos];
            bpos = next(bpos);
            return ans;
        }

        public void addLast(int x) {
            ensureMore();
            data[epos] = x;
            epos = next(epos);
        }

        public void clear() {
            bpos = epos = 0;
        }

        private int next(int x) {
            return x + 1 >= n ? 0 : x + 1;
        }

        private void ensureMore() {
            if (next(epos) == bpos) {
                expandSpace(n + 1);
            }
        }

        public int size() {
            int ans = epos - bpos;
            if (ans < 0) {
                ans += data.length;
            }
            return ans;
        }

        public boolean isEmpty() {
            return bpos == epos;
        }

        public String toString() {
            StringBuilder builder = new StringBuilder();
            for (IntegerIterator iterator = iterator(); iterator.hasNext(); ) {
                builder.append(iterator.next()).append(' ');
            }
            return builder.toString();
        }

    }

    static interface IntegerAugmentCallback {
        public static IntegerAugmentCallback NIL = (a, b) -> {
        };

        public void callback(int flow, int pathCost);

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static boolean equal(int a, int b) {
            return a == b;
        }

    }

    static class DirectedEdge {
        public int to;

        public DirectedEdge(int to) {
            this.to = to;
        }

        public String toString() {
            return "->" + to;
        }

    }

    static class IntegerFlow {
        public static <T extends IntegerFlowEdge> void send(T edge, int flow) {
            edge.flow += flow;
            edge.rev.flow -= flow;
        }

        public static IntegerCostFlowEdge addCostEdge(List<IntegerCostFlowEdge>[] g, int s, int t, int cap, int cost) {
            IntegerCostFlowEdge real = new IntegerCostFlowEdge(t, 0, true, cost);
            IntegerCostFlowEdge virtual = new IntegerCostFlowEdge(s, cap, false, -cost);
            real.rev = virtual;
            virtual.rev = real;
            g[s].add(real);
            g[t].add(virtual);
            return real;
        }

        public static List<IntegerCostFlowEdge>[] createCostFlow(int n) {
            return createGraph(n);
        }

        private static List[] createGraph(int n) {
            return IntStream.range(0, n).mapToObj(i -> new ArrayList<>()).toArray(i -> new List[i]);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(double c) {
            cache.append(new BigDecimal(c).toPlainString());
            return this;
        }

        public FastOutput println(double c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class LinearFunction {
        int l;
        long a;
        long b;

        public LinearFunction(int l, long a, long b) {
            this.l = l;
            this.a = a;
            this.b = b;
        }

        long getL() {
            return a * l + b;
        }

        double getX(double y) {
            return (y - b) / a;
        }

    }

    static class IntegerFlowEdge<T extends IntegerFlowEdge<T>> extends DirectedEdge {
        public int flow;
        public boolean real;
        public T rev;

        public IntegerFlowEdge(int to, int flow, boolean real) {
            super(to);
            this.flow = flow;
            this.real = real;
        }

        public String toString() {
            return rev.to + "-[" + flow + "/" + (flow + rev.flow) + "]->" + to;
        }

    }

    static interface IntegerIterator {
        boolean hasNext();

        int next();

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.stream.IntStream;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            GCowAndExercise solver = new GCowAndExercise();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class GCowAndExercise {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();
            MakeDistanceFarthest mdf = new MakeDistanceFarthest(n);
            for (int i = 0; i < m; i++) {
                mdf.addEdge(in.readInt() - 1, in.readInt() - 1, in.readInt(), 1);
            }
            mdf.solve(new LongDijkstraV2MinimumCostFlow(n), 0, n - 1);
            int q = in.readInt();
            for (int i = 0; i < q; i++) {
                int x = in.readInt();
                double ans = mdf.query(x);
                out.println(ans);
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static interface IntegerIterator {
        boolean hasNext();

        int next();

    }

    static class LongCostFlowEdge extends LongFlowEdge<LongCostFlowEdge> {
        public long cost;

        public LongCostFlowEdge(int to, long flow, boolean real, long cost) {
            super(to, flow, real);
            this.cost = cost;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static boolean equal(long a, long b) {
            return a == b;
        }

    }

    static class DirectedEdge {
        public int to;

        public DirectedEdge(int to) {
            this.to = to;
        }

        public String toString() {
            return "->" + to;
        }

    }

    static interface LongMinimumCostFlow {
        long[] apply(List<LongCostFlowEdge>[] net, int s, int t, long send);

    }

    static class MakeDistanceFarthest {
        private List<LongCostFlowEdge>[] g;
        MakeDistanceFarthest.LinearFunction[] fs;

        public MakeDistanceFarthest(int n) {
            g = LongFlow.createCostFlow(n);
        }

        public void addEdge(int u, int v, long len, long cost) {
            LongFlow.addCostEdge(g, u, v, cost, len);
            LongFlow.addCostEdge(g, v, u, cost, len);
        }

        public void solve(LongAugmentMinimumCostFlow mcf, int s, int t) {
            List<MakeDistanceFarthest.LinearFunction> list = new ArrayList<>();
            LongAugmentCallback callback = new LongAugmentCallback() {
                long sumFlow = 0;
                long sumCost = 0;

                public void callback(long flow, long pathCost) {
                    sumFlow += flow;
                    sumCost += flow * pathCost;

                    if (!list.isEmpty() && list.get(list.size() - 1).l == pathCost) {
                        list.remove(list.size() - 1);
                    }
                    MakeDistanceFarthest.LinearFunction func = new MakeDistanceFarthest.LinearFunction(pathCost, sumFlow, -sumCost);
                    list.add(func);
                }
            };
            mcf.setCallback(callback);
            mcf.apply(g, s, t, Long.MAX_VALUE / 4);
            fs = list.toArray(new MakeDistanceFarthest.LinearFunction[0]);
        }

        public double query(double x) {
            int l = 0;
            int r = fs.length - 1;
            while (l < r) {
                int mid = (l + r) / 2;
                boolean valid = mid + 1 >= fs.length ||
                        fs[mid + 1].getL() > x;
                if (valid) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            return fs[l].getX(x);
        }

        private static class LinearFunction {
            long l;
            long a;
            long b;

            public LinearFunction(long l, long a, long b) {
                this.l = l;
                this.a = a;
                this.b = b;
            }

            long getL() {
                return a * l + b;
            }

            double getX(double y) {
                return (y - b) / a;
            }

        }

    }

    static class LongFlowEdge<T extends LongFlowEdge<T>> extends DirectedEdge {
        public long flow;
        public boolean real;
        public T rev;

        public LongFlowEdge(int to, long flow, boolean real) {
            super(to);
            this.flow = flow;
            this.real = real;
        }

        public String toString() {
            return rev.to + "-[" + flow + "/" + (flow + rev.flow) + "]->" + to;
        }

    }

    static interface IntegerStack {
        void addLast(int x);

        boolean isEmpty();

        void clear();

    }

    static interface LongAugmentMinimumCostFlow extends LongMinimumCostFlow {
        public void setCallback(LongAugmentCallback callback);

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(double c) {
            cache.append(new BigDecimal(c).toPlainString());
            return this;
        }

        public FastOutput println(double c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static interface LongAugmentCallback {
        public static LongAugmentCallback NIL = (a, b) -> {
        };

        public void callback(long flow, long pathCost);

    }

    static class LongFlow {
        public static <T extends LongFlowEdge> void send(T edge, long flow) {
            edge.flow += flow;
            edge.rev.flow -= flow;
        }

        public static LongCostFlowEdge addCostEdge(List<LongCostFlowEdge>[] g, int s, int t, long cap, long cost) {
            LongCostFlowEdge real = new LongCostFlowEdge(t, 0, true, cost);
            LongCostFlowEdge virtual = new LongCostFlowEdge(s, cap, false, -cost);
            real.rev = virtual;
            virtual.rev = real;
            g[s].add(real);
            g[t].add(virtual);
            return real;
        }

        public static List<LongCostFlowEdge>[] createCostFlow(int n) {
            return createGraph(n);
        }

        private static List[] createGraph(int n) {
            return IntStream.range(0, n).mapToObj(i -> new ArrayList<>()).toArray(i -> new List[i]);
        }

    }

    static class IntegerDequeImpl implements IntegerDeque {
        private int[] data;
        private int bpos;
        private int epos;
        private static final int[] EMPTY = new int[0];
        private int n;

        public IntegerDequeImpl(int cap) {
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
            bpos = 0;
            epos = 0;
            n = cap;
        }

        private void expandSpace(int len) {
            while (n < len) {
                n = Math.max(n + 10, n * 2);
            }
            int[] newData = new int[n];
            if (bpos <= epos) {
                if (bpos < epos) {
                    System.arraycopy(data, bpos, newData, 0, epos - bpos);
                }
            } else {
                System.arraycopy(data, bpos, newData, 0, data.length - bpos);
                System.arraycopy(data, 0, newData, data.length - bpos, epos);
            }
            epos = size();
            bpos = 0;
            data = newData;
        }

        public IntegerIterator iterator() {
            return new IntegerIterator() {
                int index = bpos;

                public boolean hasNext() {
                    return index != epos;
                }

                public int next() {
                    int ans = data[index];
                    index = IntegerDequeImpl.this.next(index);
                    return ans;
                }
            };
        }

        public int removeFirst() {
            int ans = data[bpos];
            bpos = next(bpos);
            return ans;
        }

        public void addLast(int x) {
            ensureMore();
            data[epos] = x;
            epos = next(epos);
        }

        public void clear() {
            bpos = epos = 0;
        }

        private int next(int x) {
            return x + 1 >= n ? 0 : x + 1;
        }

        private void ensureMore() {
            if (next(epos) == bpos) {
                expandSpace(n + 1);
            }
        }

        public int size() {
            int ans = epos - bpos;
            if (ans < 0) {
                ans += data.length;
            }
            return ans;
        }

        public boolean isEmpty() {
            return bpos == epos;
        }

        public String toString() {
            StringBuilder builder = new StringBuilder();
            for (IntegerIterator iterator = iterator(); iterator.hasNext(); ) {
                builder.append(iterator.next()).append(' ');
            }
            return builder.toString();
        }

    }

    static class LongDijkstraV2MinimumCostFlow implements LongAugmentMinimumCostFlow {
        private int m;
        private long[] lastDist;
        private long[] curDist;
        private LongCostFlowEdge[] prev;
        private boolean[] inq;
        private IntegerDeque dq;
        private static final long INF = Long.MAX_VALUE / 4;
        private List<LongCostFlowEdge>[] g;
        private LongAugmentCallback callback = LongAugmentCallback.NIL;

        public void setCallback(LongAugmentCallback callback) {
            this.callback = callback;
        }

        public LongDijkstraV2MinimumCostFlow(int m) {
            this.m = m - 1;
            lastDist = new long[m];
            curDist = new long[m];
            prev = new LongCostFlowEdge[m];
            inq = new boolean[m];
            dq = new IntegerDequeImpl(m);
        }

        private void bf(int s) {
            int n = g.length;
            dq.clear();
            for (int i = 0; i < n; i++) {
                lastDist[i] = INF;
                inq[i] = false;
            }
            lastDist[s] = 0;
            inq[s] = true;
            dq.addLast(s);
            while (!dq.isEmpty()) {
                int head = dq.removeFirst();
                inq[head] = false;
                for (LongCostFlowEdge e : g[head]) {
                    if (DigitUtils.equal(e.rev.flow, 0) || lastDist[e.to] <= lastDist[head] + e.cost) {
                        continue;
                    }
                    lastDist[e.to] = lastDist[head] + e.cost;
                    if (!inq[e.to]) {
                        inq[e.to] = true;
                        dq.addLast(e.to);
                    }
                }
            }
        }

        private void dijkstra(int s) {
            int n = g.length;
            for (int i = 0; i < n; i++) {
                curDist[i] = INF;
                prev[i] = null;
                inq[i] = false;
            }
            curDist[s] = 0;

            for (int i = 0; i < n; i++) {
                int head = -1;
                for (int j = 0; j < n; j++) {
                    if (!inq[j] && (head == -1 || curDist[j] < curDist[head])) {
                        head = j;
                    }
                }
                if (curDist[head] >= INF) {
                    break;
                }
                inq[head] = true;
                for (LongCostFlowEdge e : g[head]) {
                    long dist;
                    if (e.rev.flow == 0 || curDist[e.to] <= (dist = curDist[head] + e.cost - lastDist[e.to] + lastDist[head])) {
                        continue;
                    }
                    prev[e.to] = e.rev;
                    curDist[e.to] = dist;
                }
            }

            for (int i = 0; i < n; i++) {
                lastDist[i] = Math.min(curDist[i] + lastDist[i], INF);
            }
        }

        public long[] apply(List<LongCostFlowEdge>[] net, int s, int t, long send) {
            this.g = net;
            bf(s);
            long flow = 0;
            long cost = 0;
            while (flow < send) {
                dijkstra(s);
                if (prev[t] == null) {
                    break;
                }
                long remain = send - flow;
                for (LongCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {
                    remain = Math.min(remain, trace.flow);
                }
                long sumOfCost = 0;
                for (LongCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {
                    sumOfCost -= trace.cost;
                    LongFlow.send(trace, -remain);
                }
                cost += sumOfCost * -remain;
                flow += remain;
                callback.callback(remain, sumOfCost);
            }
            return new long[]{flow, cost};
        }

    }

    static interface IntegerDeque extends IntegerStack {
        int removeFirst();

    }
}


import java.io.*;
import java.util.*;

public class E {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	int n;
	int[] p;
	int[] sz;
	int[] who;

	int[] to;
	int[] head;
	int[] next;

	void addEdge(int v, int u, int idx) {
		to[idx] = u;
		next[idx] = head[v];
		head[v] = idx;
	}

	boolean cool(int a, int b, int c, int d) {
		boolean[] can = new boolean[n];
		can[0] = true;

		int base = 0;

		for (int v = p[a]; v != 0; v = p[v]) {
			base++; // need to take this edge

			for (int e = head[v]; e >= 0; e = next[e]) {
				int u = to[e];
				if (who[u] == a) {
					// System.err.println(v + " a " + u);
					continue;
				}

				int nowSz = 2 * sz[u];

				for (int i = can.length - 1; i >= nowSz; i--) {
					can[i] |= can[i - nowSz];
				}
			}
		}

		for (int v = p[b]; v != 0; v = p[v]) {
			base++; // need to take this edge

			for (int e = head[v]; e >= 0; e = next[e]) {
				int u = to[e];
				if (who[u] == b) {
					// System.err.println(v + " b " + u);
					continue;
				}

				int nowSz = 2 * sz[u];

				for (int i = can.length - 1; i >= nowSz; i--) {
					can[i] |= can[i - nowSz];
				}
			}
		}

		int szC = -1;
		int szD = -1;
		for (int e = head[0]; e >= 0; e = next[e]) {
			int u = to[e];
			if (who[u] == c) {
				szC = 2 * sz[u];
			} else if (who[u] == d) {
				szD = 2 * sz[u];
			} else if (who[u] == -1) {
				int nowSz = 2 * sz[u];
				for (int i = can.length - 1; i >= nowSz; i--) {
					can[i] |= can[i - nowSz];
				}
			}
		}

		if (szC == -1 || szD == -1) {
			throw new AssertionError();
		}

		base += 2 + szC; // edges from root and C

		// System.err.println(Arrays.toString(can));
		// System.err.println(base);
		// System.err.println(szC + " " + szD);

		int need = n - 1 - base;

		if (need < 0 || need >= can.length || !can[need]) {
			return false;
		}

		return true;
	}

	void solve() throws IOException {
		n = nextInt();
		int a = nextInt() - 1;
		int b = nextInt() - 1;
		int c = nextInt() - 1;
		int d = nextInt() - 1;

		head = new int[n];
		Arrays.fill(head, -1);
		to = new int[n - 1];
		next = new int[n - 1];

		p = new int[n];
		p[0] = -1;
		for (int i = 1; i < n; i++) {
			p[i] = nextInt() - 1;
			addEdge(p[i], i, i - 1);
		}

		sz = new int[n];
		who = new int[n];

		Arrays.fill(who, -1);
		who[a] = a;
		who[b] = b;
		who[c] = c;
		who[d] = d;

		Arrays.fill(sz, 1);
		for (int i = n - 1; i >= 1; i--) {
			sz[p[i]] += sz[i];
			if (who[i] != -1) {
				who[p[i]] = who[i];
			}
		}

		out.println(cool(a, b, c, d) && cool(c, d, a, b) ? "YES" : "NO");

	}

	E() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new E();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


//package tinkoff2017.e;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class E2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] a = na(4);
		for(int i = 0;i < 4;i++){
			a[i]--;
		}
		int[] par = new int[n];
		par[0] = -1;
		for(int i = 1;i <n;i++){
			par[i] = ni()-1;
		}
		int[][] g = parentToG(par);
		int[][] pars = parents3(g, 0);
		int[] ord = pars[1];
		boolean[][] dp = new boolean[n][];
		int[] dom = new int[n];
		Arrays.fill(dom, -1);
		int[] des = new int[n];
		des[0]++;
		outer:
		for(int i = n-1;i >= 1;i--){
			int cur = ord[i];
			des[cur]++;
			des[par[cur]] += des[cur];
			for(int j = 0;j < 4;j++){
				if(a[j] == cur){
					dom[cur] = j;
					dp[cur] = new boolean[]{true};
					continue outer;
				}
			}
			int dome = -1;
			for(int e : g[cur]){
				if(par[cur] == e)continue;
				if(dom[e] != -1){
					dom[cur] = dom[e];
					dome = e;
					break;
				}
			}
			if(dom[cur] == -1)continue;
			dp[cur] = new boolean[2*des[cur]-1];
			for(int j = 0;j < dp[dome].length;j++){
				dp[cur][j+1] = dp[dome][j];
			}
			for(int e : g[cur]){
				if(par[cur] == e)continue;
				if(dome == e)continue;
				for(int j = dp[cur].length-1-(des[e]+1);j >= 0;j--){
					dp[cur][j+des[e]+1] |= dp[cur][j];
				}
			}
//			tr(dom[cur]);
//			tf(dp[cur]);
		}
//		tr(dom);

		boolean[] ep = new boolean[n+1];
		ep[0] = true;
		boolean[][] dps = new boolean[4][];
		int[] fa = new int[4];
		for(int e : g[0]){
			if(dom[e] == -1){
				for(int j = n;j >= 2*des[e];j--){
					ep[j] |= ep[j-2*des[e]];
				}
			}else{
				dps[dom[e]] = dp[e];
				fa[dom[e]] = dp[e].length;
			}
		}
		// a c b d
		{
			boolean[] canab = new boolean[n+1];
			for(int i = 0;i < dps[0].length;i++){
				for(int j = 0;j < dps[1].length;j++){
					if(dps[0][i] && dps[1][j]){
						int len = n-2-(dps[0].length-i-1 + j + 1) - (fa[2]+1);
						if(len >= 0)canab[len] = true;
					}
				}
			}
			boolean[] cancd = new boolean[n+1];
			for(int i = 0;i < dps[2].length;i++){
				for(int j = 0;j < dps[3].length;j++){
					if(dps[2][i] && dps[3][j]){
						int len = n-2-(dps[2].length-i-1 + j + 1) - (fa[1]+1);
						if(len >= 0)cancd[len] = true;
					}
				}
			}
			for(int i = 0;i <= n;i++){
				for(int j = 0;j <= n;j++){
					if(ep[i] && ep[j] && canab[i] && cancd[j]){
						out.println("YES");
						return;
					}
				}
			}
		}
		{
			boolean[] canab = new boolean[n+1];
			for(int i = 0;i < dps[0].length;i++){
				for(int j = 0;j < dps[1].length;j++){
					if(dps[0][i] && dps[1][j]){
						int len = n-2-(dps[0].length-i-1 + j + 1) - (fa[3]+1);
						if(len >= 0)canab[len] = true;
					}
				}
			}
			boolean[] cancd = new boolean[n+1];
			for(int i = 0;i < dps[3].length;i++){
				for(int j = 0;j < dps[2].length;j++){
					if(dps[3][i] && dps[2][j]){
						int len = n-2-(dps[3].length-i-1 + j + 1) - (fa[1]+1);
						if(len >= 0)cancd[len] = true;
					}
				}
			}
			for(int i = 0;i <= n;i++){
				for(int j = 0;j <= n;j++){
					if(ep[i] && ep[j] && canab[i] && cancd[j]){
						out.println("YES");
						return;
					}
				}
			}
		}
		out.println("NO");
	}

	public static void tf(boolean... r)
	{
		for(boolean x : r)System.out.print(x?'#':'.');
		System.out.println();
	}

	public static int[][] parents3(int[][] g, int root) {
		int n = g.length;
		int[] par = new int[n];
		Arrays.fill(par, -1);

		int[] depth = new int[n];
		depth[0] = 0;

		int[] q = new int[n];
		q[0] = root;
		for (int p = 0, r = 1; p < r; p++) {
			int cur = q[p];
			for (int nex : g[cur]) {
				if (par[cur] != nex) {
					q[r++] = nex;
					par[nex] = cur;
					depth[nex] = depth[cur] + 1;
				}
			}
		}
		return new int[][] { par, q, depth };
	}

	public static int[][] parentToG(int[] par)
	{
		int n = par.length;
		int[] ct = new int[n];
		for(int i = 0;i < n;i++){
			if(par[i] >= 0){
				ct[i]++;
				ct[par[i]]++;
			}
		}
		int[][] g = new int[n][];
		for(int i = 0;i < n;i++){
			g[i] = new int[ct[i]];
		}
		for(int i = 0;i < n;i++){
			if(par[i] >= 0){
				g[par[i]][--ct[par[i]]] = i;
				g[i][--ct[i]] = par[i];
			}
		}
		return g;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new E2().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.*;
import java.util.*;

public class E {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	int n;
	int[] p;
	int[] sz;
	int[] who;

	int[] to;
	int[] head;
	int[] next;

	void addEdge(int v, int u, int idx) {
		to[idx] = u;
		next[idx] = head[v];
		head[v] = idx;
	}

	boolean cool(int a, int b, int c, int d) {
		boolean[] can = new boolean[n];
		can[0] = true;

		int base = 0;

		for (int v = p[a]; v != 0; v = p[v]) {
			base++; // need to take this edge

			for (int e = head[v]; e >= 0; e = next[e]) {
				int u = to[e];
				if (who[u] == a) {
					// System.err.println(v + " a " + u);
					continue;
				}

				int nowSz = 2 * sz[u];

				for (int i = can.length - 1; i >= nowSz; i--) {
					can[i] |= can[i - nowSz];
				}
			}
		}

		for (int v = p[b]; v != 0; v = p[v]) {
			base++; // need to take this edge

			for (int e = head[v]; e >= 0; e = next[e]) {
				int u = to[e];
				if (who[u] == b) {
					// System.err.println(v + " b " + u);
					continue;
				}

				int nowSz = 2 * sz[u];

				for (int i = can.length - 1; i >= nowSz; i--) {
					can[i] |= can[i - nowSz];
				}
			}
		}

		int szC = -1;
		int szD = -1;
		for (int e = head[0]; e >= 0; e = next[e]) {
			int u = to[e];
//			System.err.println(who[u]);
			if (who[u] == c) {
				szC = 2 * sz[u];
			} else if (who[u] == d) {
				szD = 2 * sz[u];
			} else if (who[u] == -1) {
				int nowSz = 2 * sz[u];
				for (int i = can.length - 1; i >= nowSz; i--) {
					can[i] |= can[i - nowSz];
				}
			}
		}

		if (szC == -1 || szD == -1) {
			throw new AssertionError();
		}

		base += 2 + szC; // edges from root and C

		int need = n - 1 - base;

		if (need < 0 || need >= can.length || !can[need]) {
			return false;
		}

		return true;
	}

	void solve() throws IOException {
		n = nextInt();
		int a = nextInt() - 1;
		int b = nextInt() - 1;
		int c = nextInt() - 1;
		int d = nextInt() - 1;

		head = new int[n];
		Arrays.fill(head, -1);
		to = new int[n - 1];
		next = new int[n - 1];

		p = new int[n];
		p[0] = -1;
		for (int i = 1; i < n; i++) {
			p[i] = nextInt() - 1;
			addEdge(p[i], i, i - 1);
		}

		sz = new int[n];
		who = new int[n];

		Arrays.fill(who, -1);
		who[a] = a;
		who[b] = b;
		who[c] = c;
		who[d] = d;

		Arrays.fill(sz, 1);
		for (int i = n - 1; i >= 1; i--) {
			sz[p[i]] += sz[i];
			if (who[i] != -1) {
				if (who[p[i]] != -1 && p[i] != 0) {
					throw new AssertionError();
				}
				who[p[i]] = who[i];
			}
		}

		out.println(cool(a, b, c, d) && cool(c, d, a, b) ? "YES" : "NO");

	}

	E() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new E();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}