#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using pii = pair; using ll=long long; using ld=long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout<<"YES"<=0;i--) #define rRep(i,a,b) for(ll i=a;i>=b;i--) #define crep(i) for(char i='a';i<='z';++i) #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } template istream& operator>>(istream& is,vector& v){for(auto&& x:v)is >> x;return is;} template istream& operator>>(istream& is, pair& p){ is >> p.first; is >> p.second; return is;} template ostream& operator>>(ostream& os, const pair& p){ os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, vector& v){ for(auto i=begin(v); i != end(v); ++i){ if(i !=begin(v)) os << ' '; os << *i; } return os; } ll K[1000007],Ch[1000007]; ll C[1000007]; vector> E(1000007); void dfs(ll key,ll num){ Ch[key]=1; C[key]=num; rep(i,E[key].size()){ if(Ch[E[key][i]]==0){ dfs(E[key][i],num+1); } } } int main(){ ll N; cin >> N; rep(i,N-1){ ll A,B; cin >> A >> B; A--;B--; K[B]++; E[A].pb(B); } rep(i,N){ if(K[i]==0){ dfs(i,0); //cout << i << endl; } } ll ANS=0; rep(i,N){ ANS+=C[i]*(C[i]+1)/2; ANS%=MOD; } cout << ANS << endl; }