#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_INPUT 100

typedef struct patient{
    int id;
    int priority;
    struct patient *next;
} patient;

patient *head = NULL;

void insert_patient(int id,int priority){
    patient *new_patient = (patient *)malloc(sizeof(patient));
    new_patient->id = id;
    new_patient->priority = priority;
    new_patient->next = NULL;
    
    if (!head || priority > head->priority){
        new_patient->next = head;
        head = new_patient;
    }else{
        patient *current = head;
        while (current->next && (current->next->priority > priority || 
        (current->next->priority == priority))) {
            current  = current->next;
        }
        new_patient->next = current->next;
        current->next = new_patient;
    }
}
void delete_patient(){
    if(!head) {
        printf("Queue is empty\n");
        return;
    }
    patient *temp = head;
    printf("%d\n",temp->id);
    head = head->next;
    free(temp);
}
int main() {
    int N;
    scanf("%d", &N);
    getchar();
    
    char operation[MAX_INPUT];
    for (int i=0;i<N;i++){
        fgets(operation, sizeof(operation),stdin);
        if (strncmp(operation, "INSERT", 6) == 0) {
            int id,priority;
            if (scanf(operation, "INSERT %d %d",&id, &priority) == 2) {
                insert_patient(id, priority);
            }else{
                printf("Invalid input\n");
                return 0;
            }
        }else if (strncmp(operation, "DELETE", 6) == 0)
    } else {
        printf("INvalid input\n");
        return 0;
    }
    return 0;
}