#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

// I/O
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}

void put_str(char *str) { while(*str) putchar_unlocked(*str++); }

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}

int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}
//


// Util
#define container_of(ptr, type, member) ({  \
    void *__mptr = (void *)(ptr);           \
    ((type *)(__mptr - offsetof(type, member))); })
//


// List
struct list_head {
    struct list_head *next, *prev;
};

static inline void INIT_LIST_HEAD(struct list_head *list) {
    list->next = list;
    list->prev = list;
}

static inline void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next) {
    next->prev = new;
    new->next = next;
    new->prev = prev;
    prev->next = new;
}

static inline void list_add(struct list_head *new, struct list_head *head) {
    __list_add(new, head, head->next);
}

static inline void list_add_tail(struct list_head *new, struct list_head *head) {
    __list_add(new, head->prev, head);
}

static inline void __list_del(struct list_head *prev, struct list_head *next) {
    next->prev = prev;
    prev->next = next;
}

static inline void __list_del_entry(struct list_head *entry) {
    __list_del(entry->prev, entry->next);
}

static inline void list_del(struct list_head *entry) {
    __list_del_entry(entry);
    entry->next = NULL;
    entry->prev = NULL;
}

static inline void list_move_tail(struct list_head *list, struct list_head *head) {
    __list_del_entry(list);
    list_add_tail(list, head);
}

static inline int list_empty(const struct list_head *head) {
    return head->next == head;
}

#define list_entry(ptr, type, member) container_of(ptr, type, member)
#define list_first_entry(ptr, type, member) list_entry((ptr)->next, type, member)
#define list_last_entry(ptr, type, member) list_entry((ptr)->prev, type, member)
#define list_next_entry(pos, member) list_entry((pos)->member.next, typeof(*(pos)), member)
#define list_for_each_entry(pos, head, member)                  \
    for(pos = list_first_entry(head, typeof(*pos), member);     \
        &pos->member != (head);                                 \
        pos = list_next_entry(pos, member))
//


// my node
struct my_node {
    int num;
    struct list_head list;
};

void my_del(int num, struct list_head *head) {
    struct my_node *data;
    list_for_each_entry(data, head, list) {
        if(data->num == num) {
            list_del(&data->list);
            free(data);
            break;
        }
    }
}
//


int main(int argc, char **argv) {
    struct list_head head;
    INIT_LIST_HEAD(&head);

    int n = get_uint();
    char str[16];
    struct my_node *data;
    for(int i = 0; i < n; ++i) {
        get_str(str);
        if(*str == 'i') {
            data = malloc(sizeof(struct my_node));
            data->num = get_uint();
            list_add(&data->list, &head);
        } else if(str[6] == 0) {
            my_del(get_uint(), &head);
        } else if(str[6] == 'F') {
            data = list_first_entry(&head, struct my_node, list);
            list_del(&data->list);
            free(data);
        } else {
            data = list_last_entry(&head, struct my_node, list);
            list_del(&data->list);
            free(data);
        }
    }

    for(data = list_first_entry(&head, struct my_node, list); &data->list != head.prev; data = list_next_entry(data, list)) {
        put_uint(data->num);
        putchar_unlocked(' ');
    }
    put_uint(data->num);
    putchar_unlocked('\n');
    return 0;
}



Measured memory_bytes: 32836