#include <bits/stdc++.h>
using namespace std;
vector<long long> v[200005];
long long dp[200005];
long long sz[200005];
long long val[200005];
long long ans = 0;
long long dfs1(int cn, int pn) {
  sz[cn] = 1;
  for (auto x : v[cn]) {
    if (x != pn) {
      sz[cn] += dfs1(x, cn);
    }
  }
  return sz[cn];
}
long long dfs2(int cn, int pn) {
  dp[cn] = (sz[cn] * val[cn] + 1000000007) % 1000000007;
  for (auto x : v[cn]) {
    if (x != pn) {
      dp[cn] -= dfs2(x, cn);
      dp[cn] %= 1000000007;
      dp[cn] = (dp[cn] + 1000000007) % 1000000007;
    }
  }
  return dp[cn];
}
void dfs3(int cn, int pn) {
  ans = (ans + dp[cn] + 1000000007 + 1000000007) % 1000000007;
  for (auto x : v[cn]) {
    if (x != pn) {
      dp[cn] = (dp[cn] + dp[x] - sz[x] * val[cn] + 1000000007) % 1000000007;
      sz[cn] -= sz[x];
      dp[x] = (dp[x] + val[x] * sz[cn] - dp[cn] + 1000000007) % 1000000007;
      sz[x] += sz[cn];
      dfs3(x, cn);
      dp[x] = (dp[x] + dp[cn] - sz[cn] * val[x] + 1000000007) % 1000000007;
      sz[x] -= sz[cn];
      dp[cn] = (dp[cn] + val[cn] * sz[x] - dp[x] + 1000000007) % 1000000007;
      sz[cn] += sz[x];
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 1; i < n + 1; i++) cin >> val[i];
    for (long long i = 0; i < n - 1; i++) {
      long long a, b;
      cin >> a >> b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    dfs1(1, 0);
    dfs2(1, 0);
    dfs3(1, 0);
    cout << ans << endl;
  }
  return 0;
}
