using System;

namespace myApp
{
    class Program
    {
        public class Node {
            int key;
            Node prev;
            Node next;

            public int Key {
                get { return this.key; }
                set { this.key = value; }
            }
            public Node Previous
            {
                get { return this.prev; }
                internal set { this.prev = value; }
            }
            public Node Next 
            {
                get { return this.next; }
                internal set { this.next = value; }
            }
        }

        public class DoublyLinkedList {
            private Node    nil;

            public void Init() {
                nil = new Node();
                nil.Next = nil;
                nil.Previous = nil;
            }
            public DoublyLinkedList() {
                Init();
            }

            public void Insert(int key) {
                Node node = new Node();
                node.Key = key;
                // 番兵の直後に要素を追加
                node.Next = nil.Next;
                nil.Next.Previous = node;
                nil.Next = node;
                node.Previous = nil;
            }

            public Node ListSerch(int key) {
                Node cur = nil.Next;
                while (cur != nil && cur.Key != key) {
                    cur = cur.Next;
                }
                return cur;
            }

            public void DeleteNode(Node node) {
                if (node == nil) {
                    return;
                }
                node.Previous.Next = node.Next;
                node.Next.Previous = node.Previous;
            }
            public void DeleteFirst() {
                DeleteNode(nil.Next);
            }
            public void DeleteLast() {
                DeleteNode(nil.Previous);
            }
            public void DeleteKey(int key) {
                DeleteNode(ListSerch(key));
            }

            public void Print() {
                Node cur = nil.Next;
                bool notFirst = false;
                while (cur != nil) {
                    if (notFirst) {
                        Console.Write(" ");
                    }
                    notFirst = true;
                    Console.Write(cur.Key.ToString());
                    cur = cur.Next;
                }
                Console.WriteLine();
            }
        }

        static void Main(string[] args)
        {
            DoublyLinkedList doubly = new DoublyLinkedList();
            var n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++) {
                var line = Console.ReadLine().Split(' ');
                if (line[0] == "insert") {
                     doubly.Insert(int.Parse(line[1]));
                } else if (line[0] == "delete") {
                    doubly.DeleteKey(int.Parse(line[1]));
                } else if (line[0] == "deleteFirst") {
                    doubly.DeleteFirst();
                } else if (line[0] == "deleteLast") {
                    doubly.DeleteLast();
                }
            }

            doubly.Print();
        }
    }
}



Measured memory_bytes: 67328