#P6219. [COCI 2019/2020 #6] Konstrukcija

[COCI 2019/2020 #6] Konstrukcija

Description

Translated from COCI 2019/2020 Contest #6 T3. Konstrukcija

Let GG be a directed acyclic graph. If distinct vertices c1,c2,c3,cnc_1,c_2,c_3,\ldots c_n in GG satisfy that there is a path from c1c_1 to c2c_2, a path from c2c_2 to c3c_3, ..., and a path from cn1c_{n-1} to cnc_n, then the array C=(c1,c2,c3,cn)C = (c_1,c_2,c_3,\ldots c_n) is called an ordered array that starts at c1c_1 and ends at cnc_n.
Note that for any two adjacent elements ci,ci+1c_i,c_{i+1} in CC, there does not have to be a direct edge between them; having a path is enough.

We also define the length of an ordered array C=(c1,c2,c3,cn)C = (c_1,c_2,c_3,\ldots c_n) as len(C)=n\mathrm{len}(C) = n. Therefore, the length of an ordered array is exactly the number of vertices it contains.
Note that an ordered array of length 11 that starts and ends at the same vertex can exist.

Moreover, we define the sign of an ordered array C=(c1,c2,c3,cn)C = (c_1,c_2,c_3,\ldots c_n) as sgn(C)=(1)len(C)+1\mathrm{sgn}(C) = (-1)^{\mathrm{len}(C)+1}.
For vertices x,yx,y in GG, let Sx,yS_{x,y} denote the set of all ordered arrays that start at xx and end at yy.

Finally, we define the contradiction value between vertices x,yx,y as $\mathrm{tns}(x,y) = \sum\limits_{C \in S_{x,y}} \mathrm{sgn}(C)$.
That is, the contradiction value between xx and yy equals the sum of the signs of all ordered arrays that start at xx and end at yy.

Given an integer KK, you need to construct a directed acyclic graph with at most 10001000 vertices and 10001000 edges such that tns(1,N)=K\mathrm{tns}(1,N) = K, where NN is the number of vertices.
Vertices are numbered by positive integers 1N1 \ldots N.

Input Format

The first line contains one integer KK

Output Format

The first line contains two integers N,MN,M, the number of vertices and edges in the directed acyclic graph you construct.
In the next MM lines, the ii-th line contains two distinct integers Xi,YiX_i,Y_i, meaning the ii-th edge is directed from XiX_i to YiY_i. Each edge should appear at most once.
Also, your construction must satisfy that for any two vertices, the absolute value of their contradiction value is at most 2802^{80}.
If there are multiple solutions, output any one of them.

0
6 6
1 4
1 5
4 3
5 3
3 2
2 6
1
1 0
2
6 8
1 2
1 3
1 4
1 5
5 4
2 6
3 6
4 6

Hint

Explanation for Sample 1

The constructed graph has 66 vertices. The ordered arrays that start at 11 and end at 66 are:

  • (1,6)(1, 6)
  • (1,4,6)(1, 4, 6)
  • (1,5,6)(1, 5, 6)
  • (1,3,6)(1, 3, 6)
  • (1,2,6)(1, 2, 6)
  • (1,4,3,6)(1, 4, 3, 6)
  • (1,4,2,6)(1, 4, 2, 6)
  • (1,5,3,6)(1, 5, 3, 6)
  • (1,5,2,6)(1, 5, 2, 6)
  • (1,3,2,6)(1, 3, 2, 6)
  • (1,4,3,2,6)(1, 4, 3, 2, 6)
  • (1,5,3,2,6)(1, 5, 3, 2, 6)

Their lengths are 1,2,2,2,2,3,3,3,3,3,4,41, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, respectively,
so their signs are 1,1,1,1,1,1,1,1,1,1,1,1-1, 1, 1, 1, 1,-1,-1,-1,-1,-1, 1, 1, respectively.
Therefore, the contradiction value between 11 and 66 is 1+1+1+1+111111+1+1=0-1 + 1 + 1 + 1 + 1 - 1 - 1 - 1 - 1 - 1 + 1 + 1 = 0


Constraints

For 100%100\% of the testdata, K1018|K| \le 10^{18}.
The limits for each subtask are shown in the table below:

Subtask Points Limits
00 Sample only
11 1313 1K<5001 \le K < 500
22 300<K1-300 < K \le 1
33 1818 K<10000\lvert K\rvert < 10000
44 5656 -

Translated by ChatGPT 5