990_G. GCD Counting
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).

For every integer from 1 to 2 ⋅ 10^5 you have to count the number of pairs (x, y) (1 ≤ x ≤ y ≤ n) such that g(x, y) is equal to this number.

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

For every integer i from 1 to 2 ⋅ 10^5 do the following: if there is no pair (x, y) such that x ≤ y and g(x, y) = i, don't output anything. Otherwise output two integers: i and the number of aforementioned pairs. You have to consider the values of i in ascending order.

See the examples for better understanding.

Examples

Input

3
1 2 3
1 2
2 3


Output

1 4
2 1
3 1


Input

6
1 2 4 8 16 32
1 6
6 3
3 4
4 2
6 5


Output

1 6
2 5
4 6
8 1
16 2
32 1


Input

4
9 16 144 6
1 3
2 3
4 3


Output

1 1
2 1
3 1
6 2
9 2
16 2
144 1
```python
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading




def main():
    ans = 1
    flag = True
    primes = []
    for i in range(2, 500):
        v = 1
        for p in primes:
            if i % p == 0: v = 0
        if v: primes.append(i)

    n = int(input())
    a = [*map(int,input().split())]
    if sum(a) == n: flag = False
    for i in range(n):
        x = a[i]
        a[i] = []
        for p in primes:
            if x % p == 0:
                a[i].append([p,1])
                x = x//p
                while x % p == 0: x //= p
        if x != 1:a[i].append([x,1])

    adj = [[] for i in range(n)]
    for i in range(n-1):
        x, y =map(int,input().split())
        adj[x-1].append(y-1)
        adj[y-1].append(x-1)

    leaves = []
    for i in range(n):
        if len(adj[i]) == 1: leaves.append(i)

    for i in range(n-1):
        x = leaves.pop()
        y = adj[x][0]
        adj[y].remove(x)
        if len(adj[y]) == 1: leaves.append(y)
        for nx in a[x]:
            for ny in a[y]:
                if nx[0] == ny[0]:
                    ans = max([ans, nx[1] + ny[1]])
                    ny[1] = max([ny[1],nx[1]+1])

    if not flag:print(0)
    else:print(ans)


BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    """sys.setrecursionlimit(400000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()"""
    main()
```