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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class DGCDCounting {
        int max = 200000;
        int[] sieve;

        public void solve(int testNumber, InputReader in, OutputWriter out) {

            int n = in.nextInt();

            int[] a = in.nextIntArray(n);

            int o = 0;
            for (int val : a) {
                if (val == 1) {
                    o++;
                }
            }

            if (o == n) {
                out.println(0);
                return;
            }

            List[] g = new List[n];

            in.readUndirectedGraph(g, n, n - 1, 1);

            sieve = sieve(max);

            CentroidDecomposition cd = new CentroidDecomposition(g, n);

            cd.sieve = sieve;
            cd.a = a;
            cd.decompose(0);

            out.println(cd.ans);
        }

        int[] sieve(int n) {
            int[] sieve = new int[n + 1];

            for (int i = 1; i <= n; i++) {
                sieve[i] = i;
            }

            for (int i = 2; i * i <= n; i++) {
                if (sieve[i] == i) {
                    for (int j = i; j * i <= n; j++) {
                        if (sieve[j * i] == j * i)
                            sieve[j * i] = i;
                    }
                }
            }

            return sieve;
        }

        class CentroidDecomposition {
            List[] g;
            int n;
            vertex cdroot = null;
            List[] cdg;
            boolean[] isCentroid;
            int[] sieve;
            int[] a;
            Map<Integer, Integer> map = new HashMap<>();
            Map<Integer, Integer> cmap = new HashMap<>();
            int cans = 0;
            int ans = 0;

            public CentroidDecomposition(List[] g, int n) {
                this.g = g;
                this.n = n;
                this.cdg = new List[n];
                for (int i = 0; i < n; i++) {
                    this.cdg[i] = new ArrayList<vertex>();
                }
                this.isCentroid = new boolean[n];
            }

            int solve(int u) {
                map.clear();
                cmap.clear();
                cans = 0;

                for (int i = 0; i < g[u].size(); i++) {
                    int v = (int) g[u].get(i);

                    if (!isCentroid[v]) {
                        dfs(v, u, gcd(a[u], a[v]), 1);
                        for (int key : cmap.keySet()) {
                            map.merge(key, cmap.get(key), (a, b) -> Math.max(a, b));
                        }
                        cmap.clear();
                    }
                }

                int num = a[u];

                while (num > 1) {
                    int cf = sieve[num];

                    if (map.containsKey(cf)) {
                        cans = Math.max(cans, map.get(cf));
                    }

                    //map.merge(cf, dis, (a, b) -> Math.max(a, b));

                    num /= cf;
                }

                return cans + 1;
            }

            int gcd(int a, int b) {
                if (b == 0)
                    return a;
                else
                    return gcd(b, a % b);
            }

            void dfs(int u, int p, int gcd, int dis) {

                int num = gcd;

                while (num > 1) {
                    int cf = sieve[num];

                    if (map.containsKey(cf)) {
                        cans = Math.max(cans, dis + map.get(cf));
                    }

                    cmap.merge(cf, dis, (a, b) -> Math.max(a, b));

                    while (num % cf == 0) {
                        num /= cf;
                    }
                }

                for (int i = 0; i < g[u].size(); i++) {
                    int v = (int) g[u].get(i);

                    if (v != p && !isCentroid[v]) {
                        dfs(v, u, gcd(gcd, a[v]), dis + 1);
                    }
                }
            }

            vertex decompose(int src) {
                vertex centroid = findCentroid(src);
                isCentroid[centroid.v] = true;

                int cans = solve(centroid.v);

                ans = Math.max(ans, cans);

                if (src == 0)
                    cdroot = centroid;

                int u = centroid.v;

                for (int i = 0; i < g[u].size(); i++) {
                    int v = (int) g[u].get(i);

                    if (!isCentroid[v]) {
                        vertex child = decompose(v);
                        cdg[u].add(child);
                    }
                }

                return centroid;
            }

            vertex findCentroid(int u) {
                Map<Integer, Integer> subSize = new HashMap<>();
                dfs0(u, -1, subSize);

                int totSize = subSize.get(u);

                int curVertex = u;
                int curParent = -1;

                int heavyVertex = -1;

                while (true) {
                    boolean isCurCentroid = true;
                    for (int i = 0; i < g[curVertex].size(); i++) {
                        int v = (int) g[curVertex].get(i);

                        if (v != curParent && !isCentroid[v]) {
                            if (subSize.get(v) > totSize / 2) {
                                heavyVertex = v;
                                isCurCentroid = false;
                                break;
                            }
                        }
                    }
                    if (isCurCentroid) {
                        return new vertex(curVertex);
                    }
                    curParent = curVertex;
                    curVertex = heavyVertex;
                }
            }

            int dfs0(int u, int p, Map<Integer, Integer> subSize) {
                for (int i = 0; i < g[u].size(); i++) {
                    int v = (int) g[u].get(i);

                    if (v != p && !isCentroid[v]) {
                        int size = dfs0(v, u, subSize);
                        subSize.merge(u, size, (x, y) -> x + y);
                    }
                }

                subSize.merge(u, 1, (x, y) -> x + y);

                return subSize.get(u);
            }

            class vertex {
                int v;

                public vertex(int v) {
                    this.v = v;
                }

            }

        }

    }

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

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        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 isWhitespace(c);
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public void readUndirectedGraph(List[] g, int numOfVertices, int numOfEdges, int offset) {
            for (int i = 0; i < numOfVertices; i++) {
                g[i] = new ArrayList();
            }

            for (int i = 0; i < numOfEdges; i++) {
                int u = nextInt() - offset;
                int v = nextInt() - offset;

                g[u].add(v);
                g[v].add(u);
            }
        }

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

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}

