#include <bits/stdc++.h>
using namespace std;
const int maxn = 200003, mod = 1000000007;
int Plus(int x, int y) { return (x += y) >= mod ? x - mod : x; }
void PlusEqual(int &x, int y) {
  if ((x += y) >= mod) x -= mod;
}
int Minus(int x, int y) { return Plus(x, mod - y); }
int mul(long long x, int y) { return x * y % mod; }
vector<int> g[maxn];
int n, a[maxn], dp[maxn][2], cnt[maxn][2], ans;
void dfs(int u, int last) {
  int val[2] = {a[u], Minus(0, a[u])};
  for (int v : g[u]) {
    if (v == last) continue;
    dfs(v, u);
    for (int j = 0; j <= 1; j++) {
      PlusEqual(ans,
                Plus(mul(dp[u][j], cnt[v][!j]), mul(dp[v][!j], cnt[u][j])));
      PlusEqual(dp[u][j], Plus(dp[v][!j], mul(cnt[v][!j], val[j])));
      PlusEqual(cnt[u][j], cnt[v][!j]);
    }
  }
  PlusEqual(ans, dp[u][0]);
  PlusEqual(dp[u][0], val[0]);
  PlusEqual(cnt[u][0], 1);
}
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i), a[i] = (a[i] + ((long long)mod << 2)) % mod,
                        PlusEqual(sum, a[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v), g[v].push_back(u);
  }
  dfs(1, 0);
  printf("%d\n", Plus(mul(ans, 2), sum));
  return 0;
}
