You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i.

Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex x to vertex y (including these two vertices). Also let's denote dist(x, y) as the number of vertices on the simple path between vertices x and y, including the endpoints. dist(x, x) = 1 for every vertex x.

Your task is calculate the maximum value of dist(x, y) among such pairs of vertices that g(x, y) > 1.

Input

The first line contains one integer n — the number of vertices (1 ≤ n ≤ 2 ⋅ 10^5).

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5) — the numbers written on vertices.

Then n - 1 lines follow, each containing two integers x and y (1 ≤ x, y ≤ n, x ≠ y) denoting an edge connecting vertex x with vertex y. It is guaranteed that these edges form a tree.

Output

If there is no pair of vertices x, y such that g(x, y) > 1, print 0. Otherwise print the maximum value of dist(x, y) among such pairs.

Examples

Input

3
2 3 4
1 2
2 3


Output

1


Input

3
2 3 4
1 3
2 3


Output

2


Input

3
1 1 1
1 2
2 3


Output

0
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class D {
    static MyScanner sc;
    static PrintWriter pw;

    public static void main(String[] args) throws Throwable {
        sc = new MyScanner();
        pw = new PrintWriter(System.out);

        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = sc.nextInt();
        adj = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adj[i] = new ArrayList<>();

        for (int i = 0; i < n - 1; i++) {
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;
            adj[u].add(v);
            adj[v].add(u);
        }

        map = new HashMap[n];
        for (int i = 0; i < n; i++)
            map[i] = new HashMap<>();
        sieve((int) 2e5 + 5);
        dfs(0, -1);

        pw.println(ans);

        pw.flush();
        pw.close();
    }

    static int ask(int u, int par, int p) {
        if (a[u] % p != 0)
            return 0;
        if (map[u].containsKey(p))
            return map[u].get(p);
        int ret = 0;
        for (int v : adj[u])
            if (v != par)
                ret = Math.max(ret, ask(v, u, p));
        ret++;
        map[u].put(p, ret);
        return ret;
    }

    static int ans;

    static void dfs(int u, int par) {
        ArrayList<Integer> pf = primeFactors(a[u]);
        for (int v : adj[u])
            if (v != par)
                dfs(v, u);
        for (int p : pf) {
            int mx1 = 0, mx2 = 0;
            for (int v : adj[u])
                if (v != par) {
                    int r = ask(v, u, p);
                    if (r >= mx1) {
                        mx2 = mx1;
                        mx1 = r;
                    } else if (r >= mx2)
                        mx2 = r;
                }
            ans = Math.max(ans, mx1 + mx2 + 1);
        }
    }

    static HashMap<Integer, Integer>[] map;

    static int n;
    static int[] a;

    static ArrayList<Integer>[] adj;


    static ArrayList<Integer> primes;
    static int[] isComposite;

    static void sieve(int N)    // O(N log log N)
    {
        isComposite = new int[N + 1];
        isComposite[0] = isComposite[1] = 1;            // 0 indicates a prime number
        primes = new ArrayList<Integer>();

        for (int i = 2; i <= N; ++i)                    //can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
            if (isComposite[i] == 0)                    //can loop in 2 and odd integers for slightly better performance
            {
                primes.add(i);
                if (1l * i * i <= N)
                    for (int j = i * i; j <= N; j += i)    // j = i * 2 will not affect performance too much, may alter in modified sieve
                        isComposite[j] = 1;
            }
    }

    static ArrayList<Integer> primeFactors(int N)        // O(sqrt(N) / ln sqrt(N))
    {
        ArrayList<Integer> factors = new ArrayList<Integer>();        //take abs(N) in case of -ve integers
        int idx = 0, p = primes.get(idx);

        while (p * p <= N) {
            while (N % p == 0) {
                factors.add(p);
                N /= p;
            }
            p = primes.get(++idx);
        }

        if (N != 1)                        // last prime factor may be > sqrt(N)
            factors.add(N);                // for integers whose largest prime factor has a power of 1
        return factors;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}