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.
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <random>
#include <string>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;

#define pb push_back
#define ppp pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define stie std::tie
#define vec vector
#define forn(i, l, r) for (int i=l; i<=r; i++)
#define forb(i, r, l) for (int i=r; i>=l; i--)
#define emp empty
#define beg begin
#define ins insert
#define cle clear
#define era erase
#define que queue
#define pque priority_queue
#define mset multiset
#define deq deque
#define sta stack
#define con const
#define rsz resize
#define ass assign
#define lowb lower_bound
#define uppb upper_bound

template <class T> void mini(T& a, T b) { a = min(a, b); }
template <class T> void maxi(T& a, T b) { a = max(a, b); }
template <class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <class T1, class T2>
ostream& operator<<(ostream& os, pair<T1, T2> const& a) { return os << "[" << a.first << ", " << a.second << "]"; }
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, Container const& a) { os << "{ "; for (auto& i : a) os << i << " "; return os << "}"; }
template <class T> void out(T a) { cout << a << endl; }
template <class T, class... Args> void out(T a, Args... args) { cout << a << " "; out(args...); }
template <class T> void out( std::initializer_list<T> a) { for (auto i : a) { cout << i << " "; } cout << endl; }
template <class T> void out(vector<vector<T>> a) { for (vector<T> i : a) out(i); }
template <class T> void out_(T a[], int l, int r) { for (int i = l; i <= r; i++) cout << a[i] << " "; cout << endl; }
void out() { cout << "OK" << endl; }
template <class T> void sort(vector<T>& a) { sort(a.begin(), a.end()); }
template <class T> void rever(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T> void uniq(vector<T>& a) { sort(a); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> vector<T> set_int(vector<T> a, vector<T> b) { sort(a); sort(b); vector<T> res;
set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res)); return res; }
clock_t start_time; void start_timer() { start_time = clock(); }
double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }
#if __SIZEOF_INT128__ >= 16
typedef __int128 LL;
istream& operator>>(istream& in, __int128& a) { int64_t b; in >> b; a = b; return in; }
ostream& operator<<(ostream& out, const __int128 a) {
    unsigned __int128 b = a < 0 ? -a : a; char buf[128]; char* c = end(buf); do { --c; *c = "0123456789"[b % 10]; b /= 10; } while (b);
    if (a < 0) { --c; *c = '-'; } int64_t len = end(buf) - c; out.rdbuf()->sputn(c, len); return out;
}
#endif

// solve the problem or die trying
// do something, stay focused
// look for stupid bugs
// guess, slow, stress
// the solution is always simple

const int N = 2e5 + 5;
const int L = 21;

vector<int> g[N];
int sz[N];
int tin[N];
int tout[N];
int nxt[N];
int timer = 1;
int par[N];
int up[N][L];
// nxt[v] --- the highest vertex in the heavy path corresponding to v
// [tin[v]; tout[v]] --- subtree of v
// [tin[nxt[v]]; tin[v]] --- path from nxt[v] to v

void dfs_par(int v = 1, int p = 1) {
    par[v] = p;
    for (int u : g[v]) {
        if (u == p) continue;
        dfs_par(u, v);
    }
}

void dfs_sz(int v = 1) {
    sz[v] = 1;
    for (int& u : g[v]) {
        dfs_sz(u);
        sz[v] += sz[u];
        if (sz[u] > sz[g[v][0]]) {
            swap(u, g[v][0]);
        }
    }
}

void dfs_hld(int v = 1) {
    tin[v] = timer++;
    for (int u : g[v]) {
        nxt[u] = (u == g[v][0] ? nxt[v] : u);
        dfs_hld(u);
    }
    tout[v] = timer - 1;
}

void dfs_lca(int v = 1) {
    up[v][0] = par[v];
    for (int i = 1; i < L; i++) {
        up[v][i] = up[up[v][i - 1]][i - 1];
    }
    for (int u : g[v]) dfs_lca(u);
}

bool is_anc(int u, int v) {
    return tin[u] <= tin[v] && tin[v] <= tout[u];
}

int lca(int u, int v) {
    if (is_anc(u, v)) return u;
    if (is_anc(v, u)) return v;
    for (int i = L - 1; i >= 0; i--) {
        if (!is_anc(up[u][i], v)) u = up[u][i];
    }
    return up[u][0];
}

void init() {
    dfs_par();
    for (int i = 0; i < N; i++) {
        vector<int> cur;
        for (int u : g[i]) {
            if (u != par[i]) cur.push_back(u);
        }
        g[i] = cur;
    }
    dfs_sz();
    dfs_hld();
    dfs_lca();
}

vec<int> all;
map<int, int> Map;
int a[N];
set<int> b[N];
vec<int> whe[N];
int LCA[N];
int cnt[N];
int ans;
bool good[N];
vec<int> to[N];

void dfs1(int v = 1) {
    good[v] = 1;
    for (int u : g[v]) {
        dfs1(u);
        if (!good[u] || b[u].count(a[v])) {
            to[v].pb(u);
            good[v] = 0;
        }
        if (b[v].size() < b[u].size()) {
            swap(b[v], b[u]);
        }
        for (int i : b[u]) {
            b[v].ins(i);
        }
    }
    b[v].ins(a[v]);
}

void dfs2(int v = 1) {
    if (cnt[a[v]] == 1 && good[v]) {
        ans++;
    }
    
    if (to[v].size() >= 2) return;
    if (v != LCA[a[v]]) return;
    if (to[v].size() == 1) {
        dfs2(to[v][0]);
    }
    else {
        for (int u : g[v]) {
            dfs2(u);
        }
    }
}

void Solve() {
    int n;
    cin >> n;
    forn(i, 1, n) {
        cin >> a[i];
        all.pb(a[i]);
    }
    forn(i, 1, n - 1) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    init();
    uniq(all);
    forn(i, 0, all.size() - 1) {
        Map[all[i]] = i;
    }
    forn(i, 1, n) {
        a[i] = Map[a[i]];
        whe[a[i]].pb(i);
        cnt[a[i]]++;
    }
    forn(i, 0, N-1) {
        if (whe[i].emp()) continue;
        LCA[i] = whe[i][0];
        for (int j : whe[i]) {
            LCA[i] = lca(LCA[i], j);
        }
    }
    dfs1();
    dfs2();
    out(ans);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("usr/share/man/man1/input.txt", "r", stdin);
#endif
    start_timer();
    Solve();
    return 0;
}
