func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int add(int a, int b) { return (a + b) % MOD; }   int sub(int a, int b) { return add(a, MOD - b); }   int mul(int a, int b) { return ((long long)a * b) % MOD; }   int inv(int a) {     int b = 1;     for (int i = 0; (1 << i) <= MOD - 2; i++) {       if ((1 << i) & (MOD - 2)) b = mul(b, a);       a = mul(a, a);     }     return b;   }   const int MAXN = 1e5 + 10;   vector<int> e[MAXN];   int val[MAXN], sz[MAXN], parent[MAXN];   map<int, int> dist[MAXN];   int A[MAXN], B[MAXN], total;   bool active[MAXN];   vector<int> in[MAXN], out[MAXN];   int calc_sz(int i, int p) {     sz[i] = 1;     for (int j : e[i]) {       if (!active[j] || j == p) continue;       sz[i] += calc_sz(j, i);     }     return sz[i];   }   int find_centroid(int i, int p, int n) {     for (int j : e[i]) {       if (!active[j] || j == p) continue;       if (sz[j] > n / 2) return find_centroid(j, i, n);     }     return i;   }   void calc_dist(int i, int p, int r, int d) {     dist[i][r] = d;     for (int j : e[i]) {       if (!active[j] || j == p) continue;       calc_dist(j, i, r, d + 1);     }   }   int build_centroid(int i) {     i = find_centroid(i, -1, calc_sz(i, -1));     calc_dist(i, -1, i, 0);     active[i] = false;     for (int j : e[i]) {       if (!active[j]) continue;       parent[build_centroid(j)] = i;     }     return i;   }   void update(int i, int k) {     int v = mul(val[i], MOD + k);     for (int p = i; p != -1; p = parent[p]) {       total = sub(total, mul(A[p], B[p]));       A[p] = add(A[p], mul(v, dist[i][p]));       if (parent[p] != -1) A[p] = sub(A[p], mul(v, dist[i][parent[p]]));       B[p] = add(B[p], v);       total = add(total, mul(A[p], B[p]));     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int t = 1;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       in[l].push_back(i);       out[r].push_back(i);       val[i] = inv(r - l + 1);       t = mul(t, r - l + 1);       active[i] = true;     }     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       e[x].push_back(y);       e[y].push_back(x);     }     parent[build_centroid(0)] = -1;     int sol = 0;     for (int color = 0; color < MAXN; color++) {       for (int i : in[color]) update(i, 1);       sol = add(sol, total);       for (int i : out[color]) update(i, -1);     }     cout << mul(sol, t);     return 0;   }   