#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

struct node{
	long key;
	node *prev;
	node *next;
};

class myList{
private:
	node *head;
	node *tail;
	bool isTail(node *target);
	bool isHead(node *target);
public:
	myList();
	myList(long key);
	void printList();
	bool isEmpty();
	void deleteLast();
	void deleteFirst();
	void insert(long key);
	void deleteX(long key);
};

bool myList::isTail(node *target){
	if(tail == target) return true;
	return false;
}

bool myList::isHead(node *target){
	if(head == target) return true;
	return false;
}
myList::myList(){
	head = NULL;
	tail = NULL;
}
myList::myList(long key){
	node *newNode = new node;
	newNode->key = key;
	newNode->next = NULL;
	newNode->prev = NULL;
	head = newNode;
	tail = newNode;
}

void myList::insert(long key){
	node *newNode = new node;
	newNode->key = key;
	if(isEmpty() == true){		//list に何もない場合
		newNode->next = NULL;
		newNode->prev = NULL;
		head = newNode;
		tail = newNode;
	}else{			//list が空ではない場合
		node *nextNode = head;
		nextNode->prev = newNode;
		newNode->next = head;
		newNode->prev = NULL;
		head = newNode;
	}
}

void myList::deleteFirst(){
	node *targetNode = head;
	node *nextNode = head->next;
	if(nextNode == NULL){			//最後の一個だったばあい
		delete targetNode;
		head = NULL;
	}else{
		nextNode->prev = NULL;
		head = nextNode;
		delete targetNode;
	}
}

void myList::printList(){
	node *node;
	node = head;
	cout<<node->key;
	node = node->next;
	while(node != NULL){
		cout <<" "<<node->key;
		node = node->next;
	}
	cout << endl;
}

bool myList::isEmpty(){
	if(head == NULL) return true;
	return false;
}

void myList::deleteLast(){
	node *targetNode = tail;
	node *prevNode = targetNode->prev;
	if( prevNode == NULL){		//最後の一個
		delete targetNode;
		head = NULL;
		tail = NULL;
	}else{						//最後の一個ではない場合
		prevNode->next = NULL;
		tail = prevNode;
		delete targetNode;
	}
}

void myList::deleteX(long key){
	node *target = head;
	while( target != NULL){
		if(target->key == key){		//削除対象を見つけた場合
			if(isTail(target)){
				deleteLast();
			}else if(isHead(target)){
				deleteFirst();
			}else{
				node *prevNode = target->prev;
				node *nextNode = target->next;
				prevNode->next = nextNode;
				nextNode->prev = prevNode;
				delete target;
			}
			break;
		}
		target = target->next;
	}
}

int commandSplitIndex(string str){
	for(int i= 0; i < str.size(); i++){
		if(str[i] == ' '){
			return i;
		}
	}
	return -1;
}


int main()
{
	int n;
	cin>>n;
	string str;
	getline(cin,str);			//空白行をいったん受け取る
	myList myL = myList();
	for(int i = 0; i < n; i++){
		getline(cin,str);
		int index = commandSplitIndex(str);
		/*cout << "command split index is" << index << endl;
		cout << str.substr(0,index) << endl;
		cout << str.substr(index+1) << endl;*/
		if(index == -1){
			if(str == "deleteLast"){
				myL.deleteLast();
			}else if(str == "deleteFirst"){
				myL.deleteFirst();
			}
		}else{
			if(str.substr(0,index) == "delete"){
				myL.deleteX(stol(str.substr(index+1)));
			}else if(str.substr(0,index) == "insert"){
				myL.insert(stol(str.substr(index+1)));
			}
		}
	}
	myL.printList();
	return 0;
}





Measured memory_bytes: 34424