import collections N = int(input()) lsg = [[] for i in range(N)] per = [0]*(N) for i in range(N-1): a,b = map(int,input().split()) a -= 1 b -= 1 lsg[a].append(b) per[b] += 1 r = -1 for i in range(N): if per[i] == 0: r = i break d = collections.deque([r]) depth = [0]*(N) while d: x = d.popleft() for j in lsg[x]: depth[j] = depth[x]+1 d.append(j) ans = 0 for i in range(N): ans += (depth[i])*(depth[i]+1)//2 print(ans%(10**9+7))