from collections import defaultdict MOD = 10**9 + 7 inpl = lambda: list(map(int,input().split())) N = int(input()) children = [[] for _ in range(N)] parent = [None] * N for _ in range(N-1): A, B = inpl() A, B = A-1, B-1 children[A].append(B) parent[B] = A layer = defaultdict(int) forward, back = 0, 1 root = parent.index(None) pool = [(root,0)] while pool: node, d = pool.pop() layer[d] += 1 for c in children[node]: pool.append((c, d+1)) ans = 0 for d, n in layer.items(): ans += n*d*(d+1)//2 ans %= MOD print(ans)