# Original solution
class DLL:
    class Node:
        def __init__(self, x, y, z):
            self.v = x
            self.prv = y
            self.nxt = z

    def __init__(self):
        init = DLL.Node(None, None, None)
        init.prv = init
        init.nxt = init
        self.size = 0
        self.init = init

    def insert(self, x):
        i = self.init
        j = i.nxt
        k = DLL.Node(x, i, j)
        i.nxt = k
        j.prv = k
        self.size += 1

    def deleteFirst(self):
        if self.size != 0:
            i = self.init
            k = i.nxt
            j = k.nxt
            i.nxt = j
            j.prv = i
            self.size -= 1

    def deleteLast(self):
        if self.size != 0:
            i = self.init
            k = i.prv
            j = k.prv
            i.prv = j
            j.nxt = i
            self.size -= 1

    def delete(self, x):
        if self.size != 0:
            i = self.init
            k = i.nxt
            while 1:
                if k.v == x:
                    i = k.prv
                    j = k.nxt
                    i.nxt = j
                    j.prv = i
                    self.size -= 1
                    break
                else:
                    k = k.nxt

    def prt(self):
        f = self.init
        s = f.nxt
        l = f.prv
        while 1:
            if s != l:
                print(s.v, end=' ')
                s = s.nxt
            else:
                print(l.v)
                break

n = int(input())
L = DLL()

for i in range(n):
    com = input()
    if com == "deleteFirst":
        L.deleteFirst()
    elif com == "deleteLast":
        L.deleteLast()
    else:
        C = com.split()
        if C[0] == "insert":
            L.insert(int(C[1]))
        elif C[0] == "delete":
            L.delete(int(C[1]))
    #L.prt()
    
L.prt()



# Optimized solution
#16D8104025G 佐藤智裕 mist75__ Python3

class DLL:
    class Node:
        def __init__(self, x, y, z):
            self.v = x
            self.prv = y
            self.nxt = z

    def __init__(self):
        init = DLL.Node(None, None, None)
        init.prv = init
        init.nxt = init
        self.size = 0
        self.init = init

    def insert(self, x):
        i = self.init
        j = i.nxt
        k = DLL.Node(x, i, j)
        i.nxt = k
        j.prv = k
        self.size += 1

    def deleteFirst(self):
        if self.size != 0:
            i = self.init
            k = i.nxt
            j = k.nxt
            i.nxt = j
            j.prv = i
            self.size -= 1

    def deleteLast(self):
        if self.size != 0:
            i = self.init
            k = i.prv
            j = k.prv
            i.prv = j
            j.nxt = i
            self.size -= 1

    def delete(self, x):
        if self.size != 0:
            i = self.init
            k = i.nxt
            while 1:
                if k.v == x:
                    i = k.prv
                    j = k.nxt
                    i.nxt = j
                    j.prv = i
                    self.size -= 1
                    break
                else:
                    if k.nxt == i:
                        break
                    else:
                        k = k.nxt

    def prt(self):
        f = self.init
        s = f.nxt
        l = f.prv
        while 1:
            if s != l:
                print(s.v, end=' ')
                s = s.nxt
            else:
                print(l.v)
                break

n = int(input())
L = DLL()

for i in range(n):
    com = input()
    if com == "deleteFirst":
        L.deleteFirst()
    elif com == "deleteLast":
        L.deleteLast()
    else:
        C = com.split()
        if C[0] == "insert":
            L.insert(int(C[1]))
        elif C[0] == "delete":
            L.delete(int(C[1]))
    #L.prt()
    
L.prt()