#include <bits/stdc++.h>
using namespace std;
class modulo_field_element {
 private:
  long long value;
  const static long long mod = 1e9 + 7;
  long long power(long long x, long long deg) {
    if (deg == 0) return 1;
    if ((deg & 1) == 0) {
      long long half = power(x, deg >> 1);
      return (half * half) % mod;
    } else {
      long long peace = power(x, deg - 1);
      return (peace * x) % mod;
    }
  }
  long long power(long long x) { return power(x, mod - 2); }

 public:
  modulo_field_element(long long _value) : value((_value % mod + mod) % mod) {}
  modulo_field_element(int _value)
      : value(((long long)_value % mod + mod) % mod) {}
  modulo_field_element() : value(0) {}
  modulo_field_element inv() { return modulo_field_element(power(value)); }
  modulo_field_element operator+(const modulo_field_element &a) {
    return (this->value + a.value) % mod;
  }
  modulo_field_element operator*(const modulo_field_element &a) {
    return (this->value * a.value) % mod;
  }
  modulo_field_element operator-(const modulo_field_element &a) {
    return (this->value - a.value + mod) % mod;
  }
  modulo_field_element operator/(const modulo_field_element &a) {
    return (*this) * ((modulo_field_element)power(a.value));
  }
  modulo_field_element operator+=(const modulo_field_element &a) {
    return *this = *this + a;
  }
  modulo_field_element operator-=(const modulo_field_element &a) {
    return *this = *this - a;
  }
  modulo_field_element operator*=(const modulo_field_element &a) {
    return *this = *this * a;
  }
  modulo_field_element operator/=(const modulo_field_element &a) {
    return *this = *this / a;
  }
  modulo_field_element operator++(int) { return (this->value + 1) % mod; }
  modulo_field_element operator++() { return (this->value + 1) % mod; }
  modulo_field_element operator--(int) { return (this->value - 1 + mod) % mod; }
  modulo_field_element operator--() { return (this->value - 1 + mod) % mod; }
  modulo_field_element operator+() { return (*this); }
  modulo_field_element operator-() { return ((mod - this->value) % mod); }
  operator int() const { return (int)value; }
  operator long long() const { return (long long)value; }
};
ostream &operator<<(ostream &s, const modulo_field_element &a) {
  return s << (long long)a;
}
istream &operator>>(istream &s, modulo_field_element &a) {
  long long val;
  s >> val;
  a = modulo_field_element(val);
  return s;
}
const int mx = 2e5 + 228;
int n;
vector<int> g[mx], children[mx];
modulo_field_element ans, a[mx], even[mx], odd[mx], f_even[mx], f_odd[mx],
    t_even[mx], t_odd[mx];
void hang(int v, int pv) {
  if (v != 0) children[pv].push_back(v);
  for (auto v1 : g[v]) {
    if (v1 != pv) hang(v1, v);
  }
}
void dfs(int v) {
  for (auto v1 : children[v]) {
    dfs(v1);
  }
  even[v] += 1;
  f_even[v] += a[v];
  t_even[v] += a[v];
  modulo_field_element sum_even = 0, sum_odd = 0, sum_f_even = 0, sum_f_odd = 0,
                       sum_t_even = 0, sum_t_odd = 0;
  for (auto v1 : children[v]) {
    even[v] += odd[v1];
    f_even[v] += (f_odd[v1] + odd[v1] * a[v]);
    t_even[v] += (-t_odd[v1] + odd[v1] * a[v]);
    odd[v] += even[v1];
    f_odd[v] += (f_even[v1] - even[v1] * a[v]);
    t_odd[v] += (-t_even[v1] + even[v1] * a[v]);
    sum_even += even[v1];
    sum_odd += odd[v1];
    sum_f_even += f_even[v1];
    sum_f_odd += f_odd[v1];
    sum_t_even += t_even[v1];
    sum_t_odd += t_odd[v1];
  }
  for (auto v1 : children[v]) {
    modulo_field_element rem_odd = sum_odd - odd[v1];
    modulo_field_element rem_even = sum_even - even[v1];
    modulo_field_element rem_f_odd = sum_f_odd - f_odd[v1];
    modulo_field_element rem_f_even = sum_f_even - f_even[v1];
    modulo_field_element rem_t_odd = sum_t_odd - t_odd[v1];
    modulo_field_element rem_t_even = sum_t_even - t_even[v1];
    modulo_field_element c1 = f_even[v1] * rem_even + rem_t_even * even[v1] -
                              rem_even * even[v1] * a[v];
    modulo_field_element c2 =
        f_even[v1] * rem_odd + rem_t_odd * even[v1] - rem_odd * even[v1] * a[v];
    modulo_field_element c3 =
        f_odd[v1] * rem_even - rem_t_even * odd[v1] + rem_even * odd[v1] * a[v];
    modulo_field_element c4 =
        f_odd[v1] * rem_odd - rem_t_odd * odd[v1] + rem_odd * odd[v1] * a[v];
    ans += (c1 + c2 + c3 + c4);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  hang(0, 0);
  dfs(0);
  for (int i = 0; i < n; ++i) {
    ans += (f_odd[i] + f_even[i] + t_odd[i] + t_even[i]);
    ans -= a[i];
  }
  cout << ans << endl;
}

### Prompt

Construct a cpp code solution to the problem outlined:

Given a tree with n nodes numbered from 1 to n. Each node i has an associated value V_i.

If the simple path from u_1 to u_m consists of m nodes namely u_1 → u_2 → u_3 → ... u_{m-1} → u_{m}, then its alternating function A(u_{1},u_{m}) is defined as A(u_{1},u_{m}) = ∑_{i=1}^{m} (-1)^{i+1} ⋅ V_{u_{i}}. A path can also have 0 edges, i.e. u_{1}=u_{m}.

Compute the sum of alternating functions of all unique simple paths. Note that the paths are directed: two paths are considered different if the starting vertices differ or the ending vertices differ. The answer may be large so compute it modulo 10^{9}+7. 

Input

The first line contains an integer n (2 ≤ n ≤ 2⋅10^{5} ) — the number of vertices in the tree.

The second line contains n space-separated integers V_1, V_2, …, V_n (-10^9≤ V_i ≤ 10^9) — values of the nodes.

The next n-1 lines each contain two space-separated integers u and v (1≤ u, v≤ n, u ≠ v) denoting an edge between vertices u and v. It is guaranteed that the given graph is a tree.

Output

Print the total sum of alternating functions of all unique simple paths modulo 10^{9}+7. 

Examples

Input

4
-4 1 5 -2
1 2
1 3
1 4


Output

40


Input

8
-2 6 -4 -4 -9 -3 -7 23
8 2
2 3
1 4
6 5
7 6
4 7
5 8


Output

4

Note

Consider the first example.

A simple path from node 1 to node 2: 1 → 2 has alternating function equal to A(1,2) = 1 ⋅ (-4)+(-1) ⋅ 1 = -5.

A simple path from node 1 to node 3: 1 → 3 has alternating function equal to A(1,3) = 1 ⋅ (-4)+(-1) ⋅ 5 = -9.

A simple path from node 2 to node 4: 2 → 1 → 4 has alternating function A(2,4) = 1 ⋅ (1)+(-1) ⋅ (-4)+1 ⋅ (-2) = 3.

A simple path from node 1 to node 1 has a single node 1, so A(1,1) = 1 ⋅ (-4) = -4.

Similarly, A(2, 1) = 5, A(3, 1) = 9, A(4, 2) = 3, A(1, 4) = -2, A(4, 1) = 2, A(2, 2) = 1, A(3, 3) = 5, A(4, 4) = -2, A(3, 4) = 7, A(4, 3) = 7, A(2, 3) = 10, A(3, 2) = 10. So the answer is (-5) + (-9) + 3 + (-4) + 5 + 9 + 3 + (-2) + 2 + 1 + 5 + (-2) + 7 + 7 + 10 + 10 = 40.

Similarly A(1,4)=-2, A(2,2)=1, A(2,1)=5, A(2,3)=10, A(3,3)=5, A(3,1)=9, A(3,2)=10, A(3,4)=7, A(4,4)=-2, A(4,1)=2, A(4,2)=3 , A(4,3)=7 which sums upto 40. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class modulo_field_element {
 private:
  long long value;
  const static long long mod = 1e9 + 7;
  long long power(long long x, long long deg) {
    if (deg == 0) return 1;
    if ((deg & 1) == 0) {
      long long half = power(x, deg >> 1);
      return (half * half) % mod;
    } else {
      long long peace = power(x, deg - 1);
      return (peace * x) % mod;
    }
  }
  long long power(long long x) { return power(x, mod - 2); }

 public:
  modulo_field_element(long long _value) : value((_value % mod + mod) % mod) {}
  modulo_field_element(int _value)
      : value(((long long)_value % mod + mod) % mod) {}
  modulo_field_element() : value(0) {}
  modulo_field_element inv() { return modulo_field_element(power(value)); }
  modulo_field_element operator+(const modulo_field_element &a) {
    return (this->value + a.value) % mod;
  }
  modulo_field_element operator*(const modulo_field_element &a) {
    return (this->value * a.value) % mod;
  }
  modulo_field_element operator-(const modulo_field_element &a) {
    return (this->value - a.value + mod) % mod;
  }
  modulo_field_element operator/(const modulo_field_element &a) {
    return (*this) * ((modulo_field_element)power(a.value));
  }
  modulo_field_element operator+=(const modulo_field_element &a) {
    return *this = *this + a;
  }
  modulo_field_element operator-=(const modulo_field_element &a) {
    return *this = *this - a;
  }
  modulo_field_element operator*=(const modulo_field_element &a) {
    return *this = *this * a;
  }
  modulo_field_element operator/=(const modulo_field_element &a) {
    return *this = *this / a;
  }
  modulo_field_element operator++(int) { return (this->value + 1) % mod; }
  modulo_field_element operator++() { return (this->value + 1) % mod; }
  modulo_field_element operator--(int) { return (this->value - 1 + mod) % mod; }
  modulo_field_element operator--() { return (this->value - 1 + mod) % mod; }
  modulo_field_element operator+() { return (*this); }
  modulo_field_element operator-() { return ((mod - this->value) % mod); }
  operator int() const { return (int)value; }
  operator long long() const { return (long long)value; }
};
ostream &operator<<(ostream &s, const modulo_field_element &a) {
  return s << (long long)a;
}
istream &operator>>(istream &s, modulo_field_element &a) {
  long long val;
  s >> val;
  a = modulo_field_element(val);
  return s;
}
const int mx = 2e5 + 228;
int n;
vector<int> g[mx], children[mx];
modulo_field_element ans, a[mx], even[mx], odd[mx], f_even[mx], f_odd[mx],
    t_even[mx], t_odd[mx];
void hang(int v, int pv) {
  if (v != 0) children[pv].push_back(v);
  for (auto v1 : g[v]) {
    if (v1 != pv) hang(v1, v);
  }
}
void dfs(int v) {
  for (auto v1 : children[v]) {
    dfs(v1);
  }
  even[v] += 1;
  f_even[v] += a[v];
  t_even[v] += a[v];
  modulo_field_element sum_even = 0, sum_odd = 0, sum_f_even = 0, sum_f_odd = 0,
                       sum_t_even = 0, sum_t_odd = 0;
  for (auto v1 : children[v]) {
    even[v] += odd[v1];
    f_even[v] += (f_odd[v1] + odd[v1] * a[v]);
    t_even[v] += (-t_odd[v1] + odd[v1] * a[v]);
    odd[v] += even[v1];
    f_odd[v] += (f_even[v1] - even[v1] * a[v]);
    t_odd[v] += (-t_even[v1] + even[v1] * a[v]);
    sum_even += even[v1];
    sum_odd += odd[v1];
    sum_f_even += f_even[v1];
    sum_f_odd += f_odd[v1];
    sum_t_even += t_even[v1];
    sum_t_odd += t_odd[v1];
  }
  for (auto v1 : children[v]) {
    modulo_field_element rem_odd = sum_odd - odd[v1];
    modulo_field_element rem_even = sum_even - even[v1];
    modulo_field_element rem_f_odd = sum_f_odd - f_odd[v1];
    modulo_field_element rem_f_even = sum_f_even - f_even[v1];
    modulo_field_element rem_t_odd = sum_t_odd - t_odd[v1];
    modulo_field_element rem_t_even = sum_t_even - t_even[v1];
    modulo_field_element c1 = f_even[v1] * rem_even + rem_t_even * even[v1] -
                              rem_even * even[v1] * a[v];
    modulo_field_element c2 =
        f_even[v1] * rem_odd + rem_t_odd * even[v1] - rem_odd * even[v1] * a[v];
    modulo_field_element c3 =
        f_odd[v1] * rem_even - rem_t_even * odd[v1] + rem_even * odd[v1] * a[v];
    modulo_field_element c4 =
        f_odd[v1] * rem_odd - rem_t_odd * odd[v1] + rem_odd * odd[v1] * a[v];
    ans += (c1 + c2 + c3 + c4);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  hang(0, 0);
  dfs(0);
  for (int i = 0; i < n; ++i) {
    ans += (f_odd[i] + f_even[i] + t_odd[i] + t_even[i]);
    ans -= a[i];
  }
  cout << ans << endl;
}

```