MOD = 10 ** 9 + 7 n = int(input()) g = [[] for _ in range(n)] par = [None for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 g[a].append(b) par[b] = a src = None for v in range(n): if par[v] is None: src = v break dp = [0 for _ in range(n)] depth = [None for _ in range(n)] depth[src] = 0 st = [~ src, src] ans = 0 while len(st) > 0: cur = st.pop() if cur >= 0: for nxt in g[cur]: depth[nxt] = depth[cur] + 1 st.append(~ nxt) st.append(nxt) else: dp[~ cur] += 1 if not par[~ cur] is None: dp[par[~ cur]] += dp[~ cur] ans = (ans + dp[~ cur] * depth[~ cur]) % MOD print(ans)