Limits 1s, 512 MB

Bob was super excited about the big Cricket World Cup 2023 final. But his dad said, "No game if you don't finish homework first." Bob really wanted to watch the match, So he is planning to finish his homework as fast as possible. The statement of the homework is down below.

Bob has two arrays AA and BB. Initially array AA has NN numbers of elements and array BB is empty. He also has a function called SumOfArray()SumOfArray(). The function returns the sum of all elements of the array. He wants to move all elements from array AA to array BB. But the genaral transformation is a boring process. To make the process interesting he follows these step.

  • Calculate the sum of all elements of array AA. And checks whether the sum is even or odd.

  • If the sum is odd then he reverse the array AA otherwise the array AA remains same.

  • He appends the first element of array AA to array BB then erase the first element from array AA.

Bob has to move every element of array AA to array BB, by following the same rule.

Input

First line of the testcase contains one integer NN — represents the size of array AA.
Second line of the testcase contains NN integers A1,A2,,ANA_1, A_2, …, A_N — represents elements of array AA.

1N1051\leq N\leq 10^5

0Ai21090\leq A_i\leq 2*10^{9}

Output

You have to output two lines. First line of the output contain the sum of the array BB.

Second line of the output containNN integers. The elements of array BBseperated by space.

Sample

InputOutput
5
1 3 2 5 4
15
4 1 3 5 2 

Initially, A={1,3,2,5,4};B={}A = \{1, 3, 2, 5, 4\}; B = \{\},SumOfArray(A)=15,SumOfArray(A) = 15.

Sum is odd so we need to reverse the array making A={4,5,2,3,1}A = \{4, 5, 2, 3, 1\}.Now we need to appends the first element of array AA to array BB, then remove the first element from array AA.

So, these arrays will be A={5,2,3,1};A = \{5, 2, 3, 1\}; and B={4}B = \{4\}

Now,SumOfArray(A)SumOfArray(A) = 1111. Sum is odd so we need to reverse the array; A={1,3,2,5}A = \{1, 3, 2, 5\} So, A={3,2,5}A = \{3, 2, 5\}; B={4,1}B = \{4, 1\}

Now, SumOfArray(A)SumOfArray(A)== 1010. Sum is even so the array remain same; A={3,2,5}A = \{3, 2, 5\}
So, A={2,5}A =\{2, 5\} ;B={4,1,3}B = \{4, 1, 3\}

Now, SumOfArray(A)=7SumOfArray(A) = 7. Sum is odd so we need to reverse the array; A={5,2}A = \{5, 2\}
then, A={2}A = \{2\}; B={4,1,3,5}B = \{4, 1, 3, 5\}

Now, SumOfArray(A)=2SumOfArray(A) = 2. Sum is odd so we need to reverse the array. A={2}A = \{2\}
then, A={}A = \{\}; B={4,1,3,5,2}B = \{4, 1, 3, 5, 2\}


Submit

Login to submit.

Statistics

76% Solution Ratio
setulovelegendEarliest, 5M ago
sourov.cseFastest, 0.0s
akmshohan5123Lightest, 5.2 MB
Ahad_41Shortest, 606B
Toph uses cookies. By continuing you agree to our Cookie Policy.