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);
            List<Point> sorted = new ArrayList<>();
            for (int i = 0; i < n; ++i) sorted.add(new Point(ar[i], i));
            Collections.sort(sorted, new Comparator<Point>() {
                @Override
                public int compare(Point o1, Point o2) {
                    return o1.x-o2.x;
                }
            });
            int cur = 0;
            ar[sorted.get(0).y] = 0;
            for (int i = 1; i < n; ++i) {
                if (sorted.get(i).x > sorted.get(i - 1).x) cur++;
                ar[sorted.get(i).y] = cur;
            }

            int[] fre = new int[n];
            for (int i = 0; i < n; ++i) {
                fre[ar[i]]++;
            }
            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);
            }
            int[] path = new int[n];
            int[] vis = new int[n];
            int[] childPaths = new int[n];
            boolean[] exists = new boolean[n];
            int[] parWithoutCount = new int[n];
            int[] child = new int[n];
            for (int i = 0; i < n; ++i) {
                path[i] = vis[i] = childPaths[i] = parWithoutCount[i] = 0;
                child[i] = -1;
                exists[i] = false;
            }
            int[] par = new int[n];
            for (int i = 0; i < n; ++i) par[ar[i]] = -1;
            dfs(0, vis, path, par, child, childPaths, ar, adj, parWithoutCount);
            //out.printIntArray(path);
            //out.printIntArray(childPaths);
            int ans = dfs2(0, vis, path, ar, adj, fre, parWithoutCount, childPaths, exists);
            out.printInt(ans);
            t--;
        }
    }

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

        exists[ar[cur]] = true;
        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[ar[cur]] = false;
        return ans;
    }

    private static void dfs(int cur, int[] vis, int[] path, int[] par,
                            int[] child, int[] childPaths, int[] ar,
                            List<Integer>[] adj, int[] parWithoutCount) {
        vis[cur] = 1;
        if (par[ar[cur]] != -1) {
            path[par[ar[cur]]]++;
            childPaths[child[par[ar[cur]]]]++;
        } else {
            parWithoutCount[ar[cur]]++;
        }
        int parent = par[ar[cur]];
        par[ar[cur]] = cur;
        for (int i = 0; i < adj[cur].size(); ++i) {
            int nxt = adj[cur].get(i);
            if (vis[nxt] == 1) continue;
            child[cur] = nxt;
            dfs(nxt, vis, path, par, child, childPaths, ar, adj, parWithoutCount);
            child[cur] = -1;
        }
        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[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();
        }
    }
}