Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tags yet

No tag edit access

E2. Three Trees

time limit per test

3 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputThis problem consists of two subproblems: for solving subproblem E1 you will receive 11 points, and for solving subproblem E2 you will receive 13 points.

A tree is an undirected connected graph containing no cycles. The distance between two nodes in an unweighted tree is the minimum number of edges that have to be traversed to get from one node to another.

You are given 3 trees that have to be united into a single tree by adding two edges between these trees. Each of these edges can connect any pair of nodes from two trees. After the trees are connected, the distances between all unordered pairs of nodes in the united tree should be computed. What is the maximum possible value of the sum of these distances?

Input

The first line contains three space-separated integers *n*_{1}, *n*_{2}, *n*_{3} — the number of vertices in the first, second, and third trees, respectively. The following *n*_{1} - 1 lines describe the first tree. Each of these lines describes an edge in the first tree and contains a pair of integers separated by a single space — the numeric labels of vertices connected by the edge. The following *n*_{2} - 1 lines describe the second tree in the same fashion, and the *n*_{3} - 1 lines after that similarly describe the third tree. The vertices in each tree are numbered with consecutive integers starting with 1.

The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.

- In subproblem E1 (11 points), the number of vertices in each tree will be between 1 and 1000, inclusive.
- In subproblem E2 (13 points), the number of vertices in each tree will be between 1 and 100000, inclusive.

Output

Print a single integer number — the maximum possible sum of distances between all pairs of nodes in the united tree.

Examples

Input

2 2 3

1 2

1 2

1 2

2 3

Output

56

Input

5 1 4

1 2

2 5

3 4

4 2

1 2

1 3

1 4

Output

151

Note

Consider the first test case. There are two trees composed of two nodes, and one tree with three nodes. The maximum possible answer is obtained if the trees are connected in a single chain of 7 vertices.

In the second test case, a possible choice of new edges to obtain the maximum answer is the following:

- Connect node 3 from the first tree to node 1 from the second tree;
- Connect node 2 from the third tree to node 1 from the second tree.

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/23/2017 20:19:21 (c3).

Desktop version, switch to mobile version.

User lists

Name |
---|