Under construction

Still being built. Things may change

f(x)\sqrt{f}(x)

Time limit1sMemory limit1024 MB

Summary
Given an integer polynomial f, find a polynomial g with coefficients from -100 to 100 such that g(g(x)) = f(x), or report -1.
Level

Hard8 of 10

Topics
Math, Number theory, Implementation
Solved
No attempts yet

Problem

A polynomial f(x)=anxn+an−1xn−1+⋯+a1x+a0f(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_1 x + a_0 with integer coefficients, defined for all real xx, is given.

If a polynomial g(x)=bmxm+bm−1xm−1+⋯+b1x+b0g(x) = b_m x^m + b_{m-1} x^{m-1} + \cdots + b_1 x + b_0 satisfies g(g(x))=f(x)g(g(x)) = f(x) for all xx, then gg is called a square root of ff.

Determine whether ff has a square root gg in which every coefficient bib_i is an integer between −100-100 and 100100 inclusive. If one exists, print any such gg.

Input

The first line contains the degree nn of f(x)f(x).

The second line contains the coefficients an,an−1,⋯ ,a1,a0a_n, a_{n-1}, \cdots, a_1, a_0 of f(x)f(x), separated by spaces.

Output

If a polynomial g(x)=bmxm+bm−1xm−1+⋯+b1x+b0g(x) = b_m x^m + b_{m-1} x^{m-1} + \cdots + b_1 x + b_0 (bm≠0b_m \neq 0) satisfying the conditions exists, print mm on the first line. Then print bm,bm−1,⋯ ,b1,b0b_m, b_{m-1}, \cdots, b_1, b_0 in that order, separated by spaces, on the second line. If several answers exist, print any one of them.

If g(x)g(x) does not exist, print -1 on the first line.

Constraints

  • 1≤n≤251 \le n \le 25
  • −1015≤ai≤1015-10^{15} \le a_i \le 10^{15}, an≠0a_n \neq 0

Examples1

  1. Example 1

    Input
    4
    -1 0 -2 0 -2
    
    Expected output
    2
    -1 0 -1