import std.stdio, std.algorithm, std.conv, std.string, std.range;
import std.container;

void main(string[] args) {
    auto dlist = DList!int();

    int n = readln.chomp.to!int;
    foreach (i; 0..n) {
        string[] input = readln.chomp.split(" ");
        string op = input[0];

        if (op == "insert") {
            dlist.insertFront(input[1].to!int);
        } else if (op == "delete") {
            auto range = dlist[];
            for ( ; !range.empty; range.popFront()) {
                if (range.front == input[1].to!int) {
                    dlist.stableLinearRemove(take(range, 1));
                    break;
                }
            }
        } else if (op == "deleteFirst") {
            dlist.removeFront;
        } else if (op == "deleteLast") {
            dlist.removeBack;
        }
    }

    dlist[].map!(to!string).join(" ").writeln;
}