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



namespace ConsoleApplication3
{

    class linkedlist
    {
        public linkedlist previous;
        public linkedlist next;
        public int key;
    }

    class Program
    {


        static void Main(string[] args)
        {
            string temp;
            string[] data;
            int number;
            linkedlist first = null, last, holder = null; 
            temp = Console.ReadLine();
            number = int.Parse(temp);
            temp = Console.ReadLine();
            data = temp.Split(' ');
            first = new linkedlist();
            last = first;
            first.next = null;
            first.previous = null;
            first.key = int.Parse(data[1]);

            for (int i = 0; i < number-1; i++)
            {

                temp = Console.ReadLine();
                data = temp.Split(' ');
                switch(data[0])
                {
                    case "insert":
                        if (first == null)
                        {
                            first = new linkedlist();
                            last = first;
                            first.next = null;
                            first.key = int.Parse(data[1]);

                        }
                        else
                        {
                            holder = first;
                            first = new linkedlist();
                            first.previous = null;
                            first.key = int.Parse(data[1]);
                            first.next = holder;
                            holder.previous = first;
                        }

                        
                        break;
                    case "delete":
                        holder = first;
                        while (holder != null)
                        {
                            if (holder.key == int.Parse(data[1]))
                            {
                                if (holder.previous != null)
                                {
                                    holder.previous.next = holder.next;
                                }
                                else
                                {
                                    first = holder.next;
                                
                                
                                }

                                if (holder.next != null)
                                {
                                    holder.next.previous = holder.previous;
                                }
                                else
                                {
                                    last = holder.previous;
                                }
                                break;
                            }
                            else
                                holder = holder.next;
                        }

                        break;
                    case "deleteFirst":
                        if (first.next != null)
                        {
                            first = first.next;
                            first.previous = null;
                        }
                        else
                        {
                            first = null;
                            last = null;
                        }
                        break;
                    case "deleteLast":
                        last = last.previous;
                        if (last != null)
                        {
                            last.next = null;
                        }
                        else
                        {
                            first = null;
                            last = null;
                        }
                      
                        break;

                }
            }

            holder = first;
            while (holder != null)
            {
                if (holder.next != null)
                {
                    Console.Write("{0} ", holder.key);
                }
                else
                {
                    Console.Write("{0}", holder.key);
                }
                holder = holder.next;
            }

            Console.Write("\n");

 



        }
    }
}



Measured memory_bytes: 65440