#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
struct node
{
	struct node *prev;
	struct node *next;
	int key;
};
struct node *head;//指向链表头部结点
struct node *tail;//指向链表尾部结点
void insertnode(int Key)//在链表头部添加结点,值为Key
{
	struct node *p,*q;
	p=(struct node *)malloc(sizeof(struct node));
	q=head;
	head=p;
	p->key=Key;
	p->prev=NULL;
	if(!q)
	{
		p->next=NULL;
		tail=p;
	}
	else
	{
		p->next=q;
		q->prev=p;
	}
	return;
}
void deletefirstnode()//删除链表头部的结点
{
	struct node *t;
	t=head;
	if(!head->next)
	{
		head=NULL;
		tail=NULL;
	}
	else
	{
		head->next->prev=NULL;
		head=head->next;
	}
	free(t);
	return;
}
void deletelastnode()//删除链表尾部的结点
{
	struct node *t;
	t=tail;
	if(!tail->prev)
	{
		head=NULL;
		tail=NULL;
	}
	else
	{
		tail->prev->next=NULL;
		tail=tail->prev;
	}
	free(t);
	return;
}
void deletenode(int Key)//删除第一个值为Key的结点
{
	struct node *t;
	t=head;
	while(t!=NULL)
	{
		if(t->key==Key)
		{
			if(!t->prev)
			{
				deletefirstnode();
				return;
			}
			if(!t->next)
			{
				deletelastnode();
				return;
			}
			t->prev->next=t->next;
			t->next->prev=t->prev;
			free(t);
			return;
		}
		t=t->next;
	}
	return;
}
void printlist()//输出并释放链表中的所有结点
{
	struct node *t;
	t=head;
	if(!t)
		return;
	while(1)
	{
		printf("%d",t->key);
		if(!t->next)
		{
			printf("\n");
			free(t);
			break;
		}
		else
		{
			printf(" ");
			t=t->next;
			free(t->prev);
		}
	}
	return;
}
int main()
{
	int n,valueofakey,i;//valueofakey是value of a key
	head=NULL;
	tail=NULL;
	char command[10];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s",command);
		if(strcmp(command,"deleteFirst")==0)
		{
			deletefirstnode();
			continue;
		}
		if(strcmp(command,"deleteLast")==0)
		{
			deletelastnode();
			continue;
		}
		scanf("%d",&valueofakey);
		if(strcmp(command,"insert")==0)
			insertnode(valueofakey);
		if(strcmp(command,"delete")==0)
			deletenode(valueofakey);
	}
	printlist();
	return 0;
}
