#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 2e5 + 5;
int n;
vector<int> adj[N];
long long ans, V[N], down[N], size[N];
void dfs(int s, int dad) {
  size[s] = 1;
  down[s] = V[s];
  for (auto i : adj[s]) {
    if (i == dad) continue;
    dfs(i, s);
    size[s] += size[i];
    down[s] += V[s] * size[i] - down[i] + MOD;
    down[s] %= MOD;
  }
}
void ComputeAns(int u, int dad, int t) {
  long long total = down[u] + V[u] * (n - size[u]) - t + MOD;
  total %= MOD;
  ans += total;
  ans %= MOD;
  for (auto i : adj[u]) {
    if (i == dad) continue;
    ComputeAns(i, u, (total - V[u] * size[i] + down[i] + MOD) % MOD);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> V[i];
    if (V[i] < 0) V[i] += MOD;
  }
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 1);
  ComputeAns(1, 1, 0);
  cout << ans << '\n';
  return 0;
}
