def main(): from collections import deque import sys input = sys.stdin.readline N = int(input()) 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) ans = 0 mod = 10**9+7 d = deque() root = roots.index(True) d.append([root,0]) while len(d)>0: v,depth = d.popleft() ans += depth*(depth+1)//2 ans %= mod for w in edge[v]: d.append([w,depth+1]) print(ans) if __name__ == '__main__': main()