from collections import deque
import sys
n = int(input())
deq = deque()
sub_deq = {}
for cmd in sys.stdin.readlines():
    if cmd == 'deleteFirst\n':
        while deq:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
    elif cmd == 'deleteLast\n':
        while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
    else:
        cmd, val = cmd.split()
        if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break
sys.stdout.write(" ".join(data[0] for data in reversed(deq) if data[1]))
sys.stdout.write('\n') from collections import deque import sys sys n = int(input()) n int(input()) int input() input deq = deque() deq deque() deque sub_deq = {} sub_deq {} for cmd in sys.stdin.readlines():
    if cmd == 'deleteFirst\n':
        while deq:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
    elif cmd == 'deleteLast\n':
        while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
    else:
        cmd, val = cmd.split()
        if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break cmd sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines if cmd == 'deleteFirst\n':
        while deq:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
    elif cmd == 'deleteLast\n':
        while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
    else:
        cmd, val = cmd.split()
        if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break cmd == 'deleteFirst\n' cmd 'deleteFirst\n' while deq:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
     deq data = deq.pop() data deq.pop() deq.pop deq pop if data[1]:
                data[1] = 0
                break
     data[1] data 1 data[1] = 0 data[1] data 1 0 break elif cmd == 'deleteLast\n':
        while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
     cmd == 'deleteLast\n' cmd 'deleteLast\n' while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
     deq data = deq.popleft() data deq.popleft() deq.popleft deq popleft if data[1]:
                data[1] = 0
                break
     data[1] data 1 data[1] = 0 data[1] data 1 0 break cmd, val = cmd.split() cmd cmd.split() cmd.split cmd split val if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break cmd == 'insert' cmd 'insert' data = [val, 1] data [val, 1] val 1 deq.append(data) deq.append deq append data if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
         val not in sub_deq val sub_deq sub_deq[val] = [data] sub_deq[val] sub_deq val [data] data sub_deq[val].append(data) [val].append [val] sub_deq val append data elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break cmd == 'delete' cmd 'delete' if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break val in sub_deq val sub_deq deq_v = sub_deq[val] deq_v sub_deq[val] sub_deq val while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break deq_v data = deq_v.pop() data deq_v.pop() deq_v.pop deq_v pop if data[1]:
                        data[1] = 0
                        break data[1] data 1 data[1] = 0 data[1] data 1 0 break sys.stdout.write(" ".join(data[0] for data in reversed(deq) if data[1])) sys.stdout.write sys.stdout sys stdout write " ".join(data[0] for data in reversed(deq) if data[1]) " ".join " " join data[0] data 0 sys.stdout.write('\n') sys.stdout.write sys.stdout sys stdout write '\n' deq = deque() deque() deq data = deq.popleft() deq.popleft() data data = deq.pop() deq.pop() data val = cmd.split() cmd.split() val n = int(input()) int(input()) n deq_v = sub_deq[val] sub_deq[val] deq_v sub_deq = {} {} sub_deq data = deq_v.pop() deq_v.pop() data data = [val, 1] [val, 1] data cmd, val = cmd.split() cmd.split() cmd
from collections import deque
import sys
n = int(input())
deq = deque()
sub_deq = {}
for cmd in sys.stdin.readlines():
    if cmd == 'deleteFirst\n':
        while deq:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
    elif cmd == 'deleteLast\n':
        while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
    else:
        cmd, val = cmd.split()
        if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break
sys.stdout.write(" ".join(data[0] for data in reversed(deq) if data[1]))
sys.stdout.write('\n')