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 and . Initially array has numbers of elements and array is empty. He also has a function called . The function returns the sum of all elements of the array. He wants to move all elements from array to array . 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 . And checks whether the sum is even or odd.
If the sum is odd then he reverse the array otherwise the array remains same.
He appends the first element of array to array then erase the first element from array .
Bob has to move every element of array to array , by following the same rule.
First line of the testcase contains one integer — represents the size of array .
Second line of the testcase contains integers — represents elements of array .
You have to output two lines. First line of the output contain the sum of the array .
Second line of the output contain integers. The elements of array seperated by space.
Input | Output |
---|---|
5 1 3 2 5 4 | 15 4 1 3 5 2 |
Initially, . Sum is odd so we need to reverse the array making .Now we need to appends the first element of array to array , then remove the first element from array . So, these arrays will be and Now, = . Sum is odd so we need to reverse the array; So, ; Now, . Sum is even so the array remain same; Now, . Sum is odd so we need to reverse the array; Now, . Sum is odd so we need to reverse the array. |