#n = 頂点数,edge = 隣接リスト n=int(input()) edge=[[] for i in range(n)] isroot=[True]*n for i in range(n-1): a,b=map(int,input().split()) a-=1;b-=1 edge[a].append(b) isroot[b]=False Root=0 for i in range(n): if isroot[i]:Root=i;break order = [] par = [-1]*n tank = [Root] depth=[0]*n while tank: pele = tank.pop() order.append(pele) for e in edge[pele]: if e == par[pele]: continue tank.append(e) par[e] = pele depth[e]=depth[pele]+1 size = [1]*n for e in order[::-1]: if e == Root: break size[par[e]] += size[e] ans=0 for i in range(n): ans+=size[i]*depth[i] ans%=10**9+7 print(ans)