eolymp
bolt
Try our new interface for solving problems
Problems

Reorder List

Reorder List

Time limit 1 second
Memory limit 64 MiB

Given an array of integers. Create a Linked List from these numbers.

Write a method ReorderList that reorders a list L[0]L[1]L[2] → ... → L[n-1]L[n] into L[0]L[n]L[1]L[n-1]L[2]L[n-2] → ... .

Write the code according to the next interface:

class Node

{

public:

int data;

Node *next;

Node() : next(NULL) {};

Node(int data, Node *next = NULL) : data(data), next(next) {};

};

class List

{

public:

Node *head, *tail;

List() : head(NULL), tail(NULL) {};

void AddToTail(int val); // Add number val to the end of the Linked List

void ReorderList(void) // Reorder a list as given above

void Print(void); // Print the elements of Linked List

};

You can create (use) additional methods if needed.

Input data

The first line contains number n (1n10000). The second line contains n integers.

Output data

Print the elements of reordered Linked List using Print method.

Examples

Input example #1
5
1 2 3 4 5
Output example #1
1 5 2 4 3
Author Mykhailo Medvediev
Source C++ Language