from collections import deque
import sys

dq = deque()
num = int(sys.stdin.readline())
line = sys.stdin.readlines()

for i in range(num):

    order = line[i].split()

    if order[0] == 'insert':
        dq.appendleft(order[1])
    elif order[0] == 'deleteFirst':
        dq.popleft()
    elif order[0] == 'deleteLast':
        dq.pop()
    else:
        if order[1] in dq:
            dq.remove(order[1])

print(' '.join(dq)) from collections import deque import sys sys dq = deque() dq deque() deque num = int(sys.stdin.readline()) num int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline line = sys.stdin.readlines() line sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines for i in range(num):

    order = line[i].split()

    if order[0] == 'insert':
        dq.appendleft(order[1])
    elif order[0] == 'deleteFirst':
        dq.popleft()
    elif order[0] == 'deleteLast':
        dq.pop()
    else:
        if order[1] in dq:
            dq.remove(order[1]) i range(num) range num order = line[i].split() order line[i].split() [i].split [i] line i split if order[0] == 'insert':
        dq.appendleft(order[1])
    elif order[0] == 'deleteFirst':
        dq.popleft()
    elif order[0] == 'deleteLast':
        dq.pop()
    else:
        if order[1] in dq:
            dq.remove(order[1]) order[0] == 'insert' order[0] order 0 'insert' dq.appendleft(order[1]) dq.appendleft dq appendleft order[1] order 1 elif order[0] == 'deleteFirst':
        dq.popleft()
     order[0] == 'deleteFirst' order[0] order 0 'deleteFirst' dq.popleft() dq.popleft dq popleft elif order[0] == 'deleteLast':
        dq.pop()
     order[0] == 'deleteLast' order[0] order 0 'deleteLast' dq.pop() dq.pop dq pop if order[1] in dq:
            dq.remove(order[1]) order[1] in dq order[1] order 1 dq dq.remove(order[1]) dq.remove dq remove order[1] order 1 print(' '.join(dq)) print ' '.join(dq) ' '.join ' ' join dq num = int(sys.stdin.readline()) int(sys.stdin.readline()) num order = line[i].split() line[i].split() order line = sys.stdin.readlines() sys.stdin.readlines() line dq = deque() deque() dq
from collections import deque
import sys

dq = deque()
num = int(sys.stdin.readline())
line = sys.stdin.readlines()

for i in range(num):

    order = line[i].split()

    if order[0] == 'insert':
        dq.appendleft(order[1])
    elif order[0] == 'deleteFirst':
        dq.popleft()
    elif order[0] == 'deleteLast':
        dq.pop()
    else:
        if order[1] in dq:
            dq.remove(order[1])

print(' '.join(dq))