import sys
from collections import deque

n = int(input())
ary = deque([])

for line in sys.stdin:
    op = line.strip().split()
    cmd = op[0]

    if cmd[0] == 'i':
        x = op[1]
        ary.appendleft(x)

    elif len(cmd) == 6:
        x = op[1]
        if x in ary:
            ary.remove(x)

    elif len(cmd) == 10:
        ary.pop()

    else:
        ary.popleft()

print(*ary)
 import sys sys from collections import deque n = int(input()) n int(input()) int input() input ary = deque([]) ary deque([]) deque [] for line in sys.stdin:
    op = line.strip().split()
    cmd = op[0]

    if cmd[0] == 'i':
        x = op[1]
        ary.appendleft(x)

    elif len(cmd) == 6:
        x = op[1]
        if x in ary:
            ary.remove(x)

    elif len(cmd) == 10:
        ary.pop()

    else:
        ary.popleft() line sys.stdin sys stdin op = line.strip().split() op line.strip().split() line.strip().split line.strip() line.strip line strip split cmd = op[0] cmd op[0] op 0 if cmd[0] == 'i':
        x = op[1]
        ary.appendleft(x)

    elif len(cmd) == 6:
        x = op[1]
        if x in ary:
            ary.remove(x)

    elif len(cmd) == 10:
        ary.pop()

    else:
        ary.popleft() cmd[0] == 'i' cmd[0] cmd 0 'i' x = op[1] x op[1] op 1 ary.appendleft(x) ary.appendleft ary appendleft x elif len(cmd) == 6:
        x = op[1]
        if x in ary:
            ary.remove(x)

     len(cmd) == 6 len(cmd) len cmd 6 x = op[1] x op[1] op 1 if x in ary:
            ary.remove(x)

     x in ary x ary ary.remove(x) ary.remove ary remove x elif len(cmd) == 10:
        ary.pop()

     len(cmd) == 10 len(cmd) len cmd 10 ary.pop() ary.pop ary pop ary.popleft() ary.popleft ary popleft print(*ary) print *ary ary x = op[1] op[1] x op = line.strip().split() line.strip().split() op n = int(input()) int(input()) n ary = deque([]) deque([]) ary cmd = op[0] op[0] cmd x = op[1] op[1] x
import sys
from collections import deque

n = int(input())
ary = deque([])

for line in sys.stdin:
    op = line.strip().split()
    cmd = op[0]

    if cmd[0] == 'i':
        x = op[1]
        ary.appendleft(x)

    elif len(cmd) == 6:
        x = op[1]
        if x in ary:
            ary.remove(x)

    elif len(cmd) == 10:
        ary.pop()

    else:
        ary.popleft()

print(*ary)

