#include using namespace std; #define int long long templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b tree[1000010]; int rtree[1000010]; int dfs(int i, int j){ int ans = (j*(j+1))/2 % MOD; for(auto e : tree[i]){ ans += dfs(e, j+1); ans %= MOD; } return ans; } signed main(){ int n; cin >> n; int a, b; memset(rtree, -1, sizeof(rtree)); for(int i = 0;i < n-1;i++){ cin >> a >> b; a--; b--; tree[a].push_back(b); rtree[b] = a; } int root = 0; while(rtree[root] != -1) root = rtree[root]; cout << dfs(root, 0) << endl; return 0; }