import sys
input = sys.stdin.readline


class Node:
    def __init__(self, val):
        self.val = val
        self.prev, self.next = None, None


class DoublyLinkedList:
    def __init__(self):
        self.n = 0
        self.dummy = Node(None)
        self.dummy.prev = self.dummy
        self.dummy.next = self.dummy

    def __getitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val 

    def __setitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val

    def __len__(self):
        return self.n

    def __bool__(self):
        return self.n != 0

    def __iter__(self):
        self.p = self.dummy
        return self

    def __next__(self):
        self.p = self.p.next
        if self.p == self.dummy:
            raise StopIteration
        return self.p.val

    def append(self, val):
        ptr = self.dummy.prev
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def appendleft(self, val):
        ptr = self.dummy.next
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def pop(self):
        ptr = self.dummy.prev
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def popleft(self):
        ptr = self.dummy.next
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def _get_node(self, i):
        if i < self.n // 2:
            ptr = self.dummy.next
            for _ in range(i):
                ptr = ptr.next
        else:
            ptr = self.dummy
            for _ in range(i, self.n):
                ptr = ptr.prev
        return ptr

    def _remove(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        ptr = self._get_node(i)
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1
        return ptr.val

    def _add(self, i, val):
        if i < 0 or i > self.n:
            raise IndexError()
        ptr = self._get_node(i)
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def delete(self, val):
        ptr = self.dummy
        for _ in range(self.n):
            ptr = ptr.next
            if ptr.val == val:
                ptr.prev.next = ptr.next
                ptr.next.prev = ptr.prev
                self.n -= 1
                return True
        return False


dls = DoublyLinkedList()
input()
for query in sys.stdin:
    if query[0] == "i":
        val = query[7:-1]
        dls.appendleft(val)
    elif query[6] == "F":
        dls.popleft()
    elif query[6] == "L":
        dls.pop()
    else:
        val = query[7:-1]
        dls.delete(val)

print(*list(dls)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class Node:
    def __init__(self, val):
        self.val = val
        self.prev, self.next = None, None Node def __init__(self, val):
        self.val = val
        self.prev, self.next = None, None __init__ self.val = val self.val self val val self.prev, self.next = None, None self.prev self prev None self.next self next None self self val val class DoublyLinkedList:
    def __init__(self):
        self.n = 0
        self.dummy = Node(None)
        self.dummy.prev = self.dummy
        self.dummy.next = self.dummy

    def __getitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val 

    def __setitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val

    def __len__(self):
        return self.n

    def __bool__(self):
        return self.n != 0

    def __iter__(self):
        self.p = self.dummy
        return self

    def __next__(self):
        self.p = self.p.next
        if self.p == self.dummy:
            raise StopIteration
        return self.p.val

    def append(self, val):
        ptr = self.dummy.prev
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def appendleft(self, val):
        ptr = self.dummy.next
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def pop(self):
        ptr = self.dummy.prev
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def popleft(self):
        ptr = self.dummy.next
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def _get_node(self, i):
        if i < self.n // 2:
            ptr = self.dummy.next
            for _ in range(i):
                ptr = ptr.next
        else:
            ptr = self.dummy
            for _ in range(i, self.n):
                ptr = ptr.prev
        return ptr

    def _remove(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        ptr = self._get_node(i)
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1
        return ptr.val

    def _add(self, i, val):
        if i < 0 or i > self.n:
            raise IndexError()
        ptr = self._get_node(i)
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def delete(self, val):
        ptr = self.dummy
        for _ in range(self.n):
            ptr = ptr.next
            if ptr.val == val:
                ptr.prev.next = ptr.next
                ptr.next.prev = ptr.prev
                self.n -= 1
                return True
        return False DoublyLinkedList def __init__(self):
        self.n = 0
        self.dummy = Node(None)
        self.dummy.prev = self.dummy
        self.dummy.next = self.dummy

     __init__ self.n = 0 self.n self n 0 self.dummy = Node(None) self.dummy self dummy Node(None) Node None self.dummy.prev = self.dummy self.dummy.prev self.dummy self dummy prev self.dummy self dummy self.dummy.next = self.dummy self.dummy.next self.dummy self dummy next self.dummy self dummy self self def __getitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val 

     __getitem__ if i < 0 or i >= self.n:
            raise IndexError()
         i < 0 or i >= self.n i < 0 i 0 i >= self.n i self.n self n raise IndexError() IndexError() IndexError return self._get_node(i).val self._get_node(i).val self._get_node(i) self._get_node self _get_node i val self self i i def __setitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val

     __setitem__ if i < 0 or i >= self.n:
            raise IndexError()
         i < 0 or i >= self.n i < 0 i 0 i >= self.n i self.n self n raise IndexError() IndexError() IndexError return self._get_node(i).val self._get_node(i).val self._get_node(i) self._get_node self _get_node i val self self i i def __len__(self):
        return self.n

     __len__ return self.n self.n self n self self def __bool__(self):
        return self.n != 0

     __bool__ return self.n != 0 self.n != 0 self.n self n 0 self self def __iter__(self):
        self.p = self.dummy
        return self

     __iter__ self.p = self.dummy self.p self p self.dummy self dummy return self self self self def __next__(self):
        self.p = self.p.next
        if self.p == self.dummy:
            raise StopIteration
        return self.p.val

     __next__ self.p = self.p.next self.p self p self.p.next self.p self p next if self.p == self.dummy:
            raise StopIteration
         self.p == self.dummy self.p self p self.dummy self dummy raise StopIteration StopIteration return self.p.val self.p.val self.p self p val self self def append(self, val):
        ptr = self.dummy.prev
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

     append ptr = self.dummy.prev ptr self.dummy.prev self.dummy self dummy prev new_ptr = Node(val) new_ptr Node(val) Node val new_ptr.prev = ptr.prev new_ptr.prev new_ptr prev ptr.prev ptr prev new_ptr.next = ptr new_ptr.next new_ptr next ptr new_ptr.next.prev = new_ptr new_ptr.next.prev new_ptr.next new_ptr next prev new_ptr new_ptr.prev.next = new_ptr new_ptr.prev.next new_ptr.prev new_ptr prev next new_ptr self.n += 1 self.n self n 1 self self val val def appendleft(self, val):
        ptr = self.dummy.next
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

     appendleft ptr = self.dummy.next ptr self.dummy.next self.dummy self dummy next new_ptr = Node(val) new_ptr Node(val) Node val new_ptr.prev = ptr.prev new_ptr.prev new_ptr prev ptr.prev ptr prev new_ptr.next = ptr new_ptr.next new_ptr next ptr new_ptr.next.prev = new_ptr new_ptr.next.prev new_ptr.next new_ptr next prev new_ptr new_ptr.prev.next = new_ptr new_ptr.prev.next new_ptr.prev new_ptr prev next new_ptr self.n += 1 self.n self n 1 self self val val def pop(self):
        ptr = self.dummy.prev
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

     pop ptr = self.dummy.prev ptr self.dummy.prev self.dummy self dummy prev ptr.prev.next = ptr.next ptr.prev.next ptr.prev ptr prev next ptr.next ptr next ptr.next.prev = ptr.prev ptr.next.prev ptr.next ptr next prev ptr.prev ptr prev self.n -= 1 self.n self n 1 self self def popleft(self):
        ptr = self.dummy.next
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

     popleft ptr = self.dummy.next ptr self.dummy.next self.dummy self dummy next ptr.prev.next = ptr.next ptr.prev.next ptr.prev ptr prev next ptr.next ptr next ptr.next.prev = ptr.prev ptr.next.prev ptr.next ptr next prev ptr.prev ptr prev self.n -= 1 self.n self n 1 self self def _get_node(self, i):
        if i < self.n // 2:
            ptr = self.dummy.next
            for _ in range(i):
                ptr = ptr.next
        else:
            ptr = self.dummy
            for _ in range(i, self.n):
                ptr = ptr.prev
        return ptr

     _get_node if i < self.n // 2:
            ptr = self.dummy.next
            for _ in range(i):
                ptr = ptr.next
        else:
            ptr = self.dummy
            for _ in range(i, self.n):
                ptr = ptr.prev
         i < self.n // 2 i self.n // 2 self.n self n 2 ptr = self.dummy.next ptr self.dummy.next self.dummy self dummy next for _ in range(i):
                ptr = ptr.next
         _ range(i) range i ptr = ptr.next ptr ptr.next ptr next ptr = self.dummy ptr self.dummy self dummy for _ in range(i, self.n):
                ptr = ptr.prev
         _ range(i, self.n) range i self.n self n ptr = ptr.prev ptr ptr.prev ptr prev return ptr ptr self self i i def _remove(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        ptr = self._get_node(i)
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1
        return ptr.val

     _remove if i < 0 or i >= self.n:
            raise IndexError()
         i < 0 or i >= self.n i < 0 i 0 i >= self.n i self.n self n raise IndexError() IndexError() IndexError ptr = self._get_node(i) ptr self._get_node(i) self._get_node self _get_node i ptr.prev.next = ptr.next ptr.prev.next ptr.prev ptr prev next ptr.next ptr next ptr.next.prev = ptr.prev ptr.next.prev ptr.next ptr next prev ptr.prev ptr prev self.n -= 1 self.n self n 1 return ptr.val ptr.val ptr val self self i i def _add(self, i, val):
        if i < 0 or i > self.n:
            raise IndexError()
        ptr = self._get_node(i)
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

     _add if i < 0 or i > self.n:
            raise IndexError()
         i < 0 or i > self.n i < 0 i 0 i > self.n i self.n self n raise IndexError() IndexError() IndexError ptr = self._get_node(i) ptr self._get_node(i) self._get_node self _get_node i new_ptr = Node(val) new_ptr Node(val) Node val new_ptr.prev = ptr.prev new_ptr.prev new_ptr prev ptr.prev ptr prev new_ptr.next = ptr new_ptr.next new_ptr next ptr new_ptr.next.prev = new_ptr new_ptr.next.prev new_ptr.next new_ptr next prev new_ptr new_ptr.prev.next = new_ptr new_ptr.prev.next new_ptr.prev new_ptr prev next new_ptr self.n += 1 self.n self n 1 self self i i val val def delete(self, val):
        ptr = self.dummy
        for _ in range(self.n):
            ptr = ptr.next
            if ptr.val == val:
                ptr.prev.next = ptr.next
                ptr.next.prev = ptr.prev
                self.n -= 1
                return True
        return False delete ptr = self.dummy ptr self.dummy self dummy for _ in range(self.n):
            ptr = ptr.next
            if ptr.val == val:
                ptr.prev.next = ptr.next
                ptr.next.prev = ptr.prev
                self.n -= 1
                return True
         _ range(self.n) range self.n self n ptr = ptr.next ptr ptr.next ptr next if ptr.val == val:
                ptr.prev.next = ptr.next
                ptr.next.prev = ptr.prev
                self.n -= 1
                return True
         ptr.val == val ptr.val ptr val val ptr.prev.next = ptr.next ptr.prev.next ptr.prev ptr prev next ptr.next ptr next ptr.next.prev = ptr.prev ptr.next.prev ptr.next ptr next prev ptr.prev ptr prev self.n -= 1 self.n self n 1 return True True return False False self self val val dls = DoublyLinkedList() dls DoublyLinkedList() DoublyLinkedList input() input for query in sys.stdin:
    if query[0] == "i":
        val = query[7:-1]
        dls.appendleft(val)
    elif query[6] == "F":
        dls.popleft()
    elif query[6] == "L":
        dls.pop()
    else:
        val = query[7:-1]
        dls.delete(val) query sys.stdin sys stdin if query[0] == "i":
        val = query[7:-1]
        dls.appendleft(val)
    elif query[6] == "F":
        dls.popleft()
    elif query[6] == "L":
        dls.pop()
    else:
        val = query[7:-1]
        dls.delete(val) query[0] == "i" query[0] query 0 "i" val = query[7:-1] val query[7:-1] query 7:-1 7 -1 dls.appendleft(val) dls.appendleft dls appendleft val elif query[6] == "F":
        dls.popleft()
     query[6] == "F" query[6] query 6 "F" dls.popleft() dls.popleft dls popleft elif query[6] == "L":
        dls.pop()
     query[6] == "L" query[6] query 6 "L" dls.pop() dls.pop dls pop val = query[7:-1] val query[7:-1] query 7:-1 7 -1 dls.delete(val) dls.delete dls delete val print(*list(dls)) print *list(dls) list(dls) list dls class Node:
    def __init__(self, val):
        self.val = val
        self.prev, self.next = None, None class Node:
    def __init__(self, val):
        self.val = val
        self.prev, self.next = None, None Node val = query[7:-1] query[7:-1] val class DoublyLinkedList:
    def __init__(self):
        self.n = 0
        self.dummy = Node(None)
        self.dummy.prev = self.dummy
        self.dummy.next = self.dummy

    def __getitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val 

    def __setitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val

    def __len__(self):
        return self.n

    def __bool__(self):
        return self.n != 0

    def __iter__(self):
        self.p = self.dummy
        return self

    def __next__(self):
        self.p = self.p.next
        if self.p == self.dummy:
            raise StopIteration
        return self.p.val

    def append(self, val):
        ptr = self.dummy.prev
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def appendleft(self, val):
        ptr = self.dummy.next
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def pop(self):
        ptr = self.dummy.prev
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def popleft(self):
        ptr = self.dummy.next
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def _get_node(self, i):
        if i < self.n // 2:
            ptr = self.dummy.next
            for _ in range(i):
                ptr = ptr.next
        else:
            ptr = self.dummy
            for _ in range(i, self.n):
                ptr = ptr.prev
        return ptr

    def _remove(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        ptr = self._get_node(i)
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1
        return ptr.val

    def _add(self, i, val):
        if i < 0 or i > self.n:
            raise IndexError()
        ptr = self._get_node(i)
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def delete(self, val):
        ptr = self.dummy
        for _ in range(self.n):
            ptr = ptr.next
            if ptr.val == val:
                ptr.prev.next = ptr.next
                ptr.next.prev = ptr.prev
                self.n -= 1
                return True
        return False class DoublyLinkedList:
    def __init__(self):
        self.n = 0
        self.dummy = Node(None)
        self.dummy.prev = self.dummy
        self.dummy.next = self.dummy

    def __getitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val 

    def __setitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val

    def __len__(self):
        return self.n

    def __bool__(self):
        return self.n != 0

    def __iter__(self):
        self.p = self.dummy
        return self

    def __next__(self):
        self.p = self.p.next
        if self.p == self.dummy:
            raise StopIteration
        return self.p.val

    def append(self, val):
        ptr = self.dummy.prev
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def appendleft(self, val):
        ptr = self.dummy.next
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def pop(self):
        ptr = self.dummy.prev
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def popleft(self):
        ptr = self.dummy.next
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def _get_node(self, i):
        if i < self.n // 2:
            ptr = self.dummy.next
            for _ in range(i):
                ptr = ptr.next
        else:
            ptr = self.dummy
            for _ in range(i, self.n):
                ptr = ptr.prev
        return ptr

    def _remove(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        ptr = self._get_node(i)
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1
        return ptr.val

    def _add(self, i, val):
        if i < 0 or i > self.n:
            raise IndexError()
        ptr = self._get_node(i)
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def delete(self, val):
        ptr = self.dummy
        for _ in range(self.n):
            ptr = ptr.next
            if ptr.val == val:
                ptr.prev.next = ptr.next
                ptr.next.prev = ptr.prev
                self.n -= 1
                return True
        return False DoublyLinkedList val = query[7:-1] query[7:-1] val dls = DoublyLinkedList() DoublyLinkedList() dls input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline


class Node:
    def __init__(self, val):
        self.val = val
        self.prev, self.next = None, None


class DoublyLinkedList:
    def __init__(self):
        self.n = 0
        self.dummy = Node(None)
        self.dummy.prev = self.dummy
        self.dummy.next = self.dummy

    def __getitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val 

    def __setitem__(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        return self._get_node(i).val

    def __len__(self):
        return self.n

    def __bool__(self):
        return self.n != 0

    def __iter__(self):
        self.p = self.dummy
        return self

    def __next__(self):
        self.p = self.p.next
        if self.p == self.dummy:
            raise StopIteration
        return self.p.val

    def append(self, val):
        ptr = self.dummy.prev
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def appendleft(self, val):
        ptr = self.dummy.next
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def pop(self):
        ptr = self.dummy.prev
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def popleft(self):
        ptr = self.dummy.next
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1

    def _get_node(self, i):
        if i < self.n // 2:
            ptr = self.dummy.next
            for _ in range(i):
                ptr = ptr.next
        else:
            ptr = self.dummy
            for _ in range(i, self.n):
                ptr = ptr.prev
        return ptr

    def _remove(self, i):
        if i < 0 or i >= self.n:
            raise IndexError()
        ptr = self._get_node(i)
        ptr.prev.next = ptr.next
        ptr.next.prev = ptr.prev
        self.n -= 1
        return ptr.val

    def _add(self, i, val):
        if i < 0 or i > self.n:
            raise IndexError()
        ptr = self._get_node(i)
        new_ptr = Node(val)
        new_ptr.prev = ptr.prev
        new_ptr.next = ptr
        new_ptr.next.prev = new_ptr
        new_ptr.prev.next = new_ptr
        self.n += 1

    def delete(self, val):
        ptr = self.dummy
        for _ in range(self.n):
            ptr = ptr.next
            if ptr.val == val:
                ptr.prev.next = ptr.next
                ptr.next.prev = ptr.prev
                self.n -= 1
                return True
        return False


dls = DoublyLinkedList()
input()
for query in sys.stdin:
    if query[0] == "i":
        val = query[7:-1]
        dls.appendleft(val)
    elif query[6] == "F":
        dls.popleft()
    elif query[6] == "L":
        dls.pop()
    else:
        val = query[7:-1]
        dls.delete(val)

print(*list(dls))
