CF681C.Heap Operations

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya has recently learned data structure named "Binary heap".

The heap he is now operating with allows the following operations:

  • put the given number into the heap;
  • get the value of the minimum element in the heap;
  • extract the minimum element from the heap;

Thus, at any moment of time the heap contains several integers (possibly none), some of them might be equal.

In order to better learn this data structure Petya took an empty heap and applied some operations above to it. Also, he carefully wrote down all the operations and their results to his event log, following the format:

  • insert xx — put the element with value xx in the heap;
  • getMin xx — the value of the minimum element contained in the heap was equal to xx ;
  • removeMin — the minimum element was extracted from the heap (only one instance, if there were many).

All the operations were correct, i.e. there was at least one element in the heap each time getMin or removeMin operations were applied.

While Petya was away for a lunch, his little brother Vova came to the room, took away some of the pages from Petya's log and used them to make paper boats.

Now Vova is worried, if he made Petya's sequence of operations inconsistent. For example, if one apply operations one-by-one in the order they are written in the event log, results of getMin operations might differ from the results recorded by Petya, and some of getMin or removeMin operations may be incorrect, as the heap is empty at the moment they are applied.

Now Vova wants to add some new operation records to the event log in order to make the resulting sequence of operations correct. That is, the result of each getMin operation is equal to the result in the record, and the heap is non-empty when getMin ad removeMin are applied. Vova wants to complete this as fast as possible, as the Petya may get back at any moment. He asks you to add the least possible number of operation records to the current log. Note that arbitrary number of operations may be added at the beginning, between any two other operations, or at the end of the log.

输入格式

The first line of the input contains the only integer nn ( 1<=n<=1000001<=n<=100000 ) — the number of the records left in Petya's journal.

Each of the following nn lines describe the records in the current log in the order they are applied. Format described in the statement is used. All numbers in the input are integers not exceeding 10910^{9} by their absolute value.

输出格式

The first line of the output should contain a single integer mm — the minimum possible number of records in the modified sequence of operations.

Next mm lines should contain the corrected sequence of records following the format of the input (described in the statement), one per line and in the order they are applied. All the numbers in the output should be integers not exceeding 10910^{9} by their absolute value.

Note that the input sequence of operations must be the subsequence of the output sequence.

It's guaranteed that there exists the correct answer consisting of no more than 10000001000000 operations.

输入输出样例

  • 输入#1

    2
    insert 3
    getMin 4
    

    输出#1

    4
    insert 3
    removeMin
    insert 4
    getMin 4
    
  • 输入#2

    4
    insert 1
    insert 1
    removeMin
    getMin 2
    

    输出#2

    6
    insert 1
    insert 1
    removeMin
    removeMin
    insert 2
    getMin 2
    

说明/提示

In the first sample, after number 33 is inserted into the heap, the minimum number is 33 . To make the result of the first getMin equal to 44 one should firstly remove number 33 from the heap and then add number 44 into the heap.

In the second sample case number 11 is inserted two times, so should be similarly removed twice.

首页