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
#include <bits/stdc++.h>
using namespace std;
int n;
int ans = 0;
int num[200005];
int hei[200005];
int mpf[200005];
int ls[200005], cnt[200005];
vector<int> primes;
vector<int> adj[200005];
unordered_set<int> facts[200005];
unordered_map<int, int> inlst;
unordered_map<int, int> mxh[200005];
void linear_sieve() {
  for (int i = 2; i < 200005; i++) {
    if (!mpf[i]) {
      primes.push_back(i);
      mpf[i] = i;
      facts[i].insert(i);
    }
    vector<int> fcts;
    for (auto x : facts[i]) fcts.push_back(x);
    for (auto x : primes) {
      if (x > mpf[i] || i * x >= 200005) break;
      int m = i * x;
      mpf[m] = x;
      for (auto y : fcts) facts[m].insert(y);
      facts[m].insert(x);
    }
  }
}
void dfs(int st, int pr, int h) {
  hei[st] = h;
  unordered_map<int, pair<int, int> > clst;
  for (auto x : facts[num[st]]) {
    mxh[st][x] = h;
  }
  for (auto x : adj[st]) {
    if (x == pr) continue;
    dfs(x, st, h + 1);
    for (auto y : facts[num[st]]) {
      if (!mxh[x].count(y)) continue;
      if (clst[y].first < mxh[x][y]) {
        clst[y].second = clst[y].first;
        clst[y].first = mxh[x][y];
      } else if (clst[y].second < mxh[x][y]) {
        clst[y].second = mxh[x][y];
      }
      mxh[st][y] = max(mxh[st][y], mxh[x][y]);
    }
  }
  for (auto x : facts[num[st]]) {
    ans = max(ans, mxh[st][x] - h + 1);
    if (clst[x].second)
      ans = max(ans, clst[x].first + clst[x].second - (h << 1) + 1);
  }
}
int main() {
  linear_sieve();
  scanf("%d", &n);
  int ors = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    ors |= num[i];
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  if (ors == 1) {
    puts("0");
    return 0;
  }
  dfs(1, 0, 1);
  printf("%d\n", ans);
  return 0;
}
