P29525 [洛谷] Mivik Convolution
提高-
题目描述

Problem Background

The King of Rolling (doge)

Problem Description

Once upon a time, there was a Mivik who loved convolutions. He defined the Mivik convolution of two polynomial functions \( f(x) \) and \( g(x) \) that depend only on \( x \) as follows:

\[ f(x) \otimes g(x) = \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(x) + \left[ x^j \right] g(x) \right\} x^k \]

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

Note that the Mivik convolution is left-associative, meaning \( a \otimes b \otimes c = (a \otimes b) \otimes c \).

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

Mivik also defines a function \( f(x) \) as simple if and only if there exists a sequence \( S \) of Mivik functions (with size \( |S| \)) such that:

\[ f(x) = S_1 \otimes S_2 \otimes S_3 \otimes \cdots \otimes S_{|S|}. \]

Now, Mivik gives you a polynomial function and asks if it is simple; if it is, please also provide him with any possible sequence \( S \).

Input Format

The first line contains a positive integer \( n \), representing the number of terms in the polynomial function.

The second line contains \( n \) integers, from lowest to highest degree, representing the coefficients \( f_i \) of the polynomial function. It is guaranteed that the highest degree coefficient is not zero.

Output Format

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

Otherwise, first output one line simple, then output the size \( |S| \) of the constructed sequence \( S \) on the next line. Following that, output \( |S| \) lines, each containing two integers \( a \) and \( b \), describing a Mivik function \( f(x) = ax + b \).

Sample Input and Output

Sample Input #1

3
2 3 3

Sample Output #1

simple
2
2 1
1 1

Sample Input #2

3
97 109 101

Sample Output #2

simple
2
54 42
47 55

Sample Input #3

9
9 9 8 2 4 4 3 5 3

Sample Output #3

nice

Notes

Sample Explanation #1

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

Test Case Constraints

This problem is bundled test.

For all data, \( 1 \le n \le 5 \times 10^5 \) and \( -10^8 \le f_i \le 10^8 \).

The specific restrictions for each subtask are shown in the table below:

Subtask Number Score \( n \le \)
1 5 1
2 5 2
3 20 20
4 30 5000
5 40 $5 \times 10^5$

This problem has a large input/output size, please use fast input/output methods.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 3 3
样例输出
simple 2 2 1 1 1