#include <bits/stdc++.h>
using namespace std;
inline int Gcd(int X, int Y) { return Y ? Gcd(Y, X % Y) : X; }
inline long long Gcd(long long X, long long Y) { return Y ? Gcd(Y, X % Y) : X; }
inline int Pow(int base, long long exp, int _mod) {
  int _ans = 1;
  for (; exp; exp >>= 1, base = (long long)base * base % _mod)
    exp& 1 ? _ans = (long long)_ans * base % _mod : 0;
  return _ans;
}
inline long long Pow(long long base, long long exp, long long _mod) {
  long long _ans = 1;
  for (; exp; exp >>= 1, base = base * base % _mod)
    exp& 1 ? _ans = _ans * base % _mod : 0;
  return _ans;
}
const int INF = 0x3f3f3f3f;
int Mod = 1000000007;
int n, q;
int val[200001];
int h[200001], nxt[400001], to[400001], tot;
inline void ins(int x, int y) {
  nxt[++tot] = h[x];
  to[tot] = y;
  h[x] = tot;
}
int f[200001], siz[200001], dep[200001];
long long Ans;
void DFS(int u, int fa) {
  f[u] = 1;
  dep[u] = dep[fa] + 1;
  siz[u] = 1;
  for (int i = h[u]; i; i = nxt[i])
    if (to[i] != fa) DFS(to[i], u), f[u] -= f[to[i]], siz[u] += siz[to[i]];
}
void D2(int u, int fa) {
  for (int i = h[u]; i; i = nxt[i])
    if (to[i] != fa) {
      D2(to[i], u);
      Ans =
          ((Ans + (long long)f[to[i]] * siz[to[i]] % Mod * val[u] % Mod) % Mod +
           Mod) %
          Mod;
    }
  if (fa != 0)
    Ans = ((Ans + (long long)(((dep[u] & 1) ? -f[1] : f[1]) + f[u]) *
                      (n - siz[u]) % Mod * val[u] % Mod) %
               Mod +
           Mod) %
          Mod;
}
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 1; i <= (n); ++i) scanf("%d", val + i);
  for (int i = 2; i <= (n); ++i) scanf("%d%d", &x, &y), ins(x, y), ins(y, x);
  DFS(1, 0);
  for (int i = 1; i <= (n); ++i)
    if (dep[i] & 1)
      Ans += (long long)f[1] * val[i];
    else
      Ans -= (long long)f[1] * val[i];
  Ans = (Ans % Mod + Mod) % Mod;
  Ans = Ans * n % Mod;
  D2(1, 0);
  printf("%lld\n", Ans);
  return 0;
}
