**Divide Candies SOLUTION**

**Divide Candies SOLUTION**

There are N piles of confections (numbered 1 through N); for each legitimate I, the I-th of them contains precisely iK confections. You plan to parcel these loads among you and your companion so that each store is given to precisely one of you without being part among you.

The conveyance ought to be as reasonable as could be expected under the circumstances. Officially, how about we signify the all out number of confections you get by An and the all out number of confections your companion gets by B; you will probably limit |A−B|.

Locate the littlest conceivable estimation of |A−B| and dole out the piles to you and your companion somehow or another that limits |A−B|. On the off chance that there are different arrangements, you may locate any of them.

Information

The primary line of the information contains a solitary number K, which is basic for all experiments.

The subsequent line contains a solitary number T signifying the quantity of experiments. The depiction of T experiments follows.

The solitary line of each experiment contains a solitary number N.

Yield

For each experiment, print two lines.

The first of these lines ought to contain a solitary number ― the littlest estimation of |A−B| we can acquire.

The subsequent line ought to contain N characters depicting your task of stacks. For each legitimate I, the I-th of them ought to be ‘1’ in the event that you need to give the I-th load to you or ‘0’ in the event that you need to offer it to your companion.

Requirements

1≤T≤2,000

1≤K≤4

1≤N≤106

the whole of N over all experiments doesn’t surpass 5⋅106

Subtasks

Subtask #1 (5 focuses): K=1

Subtask #2 (10 focuses): K=2

Subtask #3 (15 focuses): K=3

Subtask #4 (70 focuses): K=4

Model Input 1

2

2

4

5

Model Output 1

2

0001

3

01001

Clarification

Model case 1: There are four piles with sizes 1, 4, 9 and 16 and two ideal tasks: either give the last pile to yourself and the rest to your companion or the other way around (so both “0001” and “1110” would be viewed as right yields). In the two cases, |A−B|=|16−(1+4+9)|=2.

Model case 2: There are five piles with sizes 1, 4, 9, 16 and 25. You can dole out the second and fifth stack to yourself, and in this manner |A−B|=|(25+4)−(16+9+1)|=3. It very well may be demonstrated this is the littlest conceivable estimation of |A−B|.

Model Input 2

4

3

5

6

9

Model Output 2

271

00001

317

000001

253

000001110

Clarification

Model case 3: We have K=4 and N=9. The littlest estimation of |A−B| is |(64+74+84)−(14+24+34+44+54+94)|=|7793−7540|=253.

Madarchodon ki team

Approval ki kya zaroorat tu padh raha hai na loda duga tere muh me

bro code leke kya karoge be cheating kar ke tum log pura contest ko bar baad kar diyo ho atleast yah log code toh nahi de rahe hai na kam se kam logic toh explain kar hi rahe h yah log jo yah cheating se jada bahtar h

Hey do not share the code but please share the logic as you have did for other questions looking forward to it.

please share the logic video for this question too it will be very helpful

bhai log koi help kardo yaar logic hai kya kisi ke paas

bhai please explain me the logic bhai

yaar sahi mai koi logic explain kardo yaar, tum hare paas hai koi approach please message karna yaar

are access de bhai