import sys import io, os input = sys.stdin.buffer.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline mod = 10**9+7 def main(): n = int(input()) g = [[] for _ in range(n)] ind = [[] for _ in range(n)] for i in range(n-1): a, b = map(int, input().split()) a, b = a-1, b-1 g[a].append(b) ind[b].append(a) root = -1 for i in range(n): if len(ind[i]) == 0: root = i break s = [] s.append(root) order = [] par = [-1]*n depth = [0]*n while s: v = s.pop() order.append(v) for u in g[v]: if u == par[v]: continue par[u] = v s.append(u) depth[u] = depth[v]+1 #print(depth) ans = 0 for i in range(n): d = depth[i] ans += d*(d+1)//2 ans %= mod print(ans) if __name__ == '__main__': main()