Under construction

Still being built. Things may change

Unique Solution

Time limit1sMemory limit512 MB

Summary
Given a target array a with entries -1, 0, or 1, find m and x so that only a and -a make the signed sum of x divisible by m.
Level

Medium7 of 10

Topics
Math, Number theory, Bit manipulation
Solved
No attempts yet

Problem

The professor is preparing a task for higher math students. The students are given nn integers x1,x2,…,xnx_1, x_2, \ldots, x_n and an integer mm (1≤m<2n1 \le m < 2^n). The student must choose nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, each either −1-1, 00, or 11, with at least one non-zero value. The chosen integers must satisfy the condition that a1x1+a2x2+…+anxna_1x_1+a_2x_2+\ldots+a_nx_n is divisible by mm.

The professor has decided that the answer is a given array of integers a1,a2,…,ana_1, a_2, \ldots, a_n (−1≤ai≤1-1 \le a_i \le 1, at least one of them is not 00). To make checking students' solutions easier, he wants to choose integers x1,…,xnx_1, \ldots, x_n and an integer mm so that his array is the only possible solution. This is impossible, because the array −a1,…,−an-a_1, \ldots, -a_n is always a solution too.

So the professor relaxes his requirements and wants the only two solutions to be a1,…,ana_1, \ldots, a_n and −a1,…,−an-a_1, \ldots, -a_n. Help him choose integers x1,…,xnx_1, \ldots, x_n and an integer mm.

Input

The first line of input contains an integer nn (1≤n≤301 \leq n \leq 30). The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−1≤ai≤1-1 \leq a_i \leq 1). At least one of aia_i is not equal to 00.

Output

The first line of output must contain an integer mm (1≤m<2n1 \le m < 2^n). The next line must contain nn integers x1,x2,…,xnx_1, x_2, \ldots, x_n (−230<xi<230-2^{30} < x_i < 2^{30}). If there are several possible answers, output any of them. It is known that the answer always exists.

Hint

In the given example, the students must choose a1a_1 and a2a_2 so that a1+4a2a_1 + 4a_2 is divisible by 33. There are two possible solutions: a1=1a_1 = 1, a2=−1a_2 = -1 (a1+4a2=1−4=−3a_1 + 4a_2 = 1 - 4 = -3, divisible by 33) and a1=−1a_1 = -1, a2=1a_2 = 1 (a1+4a2=−1+4=3a_1 + 4a_2 = -1 + 4 = 3, divisible by 33). The professor's requirements are met.

Examples1

  1. Example 1

    Input
    2
    1 -1
    
    Expected output
    3
    1 4