from collections import deque
import sys

input()
lst = deque()

for s in sys.stdin:
    if s[0] == 'i':
        lst.appendleft(s[7:-1])

    else:
        a = s[6]
        if a == ' ':
            try:
                lst.remove(s[7:-1])
            except:
                pass

        elif a == 'F':
                lst.popleft()

        else:
            lst.pop()

print(*lst) from collections import deque import sys sys input() input lst = deque() lst deque() deque for s in sys.stdin:
    if s[0] == 'i':
        lst.appendleft(s[7:-1])

    else:
        a = s[6]
        if a == ' ':
            try:
                lst.remove(s[7:-1])
            except:
                pass

        elif a == 'F':
                lst.popleft()

        else:
            lst.pop() s sys.stdin sys stdin if s[0] == 'i':
        lst.appendleft(s[7:-1])

    else:
        a = s[6]
        if a == ' ':
            try:
                lst.remove(s[7:-1])
            except:
                pass

        elif a == 'F':
                lst.popleft()

        else:
            lst.pop() s[0] == 'i' s[0] s 0 'i' lst.appendleft(s[7:-1]) lst.appendleft lst appendleft s[7:-1] s 7:-1 7 -1 a = s[6] a s[6] s 6 if a == ' ':
            try:
                lst.remove(s[7:-1])
            except:
                pass

        elif a == 'F':
                lst.popleft()

        else:
            lst.pop() a == ' ' a ' ' try:
                lst.remove(s[7:-1])
            except:
                pass

         except:
                pass

         lst.remove(s[7:-1]) lst.remove lst remove s[7:-1] s 7:-1 7 -1 elif a == 'F':
                lst.popleft()

         a == 'F' a 'F' lst.popleft() lst.popleft lst popleft lst.pop() lst.pop lst pop print(*lst) print *lst lst a = s[6] s[6] a lst = deque() deque() lst
from collections import deque
import sys

input()
lst = deque()

for s in sys.stdin:
    if s[0] == 'i':
        lst.appendleft(s[7:-1])

    else:
        a = s[6]
        if a == ' ':
            try:
                lst.remove(s[7:-1])
            except:
                pass

        elif a == 'F':
                lst.popleft()

        else:
            lst.pop()

print(*lst)
