Codeforces Round 792 (Div. 1 + Div. 2)
G
Euclid Guess
Codeforces
2800
原题
← FH →
翻译中…

Let's consider Euclid's algorithm for finding the greatest common divisor, where $t$ is a list:

翻译中…

function Euclid(a, b):
    if a < b:
        swap(a, b)

    if b == 0:
        return a

    r = reminder from dividing a by b
    if r > 0:
        append r to the back of t

    return Euclid(b, r)

翻译中…

There is an array $p$ of pairs of positive integers that are not greater than $m$. Initially, the list $t$ is empty. Then the function is run on each pair in $p$. After that the list $t$ is shuffled and given to you.

翻译中…

You have to find an array $p$ of any size not greater than $2 \cdot 10^4$ that produces the given list $t$, or tell that no such array exists.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ ($1 \le n \le 10^3$, $1 \le m \le 10^9$) — the length of the array $t$ and the constraint for integers in pairs.

翻译中…

The second line contains $n$ integers $t_1, t_2, \ldots, t_n$ ($1 \le t_i \le m$) — the elements of the array $t$.

翻译中…

Output

翻译中…
  • If the answer does not exist, output $-1$.
  • If the answer exists, in the first line output $k$ ($1 \le k \le 2 \cdot 10^4$) — the size of your array $p$, i. e. the number of pairs in the answer. The $i$-th of the next $k$ lines should contain two integers $a_i$ and $b_i$ ($1 \le a_i, b_i \le m$) — the $i$-th pair in $p$.
翻译中…

If there are multiple valid answers you can output any of them.

翻译中…

Note

翻译中…

In the first sample let's consider the array $t$ for each pair:

翻译中…
  • $(19,\, 11)$: $t = [8, 3, 2, 1]$;
  • $(15,\, 9)$: $t = [6, 3]$;
  • $(3,\, 7)$: $t = [1]$.
翻译中…

So in total $t = [8, 3, 2, 1, 6, 3, 1]$, which is the same as the input $t$ (up to a permutation).

翻译中…

In the second test case it is impossible to find such array $p$ of pairs that all integers are not greater than $10$ and $t = [7, 1]$

翻译中…

In the third test case for the pair $(15,\, 8)$ array $t$ will be $[7, 1]$.

翻译中…

样例

Input #1
7 20
1 8 1 6 3 2 3
Output #1
3
19 11
15 9
3 7
InputCopy OutputCopy
Input #2
2 10
7 1
Output #2
-1
InputCopy OutputCopy
Input #3
2 15
1 7
Output #3
1
15 8
InputCopy OutputCopy
Input #4
1 1000000000
845063470
Output #4
-1
InputCopy OutputCopy
题目信息
题号
1684G
时间限制
1 s
内存限制
256 MB
标签
构造
网络流
图匹配
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。