#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n;
long long p[200002], i[200002], v[200002], lvl[200002], ans;
vector<int> G[200002];
void dfs(int x, int par) {
  if (par) lvl[x] = lvl[par] + 1;
  for (auto it : G[x]) {
    if (it == par) continue;
    dfs(it, x);
    ans = (ans +
           2 * v[x] * (i[x] * p[it] % mod - p[x] * i[it] % mod + mod) % mod);
    i[x] += p[it];
    p[x] += i[it];
  }
  i[x]++;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> v[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(1, 0);
  for (int it = 1; it <= n; it++) {
    if (lvl[it] % 2)
      ans = (ans + 2 * v[it] *
                       (i[it] * (p[1] - i[it] + 1) % mod -
                        p[it] * (i[1] - p[it]) % mod + mod) %
                       mod) %
            mod;
    else {
      ans = (ans + 2 * v[it] *
                       (i[it] * (i[1] - i[it] + 1) % mod -
                        p[it] * (p[1] - p[it]) % mod + mod) %
                       mod) %
            mod;
    }
    ans = (ans - v[it] + mod) % mod;
  }
  cout << ans;
  return 0;
}
