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.Arrays;
import java.util.InputMismatchException;
import java.util.HashMap;
import java.io.IOException;
import java.util.ArrayList;
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 << 27);
        thread.start();
        thread.join();
    }

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

    static class EDistinctiveRootsInATree {
        ArrayList<Integer>[] a;
        int[] val;
        int[] cnt;
        int[] curCnt;
        int[] par;
        int[] dp;
        int res;
        HashMap<pair<Integer, Integer>, Integer> edges = new HashMap<>();

        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt();
            a = new ArrayList[n];
            int[] unique = new int[n];
            val = new int[n];
            cnt = new int[n];
            curCnt = new int[n];
            par = new int[n];
            dp = new int[n];
            for (int i = 0; i < n; i++) {
                val[i] = unique[i] = s.nextInt();
                a[i] = new ArrayList<>();
            }
            unique = func.unique(unique);
            for (int i = 0; i < n; i++) {
                val[i] = func.bin(unique, 0, unique.length - 1, val[i]);
                cnt[val[i]]++;
            }
            for (int i = 1; i < n; i++) {
                int u = s.nextInt() - 1, v = s.nextInt() - 1;
                a[u].add(v);
                a[v].add(u);
            }

            dfs(0, -1);
            init(0, -1);
            calc(0, -1);
//        if (n == 5) for (Map.Entry<pair<Integer, Integer>, Integer> e:
//                edges.entrySet()) w.println(e.getKey());
            w.println(res);
        }

        void calc(int cur, int p) {
            if (dp[cur] == edges.size()) res++;
            for (int i : a[cur]) {
                if (i == p) continue;
                dp[cur] -= dp[i];
                dp[cur] -= edges.getOrDefault(new pair<>(i, cur), 0);
                dp[i] += dp[cur];
                dp[i] += edges.getOrDefault(new pair<>(cur, i), 0);

                calc(i, cur);

                dp[i] -= edges.getOrDefault(new pair<>(cur, i), 0);
                dp[i] -= dp[cur];
                dp[cur] += edges.getOrDefault(new pair<>(i, cur), 0);
                dp[cur] += dp[i];
            }
        }

        void init(int cur, int p) {
            for (int i : a[cur]) {
                if (i == p) continue;
                dp[cur] += edges.getOrDefault(new pair<>(i, cur), 0);
                init(i, cur);
                dp[cur] += dp[i];
            }
        }

        void dfs(int cur, int p) {
            par[cur] = p;
            int outsideSubtree = curCnt[val[cur]]++;
            for (int i : a[cur])
                if (i != p) {
                    int subtreeCount = curCnt[val[cur]];
                    dfs(i, cur);
                    subtreeCount = curCnt[val[cur]] - subtreeCount;
                    if (subtreeCount > 0) edges.put(new pair<>(cur, i), 1);
                }
            outsideSubtree += cnt[val[cur]] - curCnt[val[cur]];
            if (cur == 0 && outsideSubtree > 0)
                throw new RuntimeException(outsideSubtree + " Nop");
            if (outsideSubtree > 0) edges.put(new pair<>(cur, p), 1);
        }

    }

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

        public FastReader(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 c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }

    static class func {
        public static int bin(int[] a, int l, int r, int val) {
            int mid;
            while (l <= r) {
                mid = l + r >> 1;
                if (a[mid] == val) return mid;
                if (a[mid] > val) r = mid - 1;
                else l = mid + 1;
            }
            return -1;
        }

        public static void sort(int[] arr) {
            int n = arr.length, mid, h, s, l, i, j, k;
            int[] res = new int[n];
            n--;
            for (s = 1; s <= n; s <<= 1) {
                for (l = 0; l < n; l += (s << 1)) {
                    h = Math.min(l + (s << 1) - 1, n);
                    mid = Math.min(l + s - 1, n);
                    i = l;
                    j = mid + 1;
                    k = l;
                    while (i <= mid && j <= h)
                        res[k++] = arr[i] <= arr[j] ? arr[i++] : arr[j++];
                    while (i <= mid) res[k++] = arr[i++];
                    while (j <= h) res[k++] = arr[j++];
                    for (k = l; k <= h; k++) arr[k] = res[k];
                }
            }
        }

        public static int[] unique(int[] a) {
            int n = 0;
            sort(a);
            for (int i = 0; i < a.length; i++)
                if (i == 0 || a[i - 1] != a[i]) a[n++] = a[i];
            return Arrays.copyOfRange(a, 0, n);
        }

    }

    static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>> {
        public U x;
        public V y;

        public pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(pair<U, V> other) {
            int cmp = x.compareTo(other.x);
            return cmp == 0 ? y.compareTo(other.y) : cmp;
        }

        public String toString() {
            return x.toString() + " " + y.toString();
        }

        public boolean equals(Object obj) {
            if (this.getClass() != obj.getClass()) return false;
            pair<U, V> other = (pair<U, V>) obj;
            return x.equals(other.x) && y.equals(other.y);
        }

        public int hashCode() {
            return 31 * x.hashCode() + y.hashCode();
        }

    }
}

