#include <bits/stdc++.h>
using namespace std;
const long long MAX = 200200, MOD = 1000000007;
vector<int> graf[MAX];
long long n, a, b, dp[MAX][2], ctr[MAX][2], val[MAX], ojc[MAX], res = 0,
                                                                sum = 0;
bool vis[MAX];
void licz(int v) {
  int u;
  vis[v] = true;
  for (int i = 0; i < graf[v].size(); i++) {
    if (!vis[graf[v][i]]) {
      ojc[graf[v][i]] = v;
      licz(graf[v][i]);
    }
  }
  for (int i = 0; i < graf[v].size(); i++) {
    u = graf[v][i];
    if (u != ojc[v]) {
      dp[v][0] += (dp[u][1] - val[v] * ctr[u][1]);
      dp[v][1] += (dp[u][0] + val[v] * ctr[u][0]);
      for (int j = 0; j <= 1; j++) {
        dp[v][j] %= MOD;
        ctr[v][j] += ctr[u][1 - j];
      }
    }
  }
  long long tmp = 0;
  for (int i = 0; i < graf[v].size(); i++) {
    u = graf[v][i];
    if (u != ojc[v]) {
      res += (dp[u][0] * (ctr[v][1] - ctr[u][0]));
      res += (dp[u][1] * (ctr[v][0] - ctr[u][1]));
      tmp += (val[v] * (ctr[v][1] - ctr[u][0]) * ctr[u][0]);
      tmp -= (val[v] * (ctr[v][0] - ctr[u][1]) * ctr[u][1]);
      res = (res + tmp / 2) % MOD;
      tmp %= 2;
    }
  }
  ctr[v][1]++;
  dp[v][1] += val[v];
  res = (res + dp[v][1]) % 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 >> val[i];
    sum += val[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    graf[a].push_back(b);
    graf[b].push_back(a);
  }
  licz(1);
  res = (res * 2 - sum) % MOD;
  if (res < 0) res += MOD;
  cout << res << "\n";
}
