cswork / OAOpen practice workspace

DuolingoOA #1

Construct New Array

Estimated EasyJudge-ready

Topics (AI-labelled)Two PointersIn-place Arrays

Build a new array by taking, in order, the leftmost element of the original array, then the rightmost, the second from the left, the second from the right, and so on.

Input

The first line contains n (1≤n≤100000), and the second line contains n integers (−10^9≤a[i]≤10^9).

Output

Output the n integers in construction order.

Example 1

Input:

5
0 4 3 2 1

Output:

0 1 4 2 3

Example 2

Input:

6
-5 4 0 3 2 2

Output:

-5 2 4 2 0 3

Example notes

Derive the linear scan/dynamic programming solution directly from the rules of the problem; the examples have been checked one by one against an independently built oracle.

Editorial

Loading solution…