#include <bits/stdc++.h>
using namespace std;
const long long N = 4e5;
const long long MO = 1e9 + 7;
long long ch[N], oe[N], a[N], first, second, z, so, n;
vector<long long> ke[N];
void dfs(long long first, long long z) {
  ch[first] = 1;
  oe[first] = -1;
  (so += a[first] * n) %= MO;
  for (auto& second : ke[first])
    if (second != z) {
      dfs(second, first);
      ch[first] += ch[second];
      oe[first] -= oe[second];
      (so += a[first] * oe[second] % MO * (n - ch[second])) %= MO;
    }
}
void dfz(long long first, long long z, long long p) {
  (so += a[first] * p % MO * ch[first]) %= MO;
  for (auto& second : ke[first])
    if (second != z) {
      dfz(second, first, -(p - oe[first] - oe[second]));
    }
}
int main() {
  cin >> n;
  for (long long i = (long long)1; i <= (long long)n; i++) cin >> a[i];
  for (long long i = (long long)1; i <= (long long)n - 1; i++) {
    cin >> first >> second;
    ke[first].push_back(second);
    ke[second].push_back(first);
  }
  dfs(1, 1);
  dfz(1, 1, 0);
  cout << (so + MO) % MO << " ";
}
