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.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
    class Node {
        int x;
        int cnt;
        public Node(int x,int cnt){
            this.x=x;
            this.cnt=cnt;
        }
    }
    void solve() {
        int n=ni();
        a=new int[n+1];
        for(int i=1;i<=n;i++) a[i]=ni();
        vec=new ArrayList[200001];
        for(int i=1;i<=200000;i++) vec[i]=new ArrayList<>(30);
        boolean prime[]=new boolean[200001];
        for(int i=2;i*i<=200000;i++){
            if(!prime[i]){
                for(int j=2*i;j<=200000;j+=i) vec[j].add(i);
            }
        }
        for(int i=2;i<=200000;i++) if(!prime[i]) vec[i].add(i);

        g=new ArrayList[n+1];
        for(int i=1;i<=n;i++) g[i]=new ArrayList<>();
        for(int i=1;i<n;i++){
            int x=ni(),y=ni();
            g[x].add(y); g[y].add(x);
        }
        
        dfs(randInt(1,n),-1);
        pw.println(ans);
    }
    int ans=0;
    ArrayList<Integer> g[];
    int a[];
    ArrayList<Integer> vec[];
    int dp2[]=new int[200001];

    Node [] dfs(int v,int pr){
        Node dp[]=new Node[vec[a[v]].size()];
        int mx1[]=new  int[vec[a[v]].size()];
        int mx2[]=new  int[vec[a[v]].size()];

        Arrays.fill(mx1,-1);
        Arrays.fill(mx2,-1);


        for(int i=0;i<vec[a[v]].size();i++)
            dp[i]=new Node(vec[a[v]].get(i),1);

        for(int u : g[v]){
            if(u!=pr) {
                Node p[] = dfs(u, v);
                for(int i=0;i<p.length;i++)
                    dp2[p[i].x]=p[i].cnt;

                for(int i=0;i<vec[a[v]].size();i++){
                    int id=vec[a[v]].get(i);
                    if(1+dp2[id]>dp[i].cnt) dp[i]=new Node(id,1+dp2[id]);

                    if (mx1[i] == -1) mx1[i] = dp2[id];
                    else if (mx2[i] == -1) {
                        mx2[i] = dp2[id];
                    } else {
                        if (dp2[id] >= mx1[i]) {
                            mx2[i] = mx1[i];
                            mx1[i] = dp2[id];
                        } else if (dp2[id] > mx2[i]) {
                            mx2[i] = dp2[id];
                        }
                    }


                }
                for(int i=0;i<p.length;i++) dp2[p[i].x]=0;
                p=null;
            }
        }

        for(int i=0;i<vec[a[v]].size();i++ ){
            ans=Math.max(ans,dp[i].cnt);
            if(dp[i].cnt>1 && mx1[i]!=-1 && mx2[i]!=-1) ans=Math.max(ans,mx1[i]+mx2[i]+1);
        }

        return dp;
    }
    static int randInt(int min,int max){
        Random rand=new Random();
        int randInt=rand.nextInt((max-min)+1)+min;
        return randInt;
    }
    long M= (long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }
    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }

}