#include <stdio.h>
#include <stdlib.h>
typedef struct node{
    int data;
    struct node *prev;
    struct node *next;
}nd;
nd *head=NULL,*tail,*newnode,*temp,*curr,*next;
void create(int val){
    newnode=(nd*)malloc(sizeof(nd));
    newnode->data=val;
    newnode->prev=NULL;
    newnode->next=NULL;
    if(head==NULL){
        head=newnode;
        tail=newnode;
    }
    tail->next=newnode;
    newnode->prev=tail;
    tail=newnode;
}
void rmdup(){
    if(head==NULL) return;
    curr=head;
    while(curr!=NULL){
        run=temp->next;
        while(run!=NULL){
            next=curr->next;
            if(curr->data==run->data){
                nd *dup=run;
                run=run->next;
                if(dup->prev!=NULL){
                    dup->prev->next=dup->next;
                }
                if(dup->next!=NULL){
                    dup->next->prev=dup->prev;
                }
                if(dup=tail){
                    tail=dup->prev;
                }
                free(dup);
            }
            run->run->bextl'
        }
        curr=curr->next;
    }
}
void display(){
    temp=head;
    while(temp!=NULL){
        printf("%d ",temp->data);
        temp=temp->next;
    }
    printf("\n");
}
int main(){
    int n,x;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        create(x);
    } 
    display();
    rmdup();
    display();
}