PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000002. Dãy yêu thích (Favorite Sequence)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy yêu thích (Favorite Sequence)

Favorite Sequence

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Polycarp has a sequence of nn integers a1,a2,…,ana_1,a_2,\ldots,a_n. He writes it on a whiteboard in a special order. First, he places a1a_1 at the left end and a2a_2 at the right end. Next, he puts a3a_3 immediately to the right of a1a_1 and a4a_4 immediately to the left of a2a_2.

He continues in the same manner: elements with odd indices fill the whiteboard from the left towards the center, while elements with even indices fill it from the right towards the center. Once all elements have been written, the visible sequence, from left to right, is b1,b2,…,bnb_1,b_2,\ldots,b_n.

Given the visible sequence bb, reconstruct Polycarp's original sequence aa. Values are not necessarily distinct; the reconstructed order must follow the writing procedure exactly.

Input

  • The first line contains an integer nn, the sequence length.
  • The second line contains exactly nn integers b1,b2,…,bnb_1,b_2,\ldots,b_n, in their current left-to-right order on the whiteboard.

Output

Print one line containing exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, separated by spaces, in their original order.

Subtasks

  • Subtask 1 (20 points): 1≤n≤71\le n\le7; 1≤bi≤1091\le b_i\le10^9 for every 1≤i≤n1\le i\le n; equal values are allowed.
  • Subtask 2 (30 points): 1≤n≤401\le n\le40; 1≤bi≤1091\le b_i\le10^9 for every 1≤i≤n1\le i\le n; equal values are allowed.
  • Subtask 3 (50 points): 1≤n≤3001\le n\le300; 1≤bi≤1091\le b_i\le10^9 for every 1≤i≤n1\le i\le n; equal values are allowed.

Examples

Input

7
3 4 5 2 9 1 1

Output

3 1 4 1 5 9 2

Explanation

The leftmost 33 is a1a_1, and the rightmost 11 is a2a_2. Removing these two elements leaves [4,5,2,9,1][4,5,2,9,1], whose leftmost 44 is a3a_3 and rightmost 11 is a4a_4.

The remaining sequence is [5,2,9][5,2,9]: 55 becomes a5a_5 and 99 becomes a6a_6. The final remaining element 22 becomes a7a_7. Thus the original sequence is [3,1,4,1,5,9,2][3,1,4,1,5,9,2].