
#include <stdio.h>
#include <stdlib.h>

typedef struct _node{
	struct _node *prev;
	struct _node *next;

	int val;

}Node;


void insert(Node **node, int val ){

	Node *ptr;


	ptr = (Node*)malloc(sizeof(Node));
	ptr->val = val;

	ptr->prev = NULL;
	ptr->next = *node;

	if( *node != NULL ) (*node)->prev = ptr;

	*node = ptr;
	
}

void delete_first( Node **node ){
	
	Node *ptr = *node;

	if( ptr->next != NULL ){
		ptr->next->prev = NULL;
		*node = ptr->next;
	}else{
		*node = NULL;
	}

	free(ptr);
}


void delete_last( Node **node ){

	Node *ptr = *node;
	
	while( ptr->next != NULL ) ptr = ptr->next;

	if( ptr->prev != NULL ){
		ptr->prev->next = NULL;
	}else{
		*node = NULL;
	}
	free( ptr );
}

void delete(Node **node, int val ){

	Node *ptr = *node;
	if(*node == NULL) return;

	//Seek for matching node
	while( ptr->next!=NULL && ptr->val!=val  )
		ptr = ptr->next;

	// delete
	if( ptr->val == val ){

		if( ptr->next == NULL ){
			delete_last(node);
		}else if( ptr->prev == NULL ){
			delete_first(node);
		}else{
			ptr->prev->next = ptr->next;
			ptr->next->prev = ptr->prev;
			free(ptr);
		}
	}

	//if node is front/last change ptr
		

}





void print( Node * node ){
		
	if(node==NULL) return;
	
	do{
		//printf( "%p:%d:%p%c", node->prev, node->val, node->next, (node->next!=NULL)?' ':'\n' );
		printf( "%d%c", node->val, (node->next!=NULL)?' ':'\n' );
		node  = node->next;
	}while( node != NULL  );
}

int main( ){

	int i, n, val;
	char cmd[33];
	Node *node = NULL;
	

	scanf( "%d\n", &n );
	
	for( i=0; i<n; i++ ){
		fgets( cmd, sizeof(cmd), stdin );

		if( strncmp(cmd,"deleteFirst",11) == 0 ){
			delete_first( &node );
		}
		else if( strncmp(cmd,"deleteLast",10) == 0 ){
			delete_last( &node );
		}
		else if( strncmp(cmd,"delete",6) == 0 ){
			val = atoi( &cmd[7] );
			delete( &node, val );
		}
		if( strncmp(cmd,"insert",6) == 0 ){
			val = atoi( &cmd[7] );
			insert( &node, val );
		}
		//print(node);
	}

	print(node);
	
	return 0;
}