You are given a rooted tree with n vertices. In each leaf vertex there's a single integer — the number of apples in this vertex. 

The weight of a subtree is the sum of all numbers in this subtree leaves. For instance, the weight of a subtree that corresponds to some leaf is the number written in the leaf.

A tree is balanced if for every vertex v of the tree all its subtrees, corresponding to the children of vertex v, are of equal weight. 

Count the minimum number of apples that you need to remove from the tree (specifically, from some of its leaves) in order to make the tree balanced. Notice that you can always achieve the goal by just removing all apples.

Input

The first line contains integer n (2 ≤ n ≤ 105), showing the number of vertices in the tree. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 108), ai is the number of apples in the vertex number i. The number of apples in non-leaf vertices is guaranteed to be zero. 

Then follow n - 1 lines, describing the tree edges. Each line contains a pair of integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi) — the vertices connected by an edge. 

The vertices are indexed from 1 to n. Vertex 1 is the root.

Output

Print a single integer — the minimum number of apples to remove in order to make the tree balanced.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the sin, cout streams cin, cout or the %I64d specifier.

Examples

Input

6
0 0 12 13 5 6
1 2
1 3
1 4
2 5
2 6


Output

6
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const long long inf = 1ll << 60;
int n, tot;
int to[N << 1], nex[N << 1], head[N];
long long ans = 0, p[N], sum[N];
bool flag;
void SE(int u, int v) {
  to[++tot] = v;
  nex[tot] = head[u];
  head[u] = tot;
  return;
}
long long _GCD(long long x, long long y) {
  long long r = x % y;
  while (r) x = y, y = r, r = x % y;
  return y;
}
void DFS(int x, int fa) {
  long long mi = inf, cnt = 0;
  for (int i = head[x]; i; i = nex[i]) {
    if (to[i] == fa) continue;
    DFS(to[i], x);
    if (flag) return;
    if (p[to[i]] < mi) mi = p[to[i]];
    cnt++;
  }
  if (cnt == 0) {
    sum[x] = 1;
    return;
  }
  long long lcm = 1ll;
  for (int i = head[x]; i; i = nex[i]) {
    if (to[i] == fa) continue;
    if ((double)lcm / _GCD(lcm, sum[to[i]]) * sum[to[i]] > (double)mi) {
      flag = 1;
      return;
    }
    lcm = lcm / _GCD(lcm, sum[to[i]]) * sum[to[i]];
  }
  p[x] = mi / lcm * lcm * cnt;
  sum[x] = lcm * cnt;
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &p[i]);
    ans += p[i];
  }
  for (int u, v, i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    SE(u, v), SE(v, u);
  }
  DFS(1, 0);
  if (!flag) ans -= p[1];
  printf("%I64d\n", ans);
  return 0;
}
