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