subway

Time limit: 0.05s Memory limit: 128MB Input: Output:

Antonia recently visited London. There, she was impressed by the large number of subway stations, which, to her surprise, formed a tree. While getting bored on the subway, Antonia wondered if she could generate a tree with the minimum number of nodes that would have exactly KK paths from XX to YY, for any nodes XX, YY, provided that XX is an ancestor of YY. By replacing the current subway map with this tree, she believes it could reduce rush-hour congestion.

Task

Help Antonia generate the desired tree with the minimum number of nodes.

Input data

The input will contain a single integer number, KK – the number of pairs with the specified property.

Output data

The output will contain N+1N+1 lines, representing the generated tree, the nodes being indexed from 00.

The first line will contain the number NN – the number of nodes in the tree.

The following NN lines will contain each 2 numbers XX and TT, separated by a space, with the following meaning: node TT is the direct ancestor of node XX. If node XX doesn’t have a direct ancestor, TT will have value 1-1.

Constraints and clarifications

  • For each test, the tree must have at most 10610^6 nodes.
  • 0K1090 \leq K \leq 10^9
  • For every test, you will get:
    1. 100%100\% points if Nparticipant=NcommitteeN_{\text{participant}} = N_{\text{committee}}
    2. 80%80\% points if Nparticipant[Ncommittee+1,Ncommittee+2]N_{\text{participant}} \in [N_{\text{committee}} + 1, N_{\text{committee}} + 2]
    3. P%P\% points if NparticipantNcommittee+3N_{\text{participant}} \geq N_{\text{committee}} + 3, where P=Ncommittee+3Nparticipant50P = \frac{N_{\text{committee}} + 3}{N_{\text{participant}}} \cdot 50
  • Note: NcommitteeN_{\text{committee}} is the minimum number of nodes that a tree with the specified property can be generated with.
# Points Constraints
1 20 0K500 \leq K \leq 50
2 30 0K5000 \leq K \leq 500
3 50 No additional constraints

Example 1

stdin

2

stdout

3
0 -1
1 0
2 0

Explanation

There are 22 pairs (X,Y)(X, Y), such that XX is the ancestor of YY:

(X,Y){(0,1),(0,2)}(X,Y) \in \{(0, 1), (0, 2)\}

Example 2

stdin

4

stdout

4
0 -1
1 0
2 0
3 2

Explanation

There are 44 pairs (X,Y)(X, Y), such that XX is the ancestor of YY:

(X,Y){(0,1),(0,2),(0,3),(2,3)}(X,Y) \in \{(0, 1), (0, 2), (0, 3), (2, 3)\}

Log in or sign up to be able to send submissions!