#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
vector<int> g[N];
int val[N];
int dp[N];
int path[N][2];
int cnt[N][2];
int mod = 1e9 + 7;
void dfs(int u, int p) {
  dp[u] = val[u];
  path[u][1] = val[u];
  cnt[u][1] = 1;
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
    dp[u] += 1ll * cnt[v][0] * path[u][1] % mod;
    dp[u] %= mod;
    dp[u] += 1ll * path[v][0] * cnt[u][1] % mod;
    dp[u] %= mod;
    dp[u] += 1ll * cnt[v][1] * path[u][0] % mod;
    dp[u] %= mod;
    dp[u] += 1ll * path[v][1] * cnt[u][0] % mod;
    dp[u] %= mod;
    path[u][0] += (path[v][1] + 1ll * cnt[v][1] * (-val[u]) % mod) % mod;
    path[u][0] %= mod;
    path[u][1] += (path[v][0] + 1ll * cnt[v][0] * val[u] % mod) % mod;
    path[u][1] %= mod;
    cnt[u][1] += cnt[v][0];
    cnt[u][1] %= mod;
    cnt[u][0] += cnt[v][1];
    cnt[u][0] %= mod;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> val[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += dp[i];
    ans %= mod;
  }
  ans += ans;
  ans %= mod;
  for (int i = 1; i <= n; i++) {
    ans -= val[i];
    ans %= mod;
  }
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}
