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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DGCDCounting solver = new DGCDCounting();
        solver.solve(1, in, out);
        out.close();
    }

    static class DGCDCounting {
        static DGCDCounting.Node[] graph;
        static boolean[] visited;
        static int[] a;

        static DGCDCounting.Pair dfs2(int u, int p) {
            visited[u] = true;
            DGCDCounting.Pair tmp = new DGCDCounting.Pair();
            if (a[u] % p != 0) {
                visited[u] = false;
                return null;
            }
            tmp.y = 0;
            tmp.x = u;
            DGCDCounting.Pair l;
            for (int i = 0; i < graph[u].edges.size(); i++) {
                if (!visited[graph[u].edges.get(i)]) {
                    l = dfs2(graph[u].edges.get(i), p);
                    if (l != null) {
                        if (l.y > tmp.y) {
                            tmp.x = l.x;
                            tmp.y = l.y;
                        }
                    }
                }
            }
            tmp.y++;
            visited[u] = false;
            return tmp;
        }

        static int dfs(int u, int b) {
            visited[u] = true;
            if (a[u] % b != 0) {
                visited[u] = false;
                return 0;
            }
            int max = 0;
            for (int i = 0; i < graph[u].edges.size(); i++) {
                if (!visited[graph[u].edges.get(i)]) {
                    max = Math.max(max, dfs(graph[u].edges.get(i), b));
                }
            }
            return max + 1;
        }

        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            graph = new DGCDCounting.Node[n];
            visited = new boolean[n];
            for (int i = 0; i < n; i++) {
                graph[i] = new DGCDCounting.Node();
                graph[i].edges = new ArrayList<>();
            }
            a = new int[n];
            int max = 0;
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
                max = Math.max(a[i], max);
            }
            int[] copy = new int[n];
            HashMap<Integer, Integer> done = new HashMap<>();
            ArrayList<ArrayList<Integer>> divi = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                copy[i] = a[i];
                for (int j = 2; j * j <= copy[i]; j++) {
                    if (copy[i] % j == 0) {
                        if (done.get(j) == null) {
                            divi.add(new ArrayList<>());
                            divi.get(divi.size() - 1).add(j);
                            divi.get(divi.size() - 1).add(i);
                            done.put(j, divi.size() - 1);
                        } else {
                            divi.get(done.get(j)).add(i);
                        }
                        while (copy[i] % j == 0) {
                            copy[i] /= j;
                        }
                    }
                }
                if (copy[i] > 1) {
                    if (done.get(copy[i]) == null) {
                        divi.add(new ArrayList<>());
                        divi.get(divi.size() - 1).add(copy[i]);
                        divi.get(divi.size() - 1).add(i);

                        done.put(copy[i], divi.size() - 1);
                    } else {
                        divi.get(done.get(copy[i])).add(i);
                    }
                }
            }

            divi.sort(new Comparator<ArrayList<Integer>>() {

                public int compare(ArrayList<Integer> a, ArrayList<Integer> b) {
                    return b.size() - a.size();
                }
            });
            int x, y;
            for (int i = 0; i < n - 1; i++) {
                x = sc.nextInt() - 1;
                y = sc.nextInt() - 1;
                graph[x].edges.add(y);
                graph[y].edges.add(x);
            }
            int ans = 0;
            DGCDCounting.Pair tmp;
            int sz;
            for (int i = 0; i < divi.size(); i++) {
                if (divi.get(i).size() > ans) {
                    sz = divi.get(i).size();
                    for (int j = 1; j < sz; j++) {
                        if (!visited[divi.get(i).get(j)]) {
                            tmp = dfs2(divi.get(i).get(j), divi.get(i).get(0));
                            ans = Math.max(dfs(tmp.x, divi.get(i).get(0)), ans);
                        }
                    }
                    for (int j = 1; j < sz; j++) {
                        visited[divi.get(i).get(j)] = false;
                    }
                } else {
                    break;
                }
            }
            out.println(ans);
        }

        public static class Node {
            ArrayList<Integer> edges;

        }

        public static class Pair {
            int x;
            int y;

        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

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

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

    }
}

