#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5, mod = 1e9 + 7;
long long sz[maxn], e[maxn], o[maxn], O[maxn], E[maxn], a[maxn], ans;
vector<long long> adj[maxn];
void getsz(long long v, long long p = -1) {
  sz[v] = 1;
  e[v] = 1;
  for (auto u : adj[v]) {
    if (u != p) {
      getsz(u, v);
      e[v] += o[u];
      o[v] += e[u];
      sz[v] += sz[u];
    }
  }
}
void getzs(long long v, long long p = -1) {
  long long ee = 0, oo = 0;
  for (auto u : adj[v]) {
    if (u != p) {
      ee += e[u];
      oo += o[u];
      ans -= a[v] * e[u] * (sz[v] - 1 - sz[u]);
      ans += a[v] * o[u] * (sz[v] - 1 - sz[u]);
      ans %= mod;
    }
  }
  for (auto u : adj[v]) {
    if (u != p) {
      E[u] = O[v] + ee - e[u];
      O[u] = 1 + E[v] + oo - o[u];
      getzs(u, v);
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n - 1; i++) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  getsz(0);
  getzs(0);
  for (long long i = 0; i < n; i++) {
    ans += a[i] * (e[i] * (n - sz[i] + 1) + (E[i] + 1) * sz[i] - 1);
    ans -= a[i] * (o[i] * (n - sz[i] + 1) + O[i] * sz[i]);
    ans %= mod;
    ans += mod;
    ans %= mod;
  }
  cout << ans;
}
