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[b-1]=1 for i in range(n): if par[i]==0: root=i break stack=[(root,0)] ans=0 visited=[0]*n while stack: now,depth=stack.pop() ans+=depth*(depth+1)//2 ans%=mod if visited[now]==0: visited[now]=1 for e in es[now]: stack.append((e, depth+1)) print(ans)