#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
template <class T>
inline void read(T &x) {
  int t;
  bool flag = false;
  while ((t = getchar()) != '-' && (t < '0' || t > '9'))
    ;
  if (t == '-') flag = true, t = getchar();
  x = t - '0';
  while ((t = getchar()) >= '0' && t <= '9') x = x * 10 + t - '0';
  if (flag) x = -x;
}
typedef struct {
  int to, next;
} Edge;
Edge tree[MAXN * 2];
int head[MAXN], cnt;
void add(int from, int to) {
  tree[cnt].to = to;
  tree[cnt].next = head[from];
  head[from] = cnt++;
}
void init() {
  memset(head, -1, sizeof(head));
  cnt = 0;
}
long long N, v[MAXN], dp0[MAXN], f0[MAXN], dp2[MAXN], f2[MAXN];
const long long MOD = 1000000007LL;
void dfs0(int root, int par) {
  dp0[root] = v[root], f0[root] = 1;
  for (int i = head[root]; ~i; i = tree[i].next) {
    int to = tree[i].to;
    if (to != par) {
      dfs0(to, root);
      dp0[root] = (f0[to] * v[root] + dp0[root] - dp0[to] + MOD) % MOD;
      dp0[root] = (dp0[root] + MOD) % MOD;
      f0[root] += f0[to];
    }
  }
}
void dfs1(int root, int par) {
  for (int i = head[root]; ~i; i = tree[i].next) {
    int to = tree[i].to;
    if (to != par) {
      dp2[to] = ((N - f0[to]) * v[to] + dp0[to] -
                 (dp2[root] + dp0[to] - f0[to] * v[root] + MOD) + MOD) %
                MOD;
      dp2[to] = (dp2[to] + MOD) % MOD;
      dfs1(to, root);
    }
  }
}
int main() {
  init();
  int a, b;
  read(N);
  for (int i = 1; i <= N; ++i) read(v[i]);
  for (int i = 1; i < N; ++i) {
    read(a), read(b);
    add(a, b);
    add(b, a);
  }
  dfs0(1, -1);
  dp2[1] = dp0[1];
  f2[1] = f0[1];
  dfs1(1, -1);
  long long ans = 0;
  for (int i = 1; i <= N; ++i) ans = (ans + dp2[i]) % MOD;
  cout << ans << endl;
  return 0;
}
