from collections import deque

# 双方向連結リストの実装
N = int(input())
commands = [input() for _ in range(N)]

d = deque()

for c in commands:
    if c == "deleteFirst":
        if d:
            d.popleft()

    elif c == 'deleteLast':
        if d:
            d.pop()

    elif 'delete ' in c:
        _, key = c.split()
        key = int(key)
        if key in d:
            d.remove(key)

    elif 'insert ' in c:
        _, key = c.split()
        key = int(key)
        d.appendleft(key)

print(*d)
 from collections import deque N = int(input()) N int(input()) int input() input input() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) input() input commands = [input() for _ in range(N)] commands [input() for _ in range(N)] d = deque() d deque() deque for c in commands:
    if c == "deleteFirst":
        if d:
            d.popleft()

    elif c == 'deleteLast':
        if d:
            d.pop()

    elif 'delete ' in c:
        _, key = c.split()
        key = int(key)
        if key in d:
            d.remove(key)

    elif 'insert ' in c:
        _, key = c.split()
        key = int(key)
        d.appendleft(key) c commands if c == "deleteFirst":
        if d:
            d.popleft()

    elif c == 'deleteLast':
        if d:
            d.pop()

    elif 'delete ' in c:
        _, key = c.split()
        key = int(key)
        if key in d:
            d.remove(key)

    elif 'insert ' in c:
        _, key = c.split()
        key = int(key)
        d.appendleft(key) c == "deleteFirst" c "deleteFirst" if d:
            d.popleft()

     d d.popleft() d.popleft d popleft elif c == 'deleteLast':
        if d:
            d.pop()

     c == 'deleteLast' c 'deleteLast' if d:
            d.pop()

     d d.pop() d.pop d pop elif 'delete ' in c:
        _, key = c.split()
        key = int(key)
        if key in d:
            d.remove(key)

     'delete ' in c 'delete ' c _, key = c.split() _ c.split() c.split c split key key = int(key) key int(key) int key if key in d:
            d.remove(key)

     key in d key d d.remove(key) d.remove d remove key elif 'insert ' in c:
        _, key = c.split()
        key = int(key)
        d.appendleft(key) 'insert ' in c 'insert ' c _, key = c.split() _ c.split() c.split c split key key = int(key) key int(key) int key d.appendleft(key) d.appendleft d appendleft key print(*d) print *d d _, key = c.split() c.split() _ N = int(input()) int(input()) N key = c.split() c.split() key key = c.split() c.split() key key = int(key) int(key) key key = int(key) int(key) key d = deque() deque() d _, key = c.split() c.split() _ commands = [input() for _ in range(N)] [input() for _ in range(N)] commands
from collections import deque

# 双方向連結リストの実装
N = int(input())
commands = [input() for _ in range(N)]

d = deque()

for c in commands:
    if c == "deleteFirst":
        if d:
            d.popleft()

    elif c == 'deleteLast':
        if d:
            d.pop()

    elif 'delete ' in c:
        _, key = c.split()
        key = int(key)
        if key in d:
            d.remove(key)

    elif 'insert ' in c:
        _, key = c.split()
        key = int(key)
        d.appendleft(key)

print(*d)

