#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const int N = 200003;
int n;
int V[N], dp[N], sz[N], ans[N], res = 0;
vector<int> g[N];
void dfs(int u, int p) {
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
    sz[u] += sz[v];
    dp[u] += (MOD - dp[v]);
    if (dp[u] >= MOD) dp[u] -= MOD;
  }
  ++sz[u];
  dp[u] += (1LL * sz[u] * V[u]) % MOD;
  if (dp[u] >= MOD) dp[u] -= MOD;
}
void solve(int u, int p) {
  if (p != 0) {
    ans[u] += dp[u];
    if (ans[u] >= MOD) ans[u] -= MOD;
    ans[u] += (1LL * (n - sz[u]) * V[u]) % MOD;
    if (ans[u] >= MOD) ans[u] -= MOD;
    ans[u] += (MOD - ans[p]);
    if (ans[u] >= MOD) ans[u] -= MOD;
    ans[u] += (1LL * V[p] * sz[u] + (MOD - dp[u])) % MOD;
    if (ans[u] >= MOD) ans[u] -= MOD;
  } else {
    ans[u] = dp[u];
  }
  res += ans[u];
  if (res >= MOD) res -= MOD;
  for (int v : g[u]) {
    if (v != p) solve(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &V[i]);
  for (int i = 1; i <= n; i++) {
    if (V[i] < 0) V[i] += MOD;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int root = 1;
  dfs(root, 0);
  solve(root, 0);
  printf("%d", res);
}
