SDE Path

Introduction to Doubly Linked List

Easy

Introduction to Doubly Linked List

Implement a doubly linked list supporting insertion and deletion from both ends.

Input format

The first line contains N. The second line contains the N node values in order.

Output format

Build a doubly linked list from the values. Print two lines: the list traversed forward, then traversed backward.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
4
1 2 3 4
Expected output
1 2 3 4
4 3 2 1
Example 2
Input
1
7
Expected output
7
7