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.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

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

    static class EDistinctiveRootsInATree {
        static int n;
        static int[] a;
        static int[] sz;
        static boolean[] distinct;
        static boolean[] distup;
        static ArrayList<Integer>[] graph;
        static HashMap<Integer, Integer> cur;

        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            n = sc.nextInt();
            a = sc.nextIntArr(n);
            sz = new int[n];
            distinct = new boolean[n];
            distup = new boolean[n];
            graph = new ArrayList[n];
            cur = new HashMap<>();
            for (int i = 0; i < n; i++) {
                graph[i] = new ArrayList<>();
//            vals.put(a[i], vals.getOrDefault(a[i], 0)+1);
                distup[i] = true;
            }
            for (int i = 0; i < n - 1; i++) {
                int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
                graph[u].add(v);
                graph[v].add(u);
            }
            dfs0(0, -1);
            dfs1(0, -1);
//        System.out.println(Arrays.toString(distinct));
//        dfs2(0,-1, false);
            dfs3(0, -1, cur);
//        System.out.println(Arrays.toString(distup));
            int ans = 0;
            for (int i = 0; i < n; i++)
                if (distinct[i] && distup[i])
                    ans++;
            out.println(ans);
        }

        private void dfs3(int u, int p, HashMap<Integer, Integer> cur) {
            if (p != -1 && (!distup[p] || cur.containsKey(a[u]) || cur.get(a[p]) > 1))
                distup[u] = false;
            int notdist = 0;
            for (int v : graph[u])
                if (v != p && !distinct[v])
                    notdist++;
            for (int v : graph[u])
                if (v != p && (notdist - (!distinct[v] ? 1 : 0)) > 0)
                    distup[v] = false;
            int bigChild = -1;
//        System.out.println(u+" "+cur.toString());
            cur.put(a[u], cur.getOrDefault(a[u], 0) + 1);
            for (int v : graph[u])
                if (v != p && (bigChild == -1 || sz[bigChild] < sz[v]))
                    bigChild = v;
            for (int v : graph[u])
                if (v != p && v != bigChild)
                    remadd(v, u, 1);
            if (bigChild != -1)
                dfs3(bigChild, u, cur);
            for (int v : graph[u])
                if (v != p && v != bigChild) {
                    remadd(v, u, 0);
                    dfs3(v, u, cur);
                }

        }

        private void remadd(int u, int p, int mode) {
            if (mode == 0) {
                if (cur.get(a[u]) == 1)
                    cur.remove(a[u]);
                else
                    cur.put(a[u], cur.get(a[u]) - 1);
            } else
                cur.put(a[u], cur.getOrDefault(a[u], 0) + 1);
            for (int v : graph[u])
                if (v != p) {
                    remadd(v, u, mode);
                }
        }

        private void dfs0(int u, int p) {
            sz[u] = 1;
            for (int v : graph[u])
                if (v != p) {
                    dfs0(v, u);
                    sz[u] += sz[v];
                }
        }

        private HashSet<Integer> dfs1(int u, int p) {
            distinct[u] = true;

            int bigChild = -1;
            for (int v : graph[u])
                if (v != p && (bigChild == -1 || sz[bigChild] < sz[v]))
                    bigChild = v;
            HashSet<Integer> cur = bigChild == -1 ? new HashSet<>() : dfs1(bigChild, u);
            for (int v : graph[u])
                if (v != p && v != bigChild) {
                    HashSet<Integer> tmp = dfs1(v, u);
                    if (!distinct[v])
                        distinct[u] = false;
                    for (int x : tmp)
                        cur.add(x);
                }
            if (bigChild != -1 && !distinct[bigChild])
                distinct[u] = false;
            if (cur.contains(a[u]))
                distinct[u] = false;
            cur.add(a[u]);
            return cur;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

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

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

        public int[] nextIntArr(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

    }
}

