DFS#11793

DFS

1 second
256 megabytes
Very hard

Everyone loves flowers, but flowers on graphs are even better!

Let's define the DFS tree of the graph and the beauty of the tree.

\operatorname{DFS}_{\operatorname{path}}(G) — the DFS tree of the graph (the edges traversed by DFS).

used = array of size |G| initialized to false
edges = empty list

procedure DFS(node):
    mark used[node] as true
    for each neighbor v in G[node]:  # iterate over all edges (node, v) in the original graph
        if not used[v]:
            add (node, v) to edges
            DFS(v)

procedure DFS_path(G):
    DFS(1) 
    return edges

The beauty of the tree is defined this way:

\operatorname{beauty}(T) = \sum_{i=1}^n \operatorname{deg}_i^2

where \operatorname{deg}_i is the degree of vertex in the tree .

Your task is as follows: Construct a simple connected graph with vertices and edges in such a way that maximizes \operatorname{beauty}(\operatorname{DFS}_{\operatorname{path}}(G)), where is the graph.

The problem has types of subtasks:

  1. K = 1: Output only the maximum value of \operatorname{beauty}(\operatorname{DFS}_{\operatorname{path}}(G)).

  2. K = 2: Output the maximum value of \operatorname{beauty}(\operatorname{DFS}_{\operatorname{path}}(G)) and the graph that achieves this value.

A graph is simple if each edge connects two distinct vertices and no two edges connect the same pair of vertices.

A graph is connected if there is a path between every pair of vertices.

Input

The line contains three integers , , (1 \le n \le 3 \cdot 10^5, n - 1 \le m \le \min(3 \cdot 10^5, \frac{n \cdot (n - 1)}{2}), 1 \le K \le 2) — the number of vertices, number of edges, and type of subtask.

Output

On the first line, output the maximum value of \operatorname{beauty}(\operatorname{DFS}_{\operatorname{path}}(G)).

If K = 2, then also output lines, each containing two integers , (1 \le u, v \le n), representing an edge in the constructed graph .

Note that the order in which you print the edges affects the DFS traversal and the value of the beauty function.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading

Note

In the third sample, the following graph could be constructed:

Here numbers on edges mean the order of edges

Our DFS tree will be:

The beauty of it is 1^2 + 2^2 + 3^2 + 1^2 + 1^2 = 16.

It can be proven that this is the best answer.

Scoring

  1. ( points): n \le 4, K = 1;

  2. ( points): n \le 4, K = 2;

  3. ( points): n \le 20, m \le 20, K = 1;

  4. ( points): n \le 20, m \le 20, K = 2;

  5. ( points): n \le 100, m \le 100, K = 1;

  6. ( points): n \le 100, m \le 100, K = 2;

  7. ( points): K = 1;

  8. ( points): K = 2;