import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { static int n; static List> list; static long ans = 0; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); list = new ArrayList<>(n); for (int i = 0; i < n; i++) { list.add(new ArrayList<>()); } boolean[] in = new boolean[n]; for (int i = 0; i < n - 1; i++) { String[] sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]) - 1; int b = Integer.parseInt(sa[1]) - 1; list.get(a).add(b); if (in[b]) { throw new Exception(); } in[b] = true; } br.close(); int root = 0; for (int i = 0; i < in.length; i++) { if (!in[i]) { root = i; break; } } dfs(root, -1, 1); System.out.println(ans % 1000000007); } static long dfs(int x, int p, long size) { long cnt = 0; for (int next : list.get(x)) { if (next != p) { cnt += dfs(next, x, size + 1); } } ans += cnt * size; return cnt + 1; } }