using System;

namespace aoj
{
    class Program
    {
        public class MyDoubleLinkedList<T> where T : IComparable
        {
            public int Length { get; private set; }
            private Task<T> first = null;
            private Task<T> last = null;

            public MyDoubleLinkedList()
            {
                this.Length = 0;
                this.first = null;
                this.last = null;
            }

            public void Insert(T _value)
            {
                var task = new Task<T>();
                task.value = _value;

                if (0 < this.Length)
                {
                    task.Attach(this.first, null);
                    this.first = task;
                }
                else
                {
                    task.Attach(null, null);
                    this.first = task;
                    this.last = task;
                }

                ++this.Length;
            }

            public bool Delete(T _value)
            {
                if (this.Length <= 0) { return false; }

                var task = this.GetTask(_value);
                if (task == null) { return false; }

                if (task == this.first) { this.first = this.first.next; }
                if (task == this.last) { this.last = this.last.prev; }

                task.Detach();
                --this.Length;
                return true;
            }

            public bool DeleteFirst()
            {
                return this.Delete(this.first);
            }

            public bool DeleteLast()
            {
                return this.Delete(this.last);
            }
            
            public void Print()
            {
                var target = this.first;
                for (var i = 0; i < this.Length; ++i)
                {
                    Console.Write(target.value);
                    if (i != this.Length - 1) { Console.Write(" "); }

                    target = target.next;
                }
                Console.WriteLine();
            }

            private bool Delete(Task<T> _task)
            {
                if (this.Length <= 0) { return false; }

                if (_task == null) { return false; }

                if (_task == this.first) { this.first = this.first.next; }
                if (_task == this.last) { this.last = this.last.prev; }

                _task.Detach();
                --this.Length;
                return true;
            }

            private Task<T> GetTask(T _value)
            {
                var task = this.first;

                if (task == null || this.Length <= 0) { return null; }

                for (var i = 0; i < this.Length; ++i)
                {
                    if (task.value.Equals(_value)) { return task; }
                    task = task.next;
                }

                return null;
            }
        }

        public class Task<T> where T : IComparable
        {
            public T value = default(T);
            public Task<T> next = null;
            public Task<T> prev = null;

            public void Attach(Task<T> _next, Task<T> _prev)
            {
                this.next = _next;
                this.prev = _prev;

                if (_next != null) { _next.prev = this; }
                if (_prev != null) { _prev.next = this; }
            }

            public void Detach()
            {
                if (this.next != null) { this.next.prev = this.prev; }
                if (this.prev != null) { this.prev.next = this.next; }

                this.next = null;
                this.prev = null;
            }

            public static bool Equals<Type>(Type a, Type b) where Type : IComparable
            {
                return a.CompareTo(b) == 0;
            }
        }

        static void Main(string[] args)
        {
            MyDoubleLinkedList<int> list = new MyDoubleLinkedList<int>();

            var length = int.Parse(Console.ReadLine());
            for (var i = 0; i < length; ++i)
            {
                string[] input = Console.ReadLine().Split(' ');
                var command = input[0];

                switch (command)
                {
                    case "insert": list.Insert(int.Parse(input[1])); break;

                    case "delete": list.Delete(int.Parse(input[1])); break;

                    case "deleteFirst": list.DeleteFirst(); break;

                    case "deleteLast": list.DeleteLast(); break;

                    default: return;
                }
            }

            list.Print();
        }
    }
}



Measured memory_bytes: 63320