#include <bits/stdc++.h>
using namespace std;
int get() {
  int x = 0, f = 1;
  char s;
  while ((s = getchar()) < '0' || s > '9')
    if (s == '-') f = -1;
  while (s >= '0' && s <= '9')
    x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
  return x * f;
}
const int M = 2e5 + 5, mo = 1e9 + 7;
int n, a[M], head[M], cntedge, fa[M], siz[M], f[M], g[M], ans, uf[M], ug[M];
struct edge {
  int to, nxt;
  edge() {}
  edge(const int T, const int NX) { to = T, nxt = NX; }
} e[M << 1];
void add(const int u, const int v) {
  e[++cntedge] = edge(v, head[u]), head[u] = cntedge;
}
void dfs(const int x) {
  f[x] = siz[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to ^ fa[x]) {
      fa[e[i].to] = x;
      dfs(e[i].to);
      siz[x] += siz[e[i].to];
      f[x] += g[e[i].to];
      g[x] += f[e[i].to];
    }
  ans = (ans + 1ll * (f[x] - g[x]) * (n - siz[x] + 1) % mo * a[x] % mo) % mo;
  ans = (ans + 1ll * (siz[x] - 1) * a[x] % mo) % mo;
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to ^ fa[x])
      ans = (ans + 1ll * (g[e[i].to] - f[e[i].to]) *
                       (siz[x] - siz[e[i].to] - 1) % mo * a[x] % mo) %
            mo;
}
void bfs() {
  queue<int> q;
  for (int i = head[1]; i; i = e[i].nxt) q.push(e[i].to);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    uf[x] = ug[fa[x]] + g[fa[x]] - f[x];
    ug[x] = uf[fa[x]] + f[fa[x]] - g[x];
    ans = (ans + 1ll * (uf[x] - ug[x]) * siz[x] % mo * a[x] % mo) % mo;
    for (int i = head[x]; i; i = e[i].nxt)
      if (e[i].to ^ fa[x]) q.push(e[i].to);
  }
}
int main() {
  n = get();
  for (int i = 1; i <= n; ++i) a[i] = get();
  for (int i = 1, u, v; i < n; ++i) {
    u = get(), v = get();
    add(u, v), add(v, u);
  }
  dfs(1);
  bfs();
  printf("%d", (ans + mo) % mo);
  return 0;
}
