import sys sys.setrecursionlimit(10**8) input=sys.stdin.readline def dfs(v,depth,mod): ans[0] += depth*(depth+1)//2 ans[0] %= mod for u in edge[v]: dfs(u,depth+1,mod) return N = int(input()) mod = 10**9+7 edge = [[] for _ in range(N)] roots = [True]*N for _ in range(N-1): a,b = map(int, input().split()) roots[b-1] = False edge[a-1].append(b-1) nums = [-1]*N child = [-1]*N root = roots.index(True) ans = [0] dfs(root,0,mod) print(ans[0])