from collections import deque 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 root = parent.index(None) pool = deque([root, -1]) ans = 0 d, n = 0, 0 while pool: node = pool.popleft() if node < 0: ans += (n * d * (d+1) // 2) % MOD ans %= MOD n = 0 d += 1 if pool: pool.append(-1) else: break else: n += 1 for c in children[node]: pool.append(c) print(ans)