#include <iostream>
#include <string>
#include <cassert>

class list
{
private:
	struct TElement
	{
		int Value;
		TElement* PrevAd;
		TElement* NextAd;
	};
	TElement* FStartElement;
	TElement* FLastElement;
	void Delete(TElement* DeletePoint);
public:
	class iterator
	{
		friend class list;
	public:
		iterator(TElement* AElement);
		bool operator!=(const iterator& itr)const;
		void operator++(int);
		void operator--(int);
		int& operator*();
	private:
		TElement* FElement;
	};
	list();
	~list();
	void push_front(int Value);
	void pop_front();
	void pop_back();
	void erase(iterator itr);
	iterator begin();
	iterator end();
};

list::list()
{
	TElement* DummyPoint = new TElement;
	*DummyPoint = {0, NULL, NULL};
	FStartElement = DummyPoint;
	FLastElement  = DummyPoint;
}

list::~list()
{
	while(FStartElement){
		TElement* NextPoint = FStartElement->NextAd;
		delete FStartElement;
		FStartElement = NextPoint;
	}
}

void list::push_front(int Value)
{
	TElement* AddPoint = new TElement;
	*AddPoint = {Value, NULL, FStartElement};
	if(FStartElement == FLastElement){
		FStartElement = AddPoint;
		FLastElement  = FStartElement->NextAd;
		FLastElement->PrevAd = FStartElement;
	}else{
		FStartElement->PrevAd = AddPoint;
		FStartElement = AddPoint;
	}
}

void list::Delete(TElement* DeletePoint)
{
	DeletePoint->NextAd->PrevAd = DeletePoint->PrevAd;
    if(DeletePoint->PrevAd == NULL){
        FStartElement = DeletePoint->NextAd;//a
    }else{
	    DeletePoint->PrevAd->NextAd = DeletePoint->NextAd;//b
    }
	delete DeletePoint;
}

void list::pop_front()
{
	assert(FStartElement != FLastElement);
	Delete(FStartElement);
}

void list::pop_back()
{
	assert(FStartElement != FLastElement);
	Delete(FLastElement->PrevAd);
}

void list::erase(iterator itr)
{
	Delete(itr.FElement);
}

list::iterator list::begin()
{
	return iterator(FStartElement);
}

list::iterator list::end()
{
	return {FLastElement};
}

list::iterator::iterator(TElement* AElement)
{
	FElement = AElement;
}

bool list::iterator::operator!=(const iterator& itr)const
{
	return itr.FElement != FElement;
}

void list::iterator::operator++(int)
{
	FElement = FElement->NextAd;
}

void list::iterator::operator--(int)
{
	FElement = FElement->PrevAd;
}

int& list::iterator::operator*()
{
	return FElement->Value;
}

void Command(list &X, std::string &c)
{
    if(c == "insert"){
        int d;
        std::cin >> d;
        X.push_front(d);
    }else if(c == "delete"){
        int d;
        std::cin >> d;
        list::iterator itr = X.begin();
        while(*itr != d && itr != X.end()){
            itr++;
        }
        if(itr != X.end()){
            X.erase(itr);
        }
    }else if(c == "deleteFirst"){
        X.pop_front();
    }else if(c == "deleteLast"){
        X.pop_back();
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n;
    std::cin >> n;
    list X;
    for(int i = 0; i < n; i++){
        std::string c;
        std::cin >> c;
        Command(X, c);
    }
    list::iterator it  = X.begin();
    list::iterator end = X.end();
    end--;
    while(it != end){
        std::cout << *it << ' ';
        it++;
    }
    std::cout << *end << std::endl;
    return 0;
}

Measured memory_bytes: 34452