using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_3_C
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力
            int inputCount = int.Parse(Console.ReadLine().Trim());

            var linkedList = new LinkedList<string>();
            for (int lp = 0; lp < inputCount; lp++)
            {
                var line = Console.ReadLine().Trim().Split(" ".ToCharArray());
                switch (line[0])
                {
                    case "insert":
                        // 連結リストの先頭にキー x を持つ要素を継ぎ足す。
                        linkedList.InsertFirst(line[1]);
                        break;
                    case "delete":
                        // キー x を持つ最初の要素を連結リストから削除する。そのような要素が存在しない場合は何もしない。
                        for (var n = linkedList.First; n != linkedList.End; n = n.Next)
                        {
                            if (n.Value == line[1])
                            {
                                linkedList.Erase(n);
                                break;
                            }
                        }
                        break;
                    case "deleteFirst":
                        // リストの先頭の要素を削除する。
                        linkedList.EraseFirst();
                        break;
                    case "deleteLast":
                        // リストの末尾の要素を削除する。
                        linkedList.EraseLast();
                        break;
                    default:
                        break;
                }

            }

            var st = new StringBuilder();
            for (var n = linkedList.First; n != linkedList.End; n = n.Next)
            {
                if (st.Length != 0) st.Append(" ");
                st.Append(n.Value);
            }
            Console.WriteLine(st.ToString());
        }
    }

    public class LinkedList<T> : IEnumerable<T>
    {
        public class Node
        {
            T val;
            Node prev;
            Node next;

            internal Node(T val, Node prev, Node next)
            {
                this.val = val;
                this.prev = prev;
                this.next = next;
            }

            public T Value
            {
                get { return this.val; }
                set { this.val = value; }
            }

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

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

        }

        readonly Node dummy;

        public LinkedList()
        {
            this.dummy = new Node(default(T), null, null);
            this.dummy.Next = this.dummy;
            this.dummy.Previous = this.dummy;
        }

        public Node First
        {
            get { return this.dummy.Next; }
        }

        public Node Last
        {
            get { return this.dummy.Previous; }
        }

        public Node End
        {
            get { return this.dummy; }
        }

        public int Count
        {
            get
            {
                int i = 0;
                for (Node n = this.First; n != this.End; n = n.Next)
                    ++i;
                return i;
            }
        }

        public Node InsertAfter(Node n, T elem)
        {
            Node m = new Node(elem, n, n.Next);
            n.Next.Previous = m;
            n.Next = m;
            return m;
        }
        public Node InsertBefore(Node n, T elem)
        {
            Node m = new Node(elem, n.Previous, n);
            n.Previous.Next = m;
            n.Previous = m;
            return m;
        }

        public Node InsertFirst(T elem)
        {
            return this.InsertAfter(this.dummy, elem);
        }

        public Node InsertLast(T elem)
        {
            return this.InsertBefore(this.dummy, elem);
        }

        public Node Erase(Node n)
        {
            if (n == this.dummy)
            {
                return this.dummy;
            }
            n.Previous.Next = n.Next;
            n.Next.Previous = n.Previous;
            return n.Next;
        }

        public void EraseFirst()
        {
            this.Erase(this.First);
        }

        public void EraseLast()
        {
            this.Erase(this.Last);
        }

        public IEnumerator<T> GetEnumerator()
        {
            for (Node n = this.First; n != this.End; n = n.Next)
                yield return n.Value;
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}



Measured memory_bytes: 114564