400469: GYM100187 I Derivative of Array
Description
Let us define the derivatives of array in the following way:
- Zeroth derivative of array a1, ..., an is defined as this array a1, ..., an itself.
- First derivative of array a1, ..., an, where n > 1, is defined as such an array a'1, ..., a'n - 1, that for all i = 1, ..., n - 1 the equality a'i = ai + 1 - ai is satisfied.
- k-th derivative of array a1, ..., an, where 1 < k < n, is defined as (k - 1)-th derivative of array a'1, ..., a'n - 1.
You are given n numbers b0, ..., bn - 1, each equals either to zero or to one. You are to build an array of length n so that its k-th derivative is strictly increasing if bk = 1 and strictly decreasing if bk = 0. Each element of array should be an integer from - 109 to 109, inclusively. If it is impossible, output «IMPOSSIBLE».
InputThe first line contains the only integer n (1 ≤ n ≤ 2000) — the length of the array you are to build.
The second line contains n integers b0, ..., bn - 1 (0 ≤ bi ≤ 1) separated by spaces. If bk = 1, k-th derivative of array should be strictly increasing, and if bk = 0 — strictly decreasing.
OutputOutput n integers a1, ..., an — the array which derivatives satisfy all the conditions specified by numbers b0, ..., bn - 1. The elements of the array should not exceed 109 by absolute value.
If there are several such arrays, you can output any of them.
If there is no such array or some of its elements are greater than 109 by absolute value, output «IMPOSSIBLE».
ExamplesInput3Output
1 1 1
1 2 5Input
3Output
0 0 1
-1 -2 -5