QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 512 MB 満点: 100

#7370. Lazy Problem Setter

統計

The problem setter is lazy and does not want to write a long problem statement, nor do they want to read one. The problem setter is kind and does not want the contestants to read a long problem statement. Therefore, this problem statement is very brief:

Given a tree with $n$ nodes. The node labeled $i$ has a weight $a_i$. A pair of paths on the tree can be represented as $(x, y, u, v)$, where $x \le y$ and $u \le v$, representing a path from $x$ to $y$ and a path from $u$ to $v$.

Define the value of a path pair $f(x, y, u, v)$ as the least common multiple (lcm) of the weights of all nodes that are present on both paths. Calculate the product of the values of all possible path pairs, i.e.,

$$\prod_{1 \le x \le y \le n, 1 \le u \le v \le n} f(x, y, u, v)$$

Since the result can be very large, you only need to output the answer modulo $10^9 + 7$.

Input

The first line contains an integer $n$, representing the size of the tree. The second line contains $n$ integers, where the $i$-th number represents the weight $a_i$ of the $i$-th node. The next $n - 1$ lines each contain two integers $u_i, v_i$, representing an edge in the tree.

Output

Output a single integer representing the answer modulo $10^9 + 7$.

Examples

Input 1

4
2 2 1 4
1 2
2 3
2 4

Output 1

248320570

Constraints

For 20% of the data, $n \le 100, a_i \le 11$; For 30% of the data, $n \le 2000, a_i \le 11$; For 50% of the data, $n \le 2 \times 10^4$; For 60% of the data, $n \le 8 \times 10^4, a_i \le 10^4$; For 80% of the data, $n \le 2 \times 10^5, a_i \le 5 \times 10^5$; For 100% of the data, $n \le 5 \times 10^5, a_i \le 5 \times 10^6$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.