Under construction

Still being built. Things may change

Chocolate Cake

Time limit1sMemory limit1024 MB

Summary
Given a cake of 2N pieces, add toppings of size M to pieces so that the largest taste gap between the two halves over all N cuts is as small as possible.
Level

Medium6 of 10

Topics
Array, Prefix sum, Math
Solved
No attempts yet

Problem

There is a round cake made of 2N2N fan-shaped pieces of the same size and area. The pieces are numbered 11 to 2N2N in clockwise order, and initially the taste of piece ii is AiA_i.

Chaewan and Heewon want to split the cake in half. To cut the cake, Chaewan picks one integer kk with 1≤k≤N1 \le k \le N, then divides the cake into the part containing pieces k,k+1,⋯ ,k+N−1k, k + 1, \cdots, k + N - 1 and the part containing the remaining pieces. The taste of each part is the sum of the tastes of the pieces it contains.

Chaewan wants to eat the tastier part, so he will choose, among the NN possible cuts, the one that maximizes the difference between the tastes of the two parts.

Heewon sees through this plan. He can place chocolate toppings on the pieces so that the difference between the two parts is as small as possible after Chaewan cuts the cake. Each topping placed on a piece raises that piece's taste by MM. A piece can get several toppings, and several pieces can get toppings at the same time. However, the maximum number of toppings on a single piece is 101210^{12}.

Find a way to place the toppings so that Heewon can split the cake as evenly as possible.

Input

The first line contains two integers NN and MM separated by a space. (1≤N≤100 000(1 \le N \le 100\ 000; 1≤M≤106)1 \le M \le 10^6)

The next line contains integers A1A_1, A2A_2, ⋯\cdots, A2N−1A_{2N-1}, A2NA_{2N} separated by spaces. (1≤Ai≤106)(1 \le A_i \le 10^6)

Output

On the first line, print the smallest possible difference in taste.

On the next line, print 2N2N integers C1C_1, C2C_2, ⋯\cdots, C2N−1C_{2N-1}, C2NC_{2N} separated by spaces. CiC_i is the number of chocolate toppings placed on piece ii, and it must satisfy 0≤Ci≤10120 \le C_i \le 10^{12}. The minimum difference can always be reached within these limits.

If several outputs reach the minimum, print any of them.

Examples1

  1. Example 1

    Input
    2 3
    1 2 3 4
    
    Expected output
    2
    1 1 0 0