from collections import deque
import sys

c=sys.stdin

def main():
    q = deque()
    N=int(input())

    for i in range(N):
        order=c.readline()
        if order[6]==" ":
            if order[0]=="i":
                q.appendleft(int(order[7:]))
            else:
                try :
                    q.remove(int(order[7:]))
                except:
                    pass
        else:
            if order[6]=="F":
                q.popleft()
            else:
                q.pop()
    print(*list(q))

if __name__ == "__main__":
    main() from collections import deque import sys sys c=sys.stdin c sys.stdin sys stdin def main():
    q = deque()
    N=int(input())

    for i in range(N):
        order=c.readline()
        if order[6]==" ":
            if order[0]=="i":
                q.appendleft(int(order[7:]))
            else:
                try :
                    q.remove(int(order[7:]))
                except:
                    pass
        else:
            if order[6]=="F":
                q.popleft()
            else:
                q.pop()
    print(*list(q)) main q = deque() q deque() deque N=int(input()) N int(input()) int input() input for i in range(N):
        order=c.readline()
        if order[6]==" ":
            if order[0]=="i":
                q.appendleft(int(order[7:]))
            else:
                try :
                    q.remove(int(order[7:]))
                except:
                    pass
        else:
            if order[6]=="F":
                q.popleft()
            else:
                q.pop()
     i range(N) range N order=c.readline() order c.readline() c.readline c readline if order[6]==" ":
            if order[0]=="i":
                q.appendleft(int(order[7:]))
            else:
                try :
                    q.remove(int(order[7:]))
                except:
                    pass
        else:
            if order[6]=="F":
                q.popleft()
            else:
                q.pop()
     order[6]==" " order[6] order 6 " " if order[0]=="i":
                q.appendleft(int(order[7:]))
            else:
                try :
                    q.remove(int(order[7:]))
                except:
                    pass
         order[0]=="i" order[0] order 0 "i" q.appendleft(int(order[7:])) q.appendleft q appendleft int(order[7:]) int order[7:] order 7: 7 try :
                    q.remove(int(order[7:]))
                except:
                    pass
         except:
                    pass
         q.remove(int(order[7:])) q.remove q remove int(order[7:]) int order[7:] order 7: 7 if order[6]=="F":
                q.popleft()
            else:
                q.pop()
     order[6]=="F" order[6] order 6 "F" q.popleft() q.popleft q popleft q.pop() q.pop q pop print(*list(q)) print *list(q) list(q) list q if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main c=sys.stdin sys.stdin c def main():
    q = deque()
    N=int(input())

    for i in range(N):
        order=c.readline()
        if order[6]==" ":
            if order[0]=="i":
                q.appendleft(int(order[7:]))
            else:
                try :
                    q.remove(int(order[7:]))
                except:
                    pass
        else:
            if order[6]=="F":
                q.popleft()
            else:
                q.pop()
    print(*list(q)) def main():
    q = deque()
    N=int(input())

    for i in range(N):
        order=c.readline()
        if order[6]==" ":
            if order[0]=="i":
                q.appendleft(int(order[7:]))
            else:
                try :
                    q.remove(int(order[7:]))
                except:
                    pass
        else:
            if order[6]=="F":
                q.popleft()
            else:
                q.pop()
    print(*list(q)) main
from collections import deque
import sys

c=sys.stdin

def main():
    q = deque()
    N=int(input())

    for i in range(N):
        order=c.readline()
        if order[6]==" ":
            if order[0]=="i":
                q.appendleft(int(order[7:]))
            else:
                try :
                    q.remove(int(order[7:]))
                except:
                    pass
        else:
            if order[6]=="F":
                q.popleft()
            else:
                q.pop()
    print(*list(q))

if __name__ == "__main__":
    main()
