Under construction

Still being built. Things may change

Two Trees

Time limit8sMemory limit256 MB

Summary
Given two trees on the same n vertices, compute the sum over all vertex pairs of the squared sum of their distances in both trees, modulo 2^32.
Level

Hard8 of 10

Topics
Tree, Divide and conquer, Math
Solved
No attempts yet

Problem

Trees T1T_1 and T2T_2 are given. Each tree has nn vertices numbered from 11 through nn. Let d(v,u,T)d(v, u, T) be the number of edges on the path between vertices vv and uu in tree TT. Compute the following sum.

∑1≤u<v≤n(d(v,u,T1)+d(v,u,T2))2\sum_{1 \le u < v \le n} \left(d(v, u, T_1) + d(v, u, T_2)\right)^2

The answer may be large, so print it modulo 2322^{32}.

Input

The first line contains one integer nn, the number of vertices in each tree (1≤n≤1000001 \le n \le 100000). Each of the next n−1n-1 lines contains two integers uu and vv, an edge between uu and vv in T1T_1 (1≤u,v≤n1 \le u, v \le n). Each of the last n−1n-1 lines contains two integers uu and vv, an edge between uu and vv in T2T_2 (1≤u,v≤n1 \le u, v \le n).

Output

Print the answer modulo 2322^{32}.

Examples2

  1. Example 1

    Input
    3
    1 2
    1 3
    1 2
    1 3
    
    Expected output
    24
    
  2. Example 2

    Input
    3
    1 2
    1 3
    1 2
    2 3
    
    Expected output
    22