#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long long N = 2e5 + 10;
const long long mod = 1e9 + 7;
int read() {
  int a;
  scanf("%d", &a);
  return a;
}
int siz[N], n, A[N], t[N], fas[N], dep[N];
long long ans, suf[N][2], sup[N][2];
vector<int> G[N];
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  fas[u] = fa;
  siz[u] = 1;
  suf[u][0] = 1;
  for (int siz1 = G[u].size(), i = 0; i < siz1; i++) {
    int v = G[u][i];
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
    suf[u][0] += suf[v][1];
    suf[u][1] += suf[v][0];
  }
  ans = (ans + mod +
         1ll * (suf[u][0] - suf[u][1]) * A[u] % mod * (n - siz[u] + 1) % mod) %
        mod;
  ans = (ans + mod + 1ll * A[u] * (siz[u] - 1) % mod) % mod;
  for (int siz1 = G[u].size(), i = 0; i < siz1; i++) {
    int v = G[u][i];
    if (v == fa) continue;
    ans = (ans + mod +
           1ll * (suf[v][1] - suf[v][0]) * A[u] % mod * (siz[u] - siz[v] - 1) %
               mod) %
          mod;
  }
}
bool cmp(int a, int b) { return dep[a] < dep[b]; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    A[i] = read();
    t[i] = i;
  }
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  sort(t + 1, t + 1 + n, cmp);
  for (int i = 2; i <= n; i++) {
    int u = t[i];
    sup[u][0] += sup[fas[u]][1] + suf[fas[u]][1] - suf[u][0];
    sup[u][1] += sup[fas[u]][0] + suf[fas[u]][0] - suf[u][1];
    ans =
        (mod + ans + (sup[u][0] - sup[u][1]) * siz[u] % mod * A[u] % mod) % mod;
  }
  cout << ans % mod;
}
