#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; ll n = 1000005; vector> tree(n,vector()); ll ans = 0; ll dfs(int i,ll depth=1,int before=-1){ ll res = 0; for(int c:tree[i]){ if(c==before) continue; ll p = dfs(c,depth+1,i); ans = (ans + (depth*p)%MOD)%MOD; res += p; } return res+1; } int main(){ cin >> n; vector cnt(n); rep(i,n-1){ int a,b; cin >> a >> b; --a;--b; tree[a].push_back(b); tree[b].push_back(a); cnt[b] ++; } int id = -1; rep(i,n){ if(cnt[i]==0) id = i; } dfs(id); cout << ans << endl; return 0; }