import java.util.*; import java.io.*; public class Main { static ArrayList> graph = new ArrayList<>(); static final int MOD = 1000000007; static long ans = 0; public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); TreeSet used = new TreeSet<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); used.add(i); } int[] ins = new int[n - 1]; int[] outs = new int[n - 1]; for (int i = 0; i < n - 1; i++) { String[] line = br.readLine().split(" ", 2); ins[i] = Integer.parseInt(line[0]) - 1; outs[i] = Integer.parseInt(line[1]) - 1; graph.get(ins[i]).add(outs[i]); used.remove(outs[i]); } calcAnswer(used.first(), 1); System.out.println(ans); } static int calcAnswer(int idx, long depth) { int count = 1; for (int x : graph.get(idx)) { int child = calcAnswer(x, depth + 1); ans += depth * child % MOD; ans %= MOD; count += child; } return count; } }