Adjacency Love

 An array is called lovely if the sum of product of each adjacent pair of elements is odd.

More formally, the array

of size is lovely if the value

is odd.

You are given an array

consisting of positive integers. Find a permutation of array

which is lovely.

If multiple such permutations are possible, output any. If there is no lovely permutation, output -1.

Input Format

  • The first line contains an integer
denoting the number of test cases. The
  • test cases then follow.
  • The first line of each test case contains an integer
  • .
  • The second line of each test case contains
  • space-separated integers
    • .

    Output Format

    For each test case, if a lovely permutation of

    is possible, print a single line containing integers denoting the elements of any lovely permutation of

    . Otherwise, print -1.

    Constraints

    Subtasks

    • Subtask 1 (100 points): Original constraints.

    Sample Input 1

    2
    5
    1 2 3 4 10
    3
    7 11 145
    

    Sample Output 1

    3 1 10 2 4
    -1
    

    Explanation

    Test Case

    : The sum of products of adjacent pair of elements of the given array is . Since this value is even, this is not a lovely permutation of the array.
    A lovely permutation of the given array is . The sum of products for this array would be

    , which is odd.

    Test Case

    : No permutation of the given array exists where the sum of products of adjacent pair of elements is odd. Thus, answer is
    Previous
    Next Post »