func_code_string: #include <bits/stdc++.h>   namespace FastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   template <class T>   inline bool read(T& x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return false;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return true;   }   template <class T, class... U>   bool read(T& h, U&... t) {     return read(h) && read(t...);   }   };  // namespace FastIO   using namespace std;   using namespace FastIO;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int INF = 0x3f3f3f3f;   const int N = 2e5 + 10;   const int mod = 1e9 + 7;   vector<long long> e[N];   long long dis[N][2], siz[N][2], n, ans, w[N];   void dfs(long long u, long long fa) {     siz[u][1] = 1;     dis[u][1] = (w[u] + mod) % mod;     for (auto v : e[u]) {       if (v == fa) continue;       dfs(v, u);       ans =           (ans + dis[u][0] * siz[v][1] % mod + dis[v][1] * siz[u][0] % mod) % mod;       ans =           (ans + dis[u][1] * siz[v][0] % mod + dis[v][0] * siz[u][1] % mod) % mod;       siz[u][0] += siz[v][1];       siz[u][1] += siz[v][0];       dis[u][0] = (dis[u][0] + dis[v][1] - w[u] * siz[v][1] % mod + mod) % mod;       dis[u][1] = (dis[u][1] + dis[v][0] + w[u] * siz[v][0] % mod + mod) % mod;     }   }   signed main() {     read(n);     for (long long i = 1; i <= n; i++) read(w[i]);     for (long long i = 1; i < n; i++) {       long long u, v;       read(u, v);       e[u].push_back(v);       e[v].push_back(u);     }     dfs(1, 1);     ans *= 2;     ans %= mod;     for (long long i = 1; i <= n; i++) ans = (ans + w[i] + mod) % mod;     cout << ans << endl;     return 0;   }   