import collections

n = int(input())
que = collections.deque()

for i in range(n):
    line = input()

    if line[0] == 'i':
        que.appendleft(int(line[7:]))
    elif line[6] == ' ':
        try:
            que.remove(int(line[7:]))
        except ValueError:
            pass
    elif line[6] == 'F':
        que.popleft()
    else:
        que.pop()

print(*que)
 import collections collections n = int(input()) n int(input()) int input() input que = collections.deque() que collections.deque() collections.deque collections deque for i in range(n):
    line = input()

    if line[0] == 'i':
        que.appendleft(int(line[7:]))
    elif line[6] == ' ':
        try:
            que.remove(int(line[7:]))
        except ValueError:
            pass
    elif line[6] == 'F':
        que.popleft()
    else:
        que.pop() i range(n) range n line = input() line input() input if line[0] == 'i':
        que.appendleft(int(line[7:]))
    elif line[6] == ' ':
        try:
            que.remove(int(line[7:]))
        except ValueError:
            pass
    elif line[6] == 'F':
        que.popleft()
    else:
        que.pop() line[0] == 'i' line[0] line 0 'i' que.appendleft(int(line[7:])) que.appendleft que appendleft int(line[7:]) int line[7:] line 7: 7 elif line[6] == ' ':
        try:
            que.remove(int(line[7:]))
        except ValueError:
            pass
     line[6] == ' ' line[6] line 6 ' ' try:
            que.remove(int(line[7:]))
        except ValueError:
            pass
     except ValueError:
            pass
     que.remove(int(line[7:])) que.remove que remove int(line[7:]) int line[7:] line 7: 7 elif line[6] == 'F':
        que.popleft()
     line[6] == 'F' line[6] line 6 'F' que.popleft() que.popleft que popleft que.pop() que.pop que pop print(*que) print *que que line = input() input() line n = int(input()) int(input()) n que = collections.deque() collections.deque() que
import collections

n = int(input())
que = collections.deque()

for i in range(n):
    line = input()

    if line[0] == 'i':
        que.appendleft(int(line[7:]))
    elif line[6] == ' ':
        try:
            que.remove(int(line[7:]))
        except ValueError:
            pass
    elif line[6] == 'F':
        que.popleft()
    else:
        que.pop()

print(*que)

