#include using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using ld = long double; using pii = pair; using pil = pair; using pli = pair; using pll = pair; const ll MOD = 1e9+7; //const ll MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const ld EPS = 1e-10; template bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; const int MAX_V = 1e6; vector es[MAX_V], rs[MAX_V]; ll subtree_size[MAX_V]; ll ans = 0; ll dfs(int now){ ll ret = 0, s = 1; for(auto &e: es[now]){ ret += dfs(e)+subtree_size[e]; s += subtree_size[e]; } subtree_size[now] = s; ans += ret, ans %= MOD; return ret; } int main(){ int N; cin >> N; rep(i, N-1){ int A, B; cin >> A >> B; A--, B--; es[A].pb(B), rs[B].pb(A); } int root = -1; rep(i, N) if(rs[i].empty()) root = i; dfs(root); cout << ans << endl; }