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.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;

public class Coding {

    private static BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
    private static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) {
        try {
            run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void run() throws Exception {
        InputModule inp = new InputModule();
        OutputModule out = new OutputModule();
        int t = 1;
        while (t > 0) {
            int n = inp.cinInt();
            int[] ar = inp.cinIntArray(n);
            Map<Integer, Integer> fre = new HashMap<>();
            for (int i = 0; i < n; ++i) {
                fre.put(ar[i], fre.getOrDefault(ar[i], 0) + 1);
            }
            List<Integer>[] adj = new ArrayList[n];
            for (int i = 0; i < n; ++i) adj[i] = new ArrayList<>();
            for (int i = 1; i <= n - 1; ++i) {
                int[] ints = inp.cinIntArray(2);
                int a = ints[0] - 1;
                int b = ints[1] - 1;
                adj[a].add(b);
                adj[b].add(a);
            }
            long[] path = new long[n];
            int[] vis = new int[n];
            long[] childs = new long[n];
            Map<Integer, Integer> child = new HashMap<>();
            for (int i = 0; i < n; ++i) {
                path[i] = vis[i] = 0;
                childs[i] = 0;
            }
            Map<Integer, Integer> par = new HashMap<>();
            Map<Integer, Integer> parWithoutCount = new HashMap<>();
            for (int i = 0; i < n; ++i) par.put(ar[i], -1);
            dfs(0, vis, path, par, child, childs, ar, adj, parWithoutCount);
            //out.printLongArray(path);
            //out.printLongArray(childs);
            par.clear();
            int ans = dfs2(0, vis, path, ar, adj, fre, parWithoutCount, childs, par);
            out.printInt(ans);
            t--;
        }
    }

    private static int dfs2(int cur, int[] vis, long[] path, int[] ar, List<Integer>[] adj,
                            Map<Integer, Integer> fre, Map<Integer, Integer> parWithoutCount,
                            long[] childs, Map<Integer, Integer> exists) {
        if (parWithoutCount.getOrDefault(ar[cur], 0) >= 2) return 0;
        if (exists.containsKey(ar[cur])) return 0;
        int ans = 0;
        int count = fre.get(ar[cur]);
        if (path[cur] == 0) {
            if (count == 1) ans++;
        }

        exists.put(ar[cur], cur);
        vis[cur] = 1;
        long childSum = 0;
        for (int i = 0; i < adj[cur].size(); ++i) {
            int nxt = adj[cur].get(i);
            if (vis[nxt] == 1) continue;
            childSum += path[nxt];
        }
        long current = path[cur] - childSum;
        for (int i = 0; i < adj[cur].size(); ++i) {
            int nxt = adj[cur].get(i);
            if (vis[nxt] == 1) continue;
            if ((path[nxt] == childSum) && (childs[nxt]==current)) {
                ans+=dfs2(nxt, vis, path, ar, adj, fre, parWithoutCount, childs, exists);
            }
        }
        vis[cur] = 0;
        exists.remove(ar[cur]);
        return ans;
    }

    private static void dfs(int cur, int[] vis, long[] path, Map<Integer, Integer> par,
                            Map<Integer, Integer> child, long[] childs, int[] ar,
                            List<Integer>[] adj, Map<Integer, Integer> parWithoutCount) {
        vis[cur] = 1;
        if (par.get(ar[cur]) != -1) {
            path[par.get(ar[cur])]++;
            childs[child.get(par.get(ar[cur]))]++;
        } else {
            parWithoutCount.put(ar[cur], parWithoutCount.getOrDefault(ar[cur], 0) + 1);
        }
        int parent = par.get(ar[cur]);
        par.put(ar[cur], cur);
        for (int i = 0; i < adj[cur].size(); ++i) {
            int nxt = adj[cur].get(i);
            if (vis[nxt] == 1) continue;
            child.put(cur, nxt);
            dfs(nxt, vis, path, par, child, childs, ar, adj, parWithoutCount);
            child.remove(cur);
        }
        for (int i = 0; i < adj[cur].size(); ++i) {
            int nxt = adj[cur].get(i);
            if (vis[nxt] == 1) continue;
            path[cur] += path[nxt];
        }
        vis[cur] = 0;
        par.put(ar[cur], parent);
    }


    private static class InputModule {
        private int cinInt() throws Exception {
            return Integer.parseInt(bi.readLine().split(" ")[0].trim());
        }

        private long cinLong() throws Exception {
            return Long.parseLong(bi.readLine().split(" ")[0].trim());
        }

        private Double cinDouble() throws Exception {
            return Double.parseDouble(bi.readLine().split(" ")[0].trim());
        }

        private String cinString() throws Exception {
            return bi.readLine();
        }

        private int[] cinIntArray(int n) throws Exception {
            String input = bi.readLine();
            String[] values = input.split(" ");
            int[] ar = new int[n];
            for (int i = 0; i < n; ++i) {
                ar[i] = Integer.parseInt(values[i]);
            }
            return ar;
        }

        private int[] cinIntArray() throws Exception {
            String input = bi.readLine();
            String[] values = input.split(" ");
            int[] ar = new int[values.length];
            for (int i = 0; i < values.length; ++i) {
                ar[i] = Integer.parseInt(values[i]);
            }
            return ar;
        }

        private long[] cinLongArray(int n) throws Exception {
            String input = bi.readLine();
            String[] values = input.split(" ");
            long[] ar = new long[n];
            for (int i = 0; i < n; ++i) {
                ar[i] = Long.parseLong(values[i]);
            }
            return ar;
        }

        private String[] cinStringArray(int n) throws Exception {
            return bi.readLine().split(" ");
        }
    }

    private static class OutputModule {
        private void printInt(int ans) throws Exception {
            writer.append(ans + "\n");
            writer.flush();
        }

        private void printLong(long ans) throws Exception {
            writer.append(ans + "\n");
            writer.flush();
        }

        private void printDouble(Double ans) throws Exception {
            writer.append(String.format("%.10f", ans));
            writer.append("\n");
            writer.flush();
        }

        private void printString(String ans) throws Exception {
            writer.append(ans + "\n");
            writer.flush();
        }

        private void printIntArray(int[] ans) throws Exception {
            for (int i = 0; i < ans.length; ++i) {
                writer.append(ans[i] + " ");
            }
            writer.append("\n");
            writer.flush();
        }

        private void printLongArray(long[] ans) throws Exception {
            for (int i = 0; i < ans.length; ++i) {
                writer.append(ans[i] + " ");
            }
            writer.append("\n");
            writer.flush();
        }

        private void printIntList(List<Integer> list) throws Exception {
            for (int i = 0; i < list.size(); ++i) {
                writer.append(list.get(i) + " ");
            }
            writer.append("\n");
            writer.flush();
        }

        private void printLongList(List<Long> list) throws Exception {
            for (int i = 0; i < list.size(); ++i) {
                writer.append(list.get(i) + " ");
            }
            writer.append("\n");
            writer.flush();
        }

        private void printIntMatrix(int[][] mat, int n, int m) throws Exception {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    writer.append(mat[i][j] + " ");
                }
                writer.append("\n");
            }
            writer.flush();
        }

        private void printLongMatrix(long[][] mat, int n, int m) throws Exception {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    writer.append(mat[i][j] + " ");
                }
                writer.append("\n");
            }
            writer.flush();
        }

        private void printPoint(Point p) throws Exception {
            writer.append(p.x + " " + p.y + "\n");
            writer.flush();
        }

        private void printPoints(List<Point> p) throws Exception {
            for (Point pp : p) {
                writer.append(pp.x + " " + pp.y + "\n");
            }
            writer.flush();
        }
    }
}