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 D implements Runnable{
	public static void main (String[] args) {new Thread(null, new D(), "_cf", 1 << 28).start();}

	int MOD = (int)1e9+7;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int n = fs.nextInt();
		int[] vs = fs.nextIntArray(n);
		int[][] divs = new int[n][];
		ArrayList<Integer>[] adj = new ArrayList[n];
		for(int i = 0; i < n; i++) adj[i] = new ArrayList<>();
		for(int i = 0; i < n-1; i++) {
			int u = fs.nextInt()-1;
			int v = fs.nextInt()-1;
			adj[u].add(v); adj[v].add(u);
		}
		int[] list = new int[10];
		for(int i = 0; i < n; i++) {
			int ptr = 0, x = vs[i];
			for(int j = 2; j * j <= x; j++) {
				boolean in = false;
				while(x%j == 0) {
					in = true;
					x /= j;
				}
				if(in) list[ptr++] = j;
			}
			if(x > 1) {
				list[ptr++] = x;
			}
			divs[i] = new int[ptr];
			for(int j = 0; j < ptr; j++) divs[i][j] = list[j];
		}
		
		int[] par = new int[n];
		int[][] best = new int[n][];
		for(int i = 0; i < n; i++) best[i] = new int[divs[i].length];
		Arrays.fill(par, -1); par[0] = 0;
		int[] order = new int[n];
		int ptr = 0;
		
		ArrayDeque<Integer> dq = new ArrayDeque<>();
		dq.add(0);
		while(!dq.isEmpty()) {
			int u = dq.pollFirst();
			order[ptr++] = u;
			for(int v : adj[u]) if(par[v] == -1) {
				par[v] = u;
				dq.add(v);
			}
		}
		
		int res = 0;
		for(int i = n-1; i >= 0; i--) {
			int u = order[i];
			if(vs[u] == 1) continue;
			Arrays.fill(best[u], 1);
			res = Math.max(res, 1);
			for(int j = 0; j < divs[u].length; j++) {
				int max1 = 0, max2 = 0;
				for(int k = 0; k < adj[u].size(); k++) {
					int v = adj[u].get(k);
					int idx = -1;
					for(int ii = 0; ii < divs[v].length; ii++) {
						if(divs[v][ii] == divs[u][j]) {
							idx = ii; break;
						}
					}
					if(idx == -1) continue;
					res = Math.max(res, 1+best[v][idx]);
					best[u][j] = Math.max(best[u][j], 1+best[v][idx]);
					int val = best[v][idx];
					if(val > max1) {
						max2 = max1; max1 = val;
					}
					else {
						if(val > max2) max2 = val;
					}
				}
				res = Math.max(res, 1+max1+max2);
			}
		}
		out.println(res);
		out.close();
	}
	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}