import sys input = sys.stdin.readline from collections import deque MOD = 10**9+7 class Tree: def __init__(self, N): self.V = N self.edge = [[] for _ in range(N)] self.to = [False]*N def add_edges(self, ind=1, bi=True): for i in range(self.V-1): a,b = map(int, input().split()) a -= ind; b -= ind self.edge[a].append(b) self.to[b] = True if bi: self.edge[b].append(a) def add_edge(self, a, b, bi=True): self.edge[a].append(b) if bi: self.edge[b].append(a) def dfs(self): for v in range(self.V): if not self.to[v]: start = v break stack = deque([start]) self.parent = [N]*N self.parent[start] = -1 cnt = 0 self.depth = [-1]*self.V self.depth[start] = 0 #記録したい値の配列を定義 while stack: v = stack.pop() for u in self.edge[v]: if u==self.parent[v]: continue self.parent[u]=v stack.append(u) self.depth[u] = self.depth[v]+1 cnt += self.depth[u]*(self.depth[u]+1)//2 cnt %= MOD return cnt N = int(input()) G = Tree(N) G.add_edges(ind=1, bi=False) print(G.dfs())