#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>



typedef struct DOUBLYLINKEDLIST{
    struct DOUBLYLINKEDLIST *  prev;
    struct DOUBLYLINKEDLIST *  next;
    int value;
}DOUBLYLINKEDLIST;


void insert(DOUBLYLINKEDLIST **head, DOUBLYLINKEDLIST **tail, int x){
    DOUBLYLINKEDLIST * inserted = (DOUBLYLINKEDLIST *)malloc(sizeof(DOUBLYLINKEDLIST));
    inserted->value = x;
    
    if(*head == NULL && *tail == NULL){
        inserted->prev = NULL;
        inserted->next = NULL;
        *head = inserted;
        *tail = inserted;
    }
    else
    {
        inserted->prev = (*head)->prev;
        (*head)->prev = inserted;
        inserted->next = (*head);
        (*head) = inserted;
    }
    return;
}

void delete(DOUBLYLINKEDLIST **head, DOUBLYLINKEDLIST **tail, int x){
    
    DOUBLYLINKEDLIST * canbedeleted = *head;
    
    if(*head == NULL && *tail == NULL){
        return;
    }
    
    if((*head) == (*tail) && (*head)->value == x){
        free((*head));
        *head = NULL;
        *tail = NULL;
        return;
    }
    
    while(canbedeleted != NULL){
        if(canbedeleted->value == x){

            if(canbedeleted == (*head))
            {
                *head = canbedeleted->next;
                (*head)->prev = NULL;
            }
            else if(canbedeleted == (*tail))
            {
                *tail = canbedeleted->prev;
                (*tail)->next = NULL;
            }
            else
            {
                canbedeleted->prev->next = canbedeleted->next;
                canbedeleted->next->prev = canbedeleted->prev;
            }
            
            free(canbedeleted);
            break;
        }else{
            canbedeleted = canbedeleted->next;
        }
    }
    return;
}

void deleteFirst(DOUBLYLINKEDLIST **head, DOUBLYLINKEDLIST **tail){
    
    DOUBLYLINKEDLIST * deleted = (*head);
    
    if(*head == NULL && *tail == NULL){
        return;
    }
    
    if((*head) == (*tail)){
        *head = NULL;
        *tail = NULL;
        free(deleted);
        return;
    }
    
    (*head) = (*head)->next;
    (*head)->prev = NULL;
    free(deleted);
    
    return;
}

void deleteLast(DOUBLYLINKEDLIST **head, DOUBLYLINKEDLIST **tail){
    
    DOUBLYLINKEDLIST * deleted = (*tail);
    
    if(*head == NULL && *tail == NULL){
        return;
    }
    
    if((*head) == (*tail)){
        *head = NULL;
        *tail = NULL;
        free(deleted);
        return;
    }
    
    (*tail) = (*tail)->prev;
    (*tail)->next = NULL;
    free(deleted);
    return;
}

int main(int argc, const char * argv[]){
    
    //Input
    int i;
    int op_num;
    char operator[20];
    int operand;
    DOUBLYLINKEDLIST * head = NULL;
    DOUBLYLINKEDLIST * tail = NULL;
    
    
    scanf("%d", &op_num);
    
    for(i = 0; i < op_num; i++){
        scanf("%s", operator);
        
        if( !strncmp(operator, "insert", sizeof("insert") ))
        {
            scanf("%d", &operand);
            insert(&head, &tail, operand);
        }
        else if(!strncmp(operator, "delete", sizeof("delete") ))
        {
            scanf("%d", &operand);
            delete(&head, &tail, operand);
        }
        else if(!strncmp(operator, "deleteFirst", sizeof("deleteFirst") ))
        {
            deleteFirst(&head, &tail);
        }
        else if(!strncmp(operator, "deleteLast", sizeof("deleteLast") ))
        {
            deleteLast(&head, &tail);
        }
    }
    
    while(head != NULL){
        printf("%d", head->value);
        if(head->next != NULL){
            printf(" ");
        }
        head = head->next;
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 31784