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.util.*;

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int i,j,N=200000; p=new int[N+1];
        for(i=2;i<=N;i++)
        if(p[i]==0)
        for(j=i;j<=N;j+=i) p[j]=i;

        int n=Integer.parseInt(bu.readLine());
        hm=new HashMap[n]; g=new ArrayList[n]; a=new int[n];
        String s[]=bu.readLine().split(" ");
        for(i=0;i<n;i++)
        {
            a[i]=Integer.parseInt(s[i]);
            hm[i]=new HashMap<>();
            g[i]=new ArrayList<>();
        }

        for(i=0;i<n-1;i++)
        {
            s=bu.readLine().split(" ");
            int u=Integer.parseInt(s[0])-1,v=Integer.parseInt(s[1])-1;
            g[u].add(v); g[v].add(u);
        }

        ans=0;
        dfs(0,-1,0);
        System.out.println(ans);
    }

    static int a[],p[],ans;
    static HashMap<Integer,Integer> hm[];
    static ArrayList<Integer> g[];
    static void dfs(int n,int pa,int d)
    {
        int pr,x=a[n];
        while(x!=1)
        {
            pr=p[x];
            while(x%pr==0) x/=pr;
            hm[n].put(pr,d);
            ans=Math.max(ans,1);
        }

        for(int c:g[n])
        if(c!=pa)
        {
            dfs(c,n,d+1);
            for(int y:hm[c].keySet())
            if(hm[n].containsKey(y))
            {
                ans=Math.max(ans,hm[n].get(y)+hm[c].get(y)-2*d+1);
                hm[n].put(y,Math.max(hm[n].get(y),hm[c].get(y)));
            }
        }
    }
}
