import java.util.*;
class DoublyLinkedlist
{
    static class Node
    {
        int data;
        Node prev,next;
        Node(int data)
        {
            this.data=data;
            this.prev=null;
            this.next=null;
        }
    }
    private Node head;
    private Node tail;
    
    public void insert(int value)
    {
        Node newNode=new Node(value);
        if(head==null)
        {
            head=newNode;
            tail=newNode;
        }
        else
        {
            tail.next=newNode;
            newNode.prev=tail;
            tail=newNode;
        }
    }
    void displayForward()
    {
        Node temp=head;
        while(temp!=null)
        {
            System.out.print(temp.data+" ");
            temp=temp.next;
        }
        System.out.println();
    }
    void displayReverse()
    {
        Node temp=tail;
    
        while(temp!=null)
        {
            System.out.print(temp.data+" ");
            temp=temp.prev;
        }
        System.out.println();
    }
}
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(value<-1000 || value>1000)
        {
            System.out.println("Invalid input");
            return;
        }
        DoublyLinkedlist obj=new DoublyLinkedlist();
        Stack<Integer> stack=new Stack<>();
        for(int i=0; i<n; i++)
        {
           stack.push(sc.nextInt());
        }
        while(!stack.isEmpty())
        {
            obj.insert(stack.pop());
        }
            
      
        obj.displayReverse();
        obj.displayForward();
    }
}
