using System;

class Node
{
    int key;
    Node prev;
    Node next;


    public Node(int k, Node p, Node n) {
        this.key = k;
        this.prev = p;
        this.next = n;
    }

    public int keyop
    {
        get {
            return this.key;
        }
        set {
            this.key = value;
        }
    }

    public Node previous
    {
        get {
            return prev;
        }
        set {
            this.prev = value;
        }
    }

    public Node Next
    {
        get {
            return next;
        }
        set {
            this.next = value;
        }
    }
}

class ListOp{
    Node nil;

    public ListOp() {
        this.nil = new Node(0, null, null);
        this.nil.Next = this.nil;
        this.nil.previous = this.nil;
    }
    public Node FirstNode
    {
        get {
            return this.nil.Next;
        }
    }
    public Node LastNode
    {
        get {
            return this.nil.previous;
        }
    }
    public Node EndNode
    {
        get {
            return this.nil;
        }
    }
    public void Insert(int data) {
        Node newnode = new Node(data, null, this.nil.Next);
        this.nil.Next.previous=newnode;
        this.nil.Next = newnode;
        newnode.previous = nil;
    }
    public void Delete(Node del) {
        if (del == nil) {
            return;
        }
        del.previous.Next = del.Next;
        del.Next.previous = del.previous;
    }
    public Node Search(int key) {
        for(Node n = this.FirstNode; n != this.EndNode; n = n.Next) {
            if (n.keyop == key) {
                return n;
            }
        }
        return null;
    }
    public void DeleteFirst() {
        this.Delete(this.FirstNode);
    }
    public void DeleteLast() {
        this.Delete(this.LastNode);
    }
}

class C
{
    public static void Main() {
        int n = int.Parse(Console.ReadLine());
        ListOp list = new ListOp();
        for(int i = 0; i < n; i++) {
            string[] command = Console.ReadLine().Split(' ');
            switch (command[0]) {
                case "insert": {
                        list.Insert(int.Parse(command[1]));
                        break;
                    }
                case "delete": {
                        Node node = new Node(0, null,null);
                        node = list.Search(int.Parse(command[1]));
                        if (node!=null){
                            list.Delete(node);
                        }
                        break;
                    }
                case "deleteFirst": {
                        list.DeleteFirst();
                        break;
                    }
                case "deleteLast": {
                        list.DeleteLast();
                        break;
                    }
                default: {
                        break;
                    }
            }
        }
        for(Node node = list.FirstNode; node != list.EndNode; node = node.Next) {
            if (node != list.FirstNode) {
                Console.Write(' ');
            }
            Console.Write(node.keyop);
        }
        Console.WriteLine();
    }
}


Measured memory_bytes: 69868