You are given a tree with n vertices. Each vertex i has a value a_i associated with it.

Let us root the tree at some vertex v. The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some other node, all the values encountered are distinct. Two different paths may have values in common but a single path must have all distinct values.

Find the number of distinctive roots in the tree.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 2⋅10^5) — the number of vertices in the tree.

The next line contains n space-separated integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).

The following n-1 lines each contain two space-separated integers u and v (1 ≤ u, v ≤ n), denoting an edge from u to v.

It is guaranteed that the edges form a tree.

Output

Print a single integer — the number of distinctive roots in the tree.

Examples

Input


5
2 5 1 1 4
1 2
1 3
2 4
2 5


Output


3

Input


5
2 1 1 1 4
1 2
1 3
2 4
2 5


Output


0

Note

In the first example, 1, 2 and 5 are distinctive roots.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class EDistinctiveRootsInATree {
        int[] enc;
        int[] sub;
        int[] par;

        boolean dfs(int x, int p, HashSet<Integer>[] adj, int[] a, int[] cnt, int[] brk) {
            par[x] = p;
            int c = a[x];
            int ec = 0;
            if (cnt[c] > 0) {
                ec++;
                brk[x] = p;
            } else if (cnt[c] == 0) {
                enc[c] = x;
            }
            sub[x] = -cnt[c];
            cnt[c]++;
            for (int y : adj[x]) {
                if (y == p)
                    continue;
                int v = cnt[c];
                if (!dfs(y, x, adj, a, cnt, brk))
                    return false;
                if (cnt[c] > v) {
                    ec++;
                    brk[x] = y;
                }
            }
            sub[x] += cnt[c];
            if (ec > 1)
                return false;
            return true;
        }

        void dfs2(int x, int p, HashSet<Integer>[] adj, int[] vis) {
            vis[x] = 1;
            for (int y : adj[x]) {
                if (y == p)
                    continue;
                dfs2(y, x, adj, vis);
            }
        }

        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt();
            HashMap<Integer, Integer> hm = new HashMap<>();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = s.nextInt();
                if (!hm.containsKey(a[i]))
                    hm.put(a[i], hm.size());
            }
            for (int i = 0; i < n; i++)
                a[i] = hm.get(a[i]);
            int[] cnt = new int[n];
            int[] brk = new int[n];
            Arrays.fill(brk, -1);
            HashSet<Integer>[] adj = new HashSet[n];
            for (int i = 0; i < n; i++)
                adj[i] = new HashSet<>();
            for (int i = 0; i < n - 1; i++) {
                int u = s.nextInt() - 1, v = s.nextInt() - 1;
                adj[u].add(v);
                adj[v].add(u);
            }
            enc = new int[n];
            sub = new int[n];
            par = new int[n];
            Arrays.fill(enc, -1);
            Arrays.fill(par, -1);
            if (!dfs(0, -1, adj, a, cnt, brk)) {
                w.println(0);
                return;
            }
            for (int i = 0; i < n; i++) {
                if (enc[i] != -1 && sub[enc[i]] < cnt[i]) {
                    if (brk[enc[i]] != -1) {
                        w.println(0);
                        return;
                    }
                    brk[enc[i]] = par[enc[i]];
                }
            }
            int[] vis = new int[n];
            for (int i = 0; i < n; i++) {
                if (vis[i] == 0 && brk[i] != -1) {
                    if (adj[i].contains(brk[i]))
                        adj[i].remove(brk[i]);
                    if (adj[brk[i]].contains(i))
                        adj[brk[i]].remove(i);
                    dfs2(i, -1, adj, vis);
                }
            }
            int res = 0;
            for (int i = 0; i < n; i++)
                if (vis[i] == 0)
                    res++;
            w.println(res);
        }

    }

    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 int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        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 interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

