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 $A$ and $B$. Initially array $A$ has $N$ numbers of elements and array $B$ is empty. He also has a function called $SumOfArray()$. The function returns the sum of all elements of the array. He wants to move all elements from array $A$ to array $B$. 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 $A$. And checks whether the sum is even or odd.

If the sum is odd then he reverse the array $A$ otherwise the array $A$ remains same.

He appends the first element of array $A$ to array $B$ then erase the first element from array $A$.

Bob has to move every element of array $A$ to array $B$, by following the same rule.

First line of the testcase contains one integer $N$ — represents the size of array $A$.

Second line of the testcase contains $N$ integers $A_1, A_2, …, A_N$ — represents elements of array $A$.

$1\leq N\leq 10^5$

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

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

Second line of the output contain$N$ integers. The elements of array $B$seperated by space.

Input | Output |
---|---|

5 1 3 2 5 4 | 15 4 1 3 5 2 |

Initially, $A = \{1, 3, 2, 5, 4\}; B = \{\}$$,SumOfArray(A) = 15$. Sum is odd so we need to reverse the array making $A = \{4, 5, 2, 3, 1\}$.Now we need to appends the first element of array $A$ to array $B$, then remove the first element from array $A$. So, these arrays will be $A = \{5, 2, 3, 1\};$ and $B = \{4\}$ Now,$SumOfArray(A)$ = $11$. Sum is odd so we need to reverse the array; $A = \{1, 3, 2, 5\}$ So, $A = \{3, 2, 5\}$; $B = \{4, 1\}$ Now, $SumOfArray(A)$$=$ $10$. Sum is even so the array remain same; $A = \{3, 2, 5\}$ Now, $SumOfArray(A) = 7$. Sum is odd so we need to reverse the array; $A = \{5, 2\}$ Now, $SumOfArray(A) = 2$. Sum is odd so we need to reverse the array. $A = \{2\}$ |

Login to submit.

70%
Solution Ratio

setulovelegendEarliest,

sourov.cseFastest, 0.0s

akmshohan5123Lightest, 5.2 MB

Ahad_41Shortest, 606B

Toph uses cookies. By continuing you agree to our Cookie Policy.