#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("YES");}else{puts("NO");} #define MAX_N 1000005 vector G[MAX_N]; int par_[MAX_N]; int main() { int n; cin >> n; rep(i,n)par_[i] = -1; ll MOD = 1000000007; rep(i,n-1){ int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); par_[b] = a; } int r = -1; rep(i,n)if(par_[i] == -1)r = i; ll ans = 0; queue que; que.push(r); ll d[n] = {}; while(que.size()>0){ int x = que.front(); que.pop(); ans += d[x] * (d[x] + 1) / 2; ans %= MOD; rep(i,G[x].size()){ int y = G[x][i]; d[y] = d[x] + 1; que.push(y); } } cout << ans << endl; return 0; }