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.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.stream.Collectors;


public class Main {

	static class Task {
		
		int NN = 200005;
		int MOD = 998244353;
		int INF = 2000000000;
		long INFINITY = 1000000000000000000L;
		
		boolean isPrime(int n) {
			if(n <= 1)
				return false;
			for(int i=2;i*i<=n;++i) {
				if(n%i == 0)
					return false;
			}
			return true;
		}
		
		int [] a;
		List<Integer> [] G;
		List<Integer> [] primeFactors = new ArrayList[NN];
		
		
		public void solve(InputReader in, PrintWriter out) {
			for(int i=1;i<NN;++i) {
				primeFactors[i] = new ArrayList<>();
			}
			for(int i=2;i<NN;++i) {
				if(!primeFactors[i].isEmpty())
					continue;
				for(int j=1;j*i<NN;++j) {
					primeFactors[j*i].add(i);
				}
			}
			int n = in.nextInt();
			a = new int[n + 1];
			G = new ArrayList[n + 1];
			for(int i=1;i<=n;++i) {
				a[i]= in.nextInt();
				G[i] = new ArrayList<>();
			}
			for(int i=1;i<n;++i) {
				int u = in.nextInt();
				int v = in.nextInt();
				G[u].add(v);
				G[v].add(u);
			}
			int ans = dfs(1, -1);
			out.println(ans);
		}
		
		int dfs(int cur, int prev) {
			int ret = 0;
			for(int next: G[cur]) {
				if(prev == next)
					continue;
				ret = Math.max(ret, dfs(next, cur));
			}
			int val = a[cur];
			for(int p: primeFactors[val]) {
				int maxD = 1;
				int max1 = 0;
				int max2 = 0;
				for(int next: G[cur]) {
					if(prev == next)
						continue;
					int d = 0;
					if(depth.containsKey(new Pair(next, p))) {
						d = depth.get(new Pair(next, p));
					}
					d++;
					maxD = Math.max(maxD, d);
					--d;
					if(d > max1) {
						max2 = max1;max1 = d;
					} else if(d > max2) {
						max2 = d;
					}
				}
				depth.put(new Pair(cur, p), maxD);
				ret = Math.max(ret, 1 + max1 + max2);
			}
			return ret;
		}
		
		Map<Pair, Integer> depth = new TreeMap<>(
				(i, j) -> i.first.equals(j.first)
				? i.second.compareTo(j.second)
				: i.first.compareTo(j.first));
		
		class Pair {
			Integer first, second;
			public Pair() {
			}
			public Pair(int first, int second) {
				this.first = first;
				this.second = second;
			}
			@Override
			public int hashCode() {
				final int prime = 31;
				int result = 1;
				result = prime * result + getOuterType().hashCode();
				result = prime * result + first;
				result = prime * result + second;
				return result;
			}
			@Override
			public boolean equals(Object obj) {
				if (this == obj)
					return true;
				if (obj == null)
					return false;
				if (getClass() != obj.getClass())
					return false;
				Pair other = (Pair) obj;
				if (!getOuterType().equals(other.getOuterType()))
					return false;
				if (first != other.first)
					return false;
				if (second != other.second)
					return false;
				return true;
			}
			private Task getOuterType() {
				return Task.this;
			}
			
		}
		
	}
	
	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}
	
	public static void main(String[] args) {
        prepareIO(false);
	}
	
	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        
        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }
        
        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }
        
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

}