#P7117. Mivik 卷积

Mivik 卷积

Description

Once upon a time, there was a Mivik who liked convolution. He defines the Mivik convolution of two polynomial functions f(x)f\left(x\right) and g(x)g\left(x\right) (both only related to xx) as follows:

$$f\left(x\right)\otimes g\left(x\right)=\sum_{k=0}^{\deg f +\deg g}\max_{i\in [0,\deg f] \land j\in [0,\deg g]\land i+j=k}\left\{\left[x^i\right]f\left(x\right)+\left[x^j\right]g\left(x\right)\right\} x^k$$

Here degf\deg f denotes the highest degree of ff, and [xi]f(x)\left[x^i\right]f\left(x\right) denotes the coefficient of the xix^i term in f(x)f\left(x\right).

Note that Mivik convolution is left-associative, i.e., abc=(ab)ca\otimes b\otimes c=(a\otimes b)\otimes c.

Mivik defines a Mivik function as a function that can be written in the form f(x)=ax+bf\left(x\right)=ax+b, where aa and bb are both integers. For example, f(x)=3+2xf\left(x\right)=-3+2x is a Mivik function, while f(x)=1xf\left(x\right)=\frac{1}{x} is not.

Mivik also defines a function f(x)f\left(x\right) to be simple if and only if there exists a sequence SS of Mivik functions (of size S\left|S\right|) such that:

$$f\left(x\right)=S_1\otimes S_2\otimes S_3\otimes\cdots\otimes S_{\left|S\right|}.$$

Now Mivik gives you a polynomial function. Determine whether this function is simple. If it is, also output any possible SS.

Input Format

The first line contains a positive integer nn, representing the number of terms of this polynomial function.

The second line contains nn integers. From low degree to high degree, they represent the coefficients fif_i of this polynomial function. It is guaranteed that the highest-degree coefficient is non-zero.

Output Format

If this function is not simple, output one line nice.

Otherwise, first output one line simple, then output one line with the size S\left|S\right| of the sequence SS you construct. In the next S\left|S\right| lines, output the sequence SS you construct. Each line contains two integers aa and bb, describing a Mivik function f(x)=ax+bf\left(x\right)=ax+b.

3
2 3 3

simple
2
2 1
1 1

3
97 109 101

simple
2
54 42
47 55

9
9 9 8 2 4 4 3 5 3

nice

Hint

Sample Explanation #1

The given function f(x)=2+3x+3x2f\left(x\right)=2+3x+3x^2 can be obtained from (2x+1)(x+1)\left(2x+1\right)\otimes\left(x+1\right).

Constraints

This problem uses bundled testdata.

For all data, 1n5×1051\le n\le 5\times 10^5, 108fi108-10^8\le f_i\le 10^8.

The detailed limits for each subtask are shown in the table below:

Subtask ID Score nn\le
1 5 11
2 22
3 20 2020
4 30 50005000
5 40 5×1055\times 10^5

The input and output size of this problem is large. Please use fast I/O.

Translated by ChatGPT 5