Vera and Trail Building

Given K, follow a fixed greedy decomposition into complete blocks and print the resulting connected trail network with exactly K two-edge-disjoint paths.

Easy3GreedyGraphImplementationMathNo attempts yetTime limit1sMemory limit512 MB

Problem

Vera loves hiking and is building her own trail network. The network has VV places numbered 11 to VV and EE bidirectional trails, where trail ii directly joins two distinct places aia_i and bib_i. The network has to be connected, so it is possible to hike between any two places along the trails. More than one trail may directly join the same pair of places.

Two places aa and bb with a<ba < b form a beautifully connected pair if Vera can hike from aa to bb and then back to aa without hiking on the same trail more than once. Vera calls her network beautiful if it has exactly KK beautifully connected pairs.

Vera does not want her network to be too large, so it has to satisfy 1V,E50001 \le V, E \le 5000.

For almost every KK many beautiful networks exist, so this problem asks for one specific network. The output section states exactly which one to print.

Input

The first line contains one integer KK (1K1071 \le K \le 10^7).

Output

Build the network with the rule below and print it. Nothing else is accepted.

First split KK into blocks. Start with an empty list and repeat while K>0K > 0: take the largest integer mm with m2m \ge 2 and m(m1)/2Km(m-1)/2 \le K, append mm to the list, then replace KK by Km(m1)/2K - m(m-1)/2. Call the resulting list m1,m2,,mtm_1, m_2, \dots, m_t and let V=m1+m2++mtV = m_1 + m_2 + \dots + m_t.

Number the places 11 to VV and give every block a consecutive range of places: block 11 takes places 11 to m1m_1, block 22 takes the next m2m_2 places, and so on. Write sjs_j for the first place of block jj and eje_j for its last place.

The first line of the output contains VV and E=V+t1E = V + t - 1, separated by one space. Each of the next EE lines contains the two places of one trail, separated by one space, in the order described here.

For j=1,2,,tj = 1, 2, \dots, t, print the trails of block jj:

  • if mj=2m_j = 2, print the line "sjs_j eje_j" twice;
  • if mj3m_j \ge 3, print the mjm_j trails (sj,sj+1)(s_j, s_j + 1), (sj+1,sj+2)(s_j + 1, s_j + 2), up to (ej1,ej)(e_j - 1, e_j), and then (ej,sj)(e_j, s_j), one per line, each with its first place written first.

After the trails of all tt blocks, print the t1t - 1 joining trails: for j=2,3,,tj = 2, 3, \dots, t, print the line "ej1e_{j-1} sjs_j".

This network is connected, has exactly KK beautifully connected pairs, and satisfies V4587V \le 4587 and E4592E \le 4592 for every allowed KK.

Note

In the first example K=2K = 2, so the blocks are m1=2m_1 = 2 and m2=2m_2 = 2. Places 11 and 22 are joined by two trails, places 33 and 44 are joined by two trails, and the trail between places 22 and 33 joins the two blocks. The two beautifully connected pairs are (1,2)(1, 2) and (3,4)(3, 4).

In the second example K=6K = 6, so there is one block with m1=4m_1 = 4 and the network is a cycle on four places. All six pairs of places form a beautifully connected pair.