1 sekunda / 512 MiB / 110 points Let $G$ be a directed acyclic graph. If $c_{1}$, $c_{2}$, $c_{3}$, . . . $c_{n}$ are distinct vertices of $G$ such that there is a path from $c_{1}$ to $c_{2}$, there is a path from $c_{2}$ to $c_{3}$, . . . and there is a path from $c_{$n - 1$}$ to $c_{n}$, we say that array $C$ = ($c_{1}$, $c_{2}$, $c_{3}$, . . . $c_{n}$) is an ordered array starting at $c_{1}$ and ending at $c_{n}$. Note that between neighbouring elements $c_{i}$ and $c_{$i+1$}$ of ordered array $C$ it isn’t necessary to exist a direct edge, it is enough for the path to exist from $c_{i}$ to $c_{$i+1$}$. For this definition of an ordered array $C$ = ($c_{1}$, $c_{2}$, $c_{3}$, . . . $c_{n}$), we define its length len($C$) = $n$. Therefore, the length of an ordered array is equal to the number of vertices it holds. Note that the ordered array can have a length of 1 when holding a single vertex which represents both its beginning and its end. Also, for an ordered array $C$ = ($c_{1}$, $c_{2}$, $c_{3}$, . . . $c_{n}$) we can define its sign as sgn($C$) = (−1)^{len(C)+1}. For vertices $x$ and $y$ of $G$, let’s denote with $S_{x,y}$ a set of all ordered arrays that start in $x$ and end in $y$. Finally, we define the tension between nodes $x$ and $y$ as tns(x, y) = ^{P} _{C∈Sx,y} ^{sgn(C).} ^{Therefore,} ^{the} tension between nodes $x$ and $y$ equals the sum of signs of all ordered arrays that start in $x$ and end in $y$. An integer $K$ is given. Your task is to construct a directed acyclic graph with at most 1000 vertices and at most 1000 edges for which tns(1, N) = $K$ holds. Number $N$ in the previous expression denotes the number of vertices in a graph. Vertices of a graph should be indexed using positive integers from 1 to $N$.
Input
The first line contains an integer $K$ (|$K$| ≤$10^{18}$) from the task description.
Output
In the first line you should output the number of vertices and the number of edges of the constructed graph. Let’s denote the number of vertices of that graph with $N$ ($1 \le N \le 1000$), and the number of edges with $M$ ($0 \le M \le 1000$). In the $i$-th of the next $M$ lines you should output two distinct integers $X_{i}$ and $Y_{i}$ ($1 \le X_{i}$, $Y_{i} \le N$), which represent the $i$-th edge which is directed from vertex with index $X_{i}$ towards vertex with index $Y_{i}$. Each edge must appear only once in the output. Also, the absolute value of tension between each two nodes in the graph must be less or equal to $2^{80}$. If there are multiple solutions, output any of them.
Constraints
Subtask 1 (15 points): $1 \le K < 500$
Subtask 2 (15 points): −$300 < K \le 1$
Subtask 3 (20 points): |$K$| < 10000
Subtask 4 (60 points): No additional constraints. 1 sekunda / 512 MiB / 110 points
Example 1
0
6 6 1 4 1 5 4 3 5 3 3 2 2 6
Example 2
1
1 0
Example 3
2
6 8 1 2 1 3 1 4 1 5 5 4 2 6 3 6 4 6
Clarification of the first example: The constructed graph has 6 vertices. Ordered arrays that start in 1 and end in 6 are: (1, 6), (1, 4, 6), (1, 5, 6), (1, 3, 6), (1, 2, 6), (1, 4, 3, 6), (1, 4, 2, 6), (1, 5, 3, 6), (1, 5, 2, 6), (1, 3, 2, 6), (1, 4, 3, 2, 6), (1, 5, 3, 2, 6). Their lengths are (in order): 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, so their signs are −1, 1, 1, 1, 1, −1, −1, −1, −1, −1, 1, 1. Therefore, the tension between 1 and 6 is equal to −1 + 1 + 1 + 1 + 1 −1 −1 −1 −1 −1 + 1 + 1 = 0.
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.