// editor4

#include<stdio.h>
#include<stdlib.h>

typedef struct doubly
{
    int data;
    struct doubly *prev,*next;
}node;

node *head=NULL,*tail=NULL;

void create(int n)
{
    node *nd=(node*)malloc(sizeof(node*));
    nd->data=n;
    nd->next=nd->prev=NULL;
    if(head==NULL)
    {
        head=tail=nd;
    }
    else
    {
        tail->next=nd;
        nd->prev=tail;
        tail=nd;
    }
}

void print()
{
    node *temp=head;
    while(temp!=NULL)
    {
        printf("%d ",temp->data);
        temp=temp->next;
    }
}

void del()
{
    node*temp=head;
    while(temp!=NULL&&temp->next!=NULL)
    {
        node*temp2=temp->next;
        while(temp2!=NULL)
        {
            if(temp->data==temp2->data)
            {
                
                temp2->prev->next=temp2->next;
                 if(temp2->next!=NULL)
                    temp2->next->prev=temp;
                    free(temp2);
                    temp=temp->next;
            }
            else
            {
                temp=temp->next;
            }
        
    }
}

int main()
{
    int n,data;
    scanf("%d",&n);
    if(n<0)
    {
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&data);
        create(data);
    }
    print();
    del();
    printf("\n");
    print();
}