from collections import deque


def main():
    d = deque()
    for _ in range(int(input())):
        command = input()
        if command[0] == 'i':
            d.appendleft(command[7:])
        elif command[6] == ' ':
            try:
                d.remove(command[7:])
            except ValueError:
                pass
        elif len(command) == 11:
            d.popleft()
        else:
            d.pop()
    print(*d)


if __name__ == '__main__':
    main()
 from collections import deque def main():
    d = deque()
    for _ in range(int(input())):
        command = input()
        if command[0] == 'i':
            d.appendleft(command[7:])
        elif command[6] == ' ':
            try:
                d.remove(command[7:])
            except ValueError:
                pass
        elif len(command) == 11:
            d.popleft()
        else:
            d.pop()
    print(*d) main d = deque() d deque() deque for _ in range(int(input())):
        command = input()
        if command[0] == 'i':
            d.appendleft(command[7:])
        elif command[6] == ' ':
            try:
                d.remove(command[7:])
            except ValueError:
                pass
        elif len(command) == 11:
            d.popleft()
        else:
            d.pop()
     _ range(int(input())) range int(input()) int input() input command = input() command input() input if command[0] == 'i':
            d.appendleft(command[7:])
        elif command[6] == ' ':
            try:
                d.remove(command[7:])
            except ValueError:
                pass
        elif len(command) == 11:
            d.popleft()
        else:
            d.pop()
     command[0] == 'i' command[0] command 0 'i' d.appendleft(command[7:]) d.appendleft d appendleft command[7:] command 7: 7 elif command[6] == ' ':
            try:
                d.remove(command[7:])
            except ValueError:
                pass
         command[6] == ' ' command[6] command 6 ' ' try:
                d.remove(command[7:])
            except ValueError:
                pass
         except ValueError:
                pass
         d.remove(command[7:]) d.remove d remove command[7:] command 7: 7 elif len(command) == 11:
            d.popleft()
         len(command) == 11 len(command) len command 11 d.popleft() d.popleft d popleft d.pop() d.pop d pop print(*d) print *d d if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    d = deque()
    for _ in range(int(input())):
        command = input()
        if command[0] == 'i':
            d.appendleft(command[7:])
        elif command[6] == ' ':
            try:
                d.remove(command[7:])
            except ValueError:
                pass
        elif len(command) == 11:
            d.popleft()
        else:
            d.pop()
    print(*d) def main():
    d = deque()
    for _ in range(int(input())):
        command = input()
        if command[0] == 'i':
            d.appendleft(command[7:])
        elif command[6] == ' ':
            try:
                d.remove(command[7:])
            except ValueError:
                pass
        elif len(command) == 11:
            d.popleft()
        else:
            d.pop()
    print(*d) main
from collections import deque


def main():
    d = deque()
    for _ in range(int(input())):
        command = input()
        if command[0] == 'i':
            d.appendleft(command[7:])
        elif command[6] == ' ':
            try:
                d.remove(command[7:])
            except ValueError:
                pass
        elif len(command) == 11:
            d.popleft()
        else:
            d.pop()
    print(*d)


if __name__ == '__main__':
    main()

