#P7510. Partitioning 1 to 2n into Ordered Pairs with Given Differences
Partitioning 1 to 2n into Ordered Pairs with Given Differences
Partitioning 1 to 2n into Ordered Pairs with Given Differences
You are given a positive integer n. Your task is to partition the integers from 1 to 2n into n ordered pairs \((a_i, b_i)\) (for \(1 \le i \le n\)) such that for each \(i\) the difference satisfies \(a_i - b_i = i\) (in \(\LaTeX\) format, that is \(a_i - b_i = i\)).
If a valid partition exists, output one construction in which the pairs (in the order of \(i=1,2,\dots,n\)) are printed on separate lines. For each pair, output two space‐separated integers: ai and bi. If no valid solution exists, output a single line containing -1 0
.
Note: It can be shown that a necessary and sufficient condition for a solution to exist is that the input n satisfies \(n\equiv0 \text{ or } 1 \; (\bmod\; 4)\). In other cases, output -1 0
.
inputFormat
The input consists of a single integer n on one line.
outputFormat
If a valid partition exists, output n lines. The i-th line should contain two integers ai and bi (separated by a space) such that \(a_i - b_i = i\). Otherwise, output a single line containing -1 0
.
sample
1
2 1