n=int(input()) mod=10**9+7 es=[[] for _ in range(n)] par=[-1]*n for _ in range(n-1): a,b=map(int,input().split()) es[a-1].append(b-1) if par[b-1]==-1: par[b-1]=a-1 for i in range(n): if par[i]==-1: root=i break new=[] # dfs from collections import deque, Counter stack=deque([(root,0)]) ans=0 while stack: now,depth=stack.pop() new.append((now,depth)) for e in es[now]: stack.append((e, depth+1)) ans+=(depth+1)*(depth+2)//2 ans%=mod print(ans%mod)