685. Odd Even List

0

Easy

Om has a singly linked list where nodes with odd indices are grouped together, followed by nodes with even indices. Print the reordered list. The first node is considered odd, the second node is even, and so on. Note that the relative order within both the even and odd groups should remain the same as in the input. You must solve the problem using O(1) extra space complexity and O(n) time complexity.

Input Format

The first line contains the size of the linked list. The second line contains the elements of the linked list.

Output Format

Print the reordered linked list.

Example

Input

5 3 5 6 7 8

Output

3 6 8 5 7

Constraints

The linked list contains between 0 and 10^4 nodes. Each node's value is between -10^6 and 10^6.
Loading...

View Submissions

Console