#K63307. Modify Array to Satisfy Consecutive Sum Divisibility

    ID: 31724 Type: Default 1000ms 256MiB

Modify Array to Satisfy Consecutive Sum Divisibility

Modify Array to Satisfy Consecutive Sum Divisibility

You are given an array of n integers and a positive integer x. Your task is to modify the array to produce a new array b such that for every consecutive pair of elements, the following condition holds:

[ b_i + b_{i+1} \equiv 0 \pmod{x} ]

In other words, for every i (1 ≤ i < n), the sum b[i-1] + b[i] is divisible by x. Moreover, each element b[i] should be chosen as close as possible to the original a[i]. It is guaranteed that at least one valid solution exists.

inputFormat

The input is given via standard input (stdin). The first line contains two integers n and x. The second line contains n integers representing the array a.

outputFormat

Output the modified array b in a single line in which the elements are separated by a space. The resulting array must satisfy the property that for every consecutive pair, (b_i + b_{i+1} \equiv 0 \pmod{x}).## sample

5 3
5 4 3 2 1
5 4 2 1 2