import sys sys.setrecursionlimit(10**7) from functools import lru_cache import pypyjit pypyjit.set_param('max_unroll_recursion=-1') mod = 10**9+7 n = int(input()) li = [0]*n ab = [[] for i in range(n)] for i in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 ab[a].append(b) li[b] = 1 for i in range(n): if li[i] == 0: idx = i break num = [0]*n @lru_cache(maxsize=n+1) def dfs(v): if num[v] != 0: return num[v] for i in range(len(ab[v])): num[v] += dfs(ab[v][i]) num[v] += 1 return num[v] dfs(idx) dp = [-1]*n @lru_cache(maxsize=n+1) def dfs2(v): if dp[v] != -1: return dp[v] for i in range(len(ab[v])): dp[v] += dfs2(ab[v][i])+num[ab[v][i]] dp[v] %= mod dp[v] += 1 dp[v] %= mod return dp[v] #print(dp,num) dfs2(idx) ans = 0 for i in range(n): ans += dp[i] ans %= mod #print(sum(dp)%mod) print(ans) #print(dp)