from collections import deque

n = int(input())
dq = deque()
for _ in range(n):
    query = input()
    if query == "deleteFirst":
        dq.popleft()
    elif query == "deleteLast":
        dq.pop()
    else:
        op, arg = query.split()
        if op == "insert":
            dq.appendleft(arg)
        else:
            tmp = deque()
            while dq:
                item = dq.popleft()
                if item == arg:
                    break
                else:
                    tmp.append(item)
            while tmp:
                dq.appendleft(tmp.pop())
print(*dq)
 from collections import deque n = int(input()) n int(input()) int input() input dq = deque() dq deque() deque for _ in range(n):
    query = input()
    if query == "deleteFirst":
        dq.popleft()
    elif query == "deleteLast":
        dq.pop()
    else:
        op, arg = query.split()
        if op == "insert":
            dq.appendleft(arg)
        else:
            tmp = deque()
            while dq:
                item = dq.popleft()
                if item == arg:
                    break
                else:
                    tmp.append(item)
            while tmp:
                dq.appendleft(tmp.pop()) _ range(n) range n query = input() query input() input if query == "deleteFirst":
        dq.popleft()
    elif query == "deleteLast":
        dq.pop()
    else:
        op, arg = query.split()
        if op == "insert":
            dq.appendleft(arg)
        else:
            tmp = deque()
            while dq:
                item = dq.popleft()
                if item == arg:
                    break
                else:
                    tmp.append(item)
            while tmp:
                dq.appendleft(tmp.pop()) query == "deleteFirst" query "deleteFirst" dq.popleft() dq.popleft dq popleft elif query == "deleteLast":
        dq.pop()
     query == "deleteLast" query "deleteLast" dq.pop() dq.pop dq pop op, arg = query.split() op query.split() query.split query split arg if op == "insert":
            dq.appendleft(arg)
        else:
            tmp = deque()
            while dq:
                item = dq.popleft()
                if item == arg:
                    break
                else:
                    tmp.append(item)
            while tmp:
                dq.appendleft(tmp.pop()) op == "insert" op "insert" dq.appendleft(arg) dq.appendleft dq appendleft arg tmp = deque() tmp deque() deque while dq:
                item = dq.popleft()
                if item == arg:
                    break
                else:
                    tmp.append(item)
             dq item = dq.popleft() item dq.popleft() dq.popleft dq popleft if item == arg:
                    break
                else:
                    tmp.append(item)
             item == arg item arg break tmp.append(item) tmp.append tmp append item while tmp:
                dq.appendleft(tmp.pop()) tmp dq.appendleft(tmp.pop()) dq.appendleft dq appendleft tmp.pop() tmp.pop tmp pop print(*dq) print *dq dq tmp = deque() deque() tmp dq = deque() deque() dq n = int(input()) int(input()) n query = input() input() query op, arg = query.split() query.split() op arg = query.split() query.split() arg item = dq.popleft() dq.popleft() item
from collections import deque

n = int(input())
dq = deque()
for _ in range(n):
    query = input()
    if query == "deleteFirst":
        dq.popleft()
    elif query == "deleteLast":
        dq.pop()
    else:
        op, arg = query.split()
        if op == "insert":
            dq.appendleft(arg)
        else:
            tmp = deque()
            while dq:
                item = dq.popleft()
                if item == arg:
                    break
                else:
                    tmp.append(item)
            while tmp:
                dq.appendleft(tmp.pop())
print(*dq)

