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 x — put the element with value x in the heap;  getMin x — the value of the minimum element contained in the heap was equal to x;  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.


-----Input-----

The first line of the input contains the only integer n (1 ≤ n ≤ 100 000) — the number of the records left in Petya's journal.

Each of the following n 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 10^9 by their absolute value.


-----Output-----

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

Next m 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 10^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 1 000 000 operations.


-----Examples-----
Input
2
insert 3
getMin 4

Output
4
insert 3
removeMin
insert 4
getMin 4

Input
4
insert 1
insert 1
removeMin
getMin 2

Output
6
insert 1
insert 1
removeMin
removeMin
insert 2
getMin 2



-----Note-----

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

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

Difficulty: interview

Starter code:

Solutions:
from heapq import *
n=int(input())
q,ans,k=[],[],0
for i in range(n):
    ss=input()
    if ss!="removeMin": 
        s,mm=ss.split(); m=int(mm)
        if s=='insert':
            k+=1
            heappush(q,m)
        else:
            while k==0 or q[0]!=m:
                if k==0:
                    heappush(q,m)
                    ans+=['insert '+mm]
                    k+=1
                elif q[0]<m: 
                    k-=1
                    t=heappop(q)
                    ans+=['removeMin']
                else: 
                    k+=1
                    heappush(q,m)
                    ans+=['insert '+mm]
    else: 
        if k==0:
            ans+=['insert 1']
        else: 
            heappop(q)
            k-=1
    ans+=[ss]
print(len(ans))
print('\n'.join(ans))

from heapq import *

n = int(input())
heap = []
ops = []
for i in range(n):
    ln = input().rstrip()
    #print(">", ln, "<=>", heap)
    if ln[0] == 'i': # insert X
        X = int(ln.split()[1])
        heappush(heap, X)
        ops.append(ln)
        continue
    if ln[0] == 'g': # getMin X
        X = int(ln.split()[1])
        while heap and heap[0] < X:
            heappop(heap)
            ops.append("removeMin")
        if not heap or heap[0] > X:
            ops.append("insert " + str(X))
            heappush(heap, X)
        #else: heappop(heap)
        ops.append(ln)
        continue

    # removeMin
    if not heap:
        ops.append("insert 1")
    else: heappop(heap)
    ops.append(ln)
print(len(ops))
print("\n".join(ops))


import heapq

n = int(input())
m = n
operations = []
heap = []
for i in range(n):
    s = input() 
    a = s.split()
    if a[0] == 'insert':
        heapq.heappush(heap, int(a[1])) 
    elif a[0] == 'removeMin':
        if heap:
            heapq.heappop(heap)
        else:
            m += 1
            operations.append('insert 1')
    elif a[0] == 'getMin':
        b = int(a[1])
        while heap:
            if heap[0] < b:
                operations.append('removeMin')
                m += 1
                heapq.heappop(heap)
            else:
                break
        else:
            operations.append('insert {}'.format(b))
            m += 1
            heapq.heappush(heap, b)
        if heap[0] > b:
            operations.append('insert {}'.format(b))
            m += 1
            heapq.heappush(heap, b)
    operations.append(s)

print(m)
print('\n'.join(operations))


from heapq import *

n = int(input())
heap = []
ops = []
for i in range(n):
    ln = input().rstrip()
    #print(">", ln, "<=>", heap)
    if ln[0] == 'i': # insert X
        X = int(ln.split()[1])
        heappush(heap, X)
        ops.append(ln)
        continue
    if ln[0] == 'g': # getMin X
        X = int(ln.split()[1])
        while heap and heap[0] < X:
            heappop(heap)
            ops.append("removeMin")
        if not heap or heap[0] > X:
            ops.append("insert " + str(X))
            heappush(heap, X)
        ops.append(ln)
        continue

    # removeMin
    if not heap:
        ops.append("insert 1")
    else: heappop(heap)
    ops.append(ln)
print(len(ops))
print("\n".join(ops))


import sys
from collections import defaultdict
from heapq import heappop,heappush

def main():
    n = int(sys.stdin.readline())
    h = []
    d = sys.stdin.readlines()
    res = []
    for i in range(n):
        x = d[i].split()
        if x[0]=="insert":
            t = int(x[1])
            heappush(h,t)
        elif x[0] == "getMin":
            t = int(x[1])
            while len(h)>0 and h[0]<t:
                res.append("removeMin")
                heappop(h)
                
            if len(h)==0 or h[0]>t:
                res.append("insert "+x[1])
                heappush(h,t)
            
        elif x[0] == "removeMin":
            if len(h)==0:
                res.append("insert 0")  
            else:
                heappop(h)              
                
        res.append(d[i].rstrip())

    print(len(res))
    print("\n".join(res))

main()


import heapq

n = int(input())
m = n
operations = []
heap = []
for i in range(n):
    s = input() 
    a = s.split()
    if a[0] == 'insert':
        heapq.heappush(heap, int(a[1])) 
    elif a[0] == 'removeMin':
        if heap:
            heapq.heappop(heap)
        else:
            m += 1
            operations.append('insert 1')
    elif a[0] == 'getMin':
        b = int(a[1])
        while heap:
            if heap[0] < b:
                operations.append('removeMin')
                m += 1
                heapq.heappop(heap)
            else:
                break
        else:
            operations.append('insert {}'.format(b))
            m += 1
            heapq.heappush(heap, b)
        if heap[0] > b:
            operations.append('insert {}'.format(b))
            m += 1
            heapq.heappush(heap, b)
    operations.append(s)

print(m)
print('\n'.join(operations))

import heapq

a = []
h = []
heapq.heapify(h)

for _ in range(int(input())):
    l = input()

    if l.startswith("insert"):
        heapq.heappush(h, int(l.split()[1]))

    elif l.startswith("getMin"):
        m = int(l.split()[1])
        while len(h) > 0 and h[0] != m:
            if h[0] < m:
                heapq.heappop(h)
                a.append("removeMin")
            else:
                heapq.heappush(h, m)
                a.append("insert " + str(m))
        if len(h) == 0:
            heapq.heappush(h, m)
            a.append("insert " + str(m))

    elif l.startswith("removeMin"):
        if len(h) == 0:
            a.append("insert 1")
        else:
            heapq.heappop(h)

    a.append(l)

print(len(a))
print("\n".join(a))

import sys
from heapq import *

answer = []
n = int(input())

def main():
    h = []

    all_input = sys.stdin.readlines()

    for q in all_input:
        raw = q.split()

        if raw[0] == "insert":
            v = int(raw[1])
            heappush(h, v)
        elif raw[0] == "getMin":
            v = int(raw[1])

            while h and h[0] < v:
                answer.append("removeMin\n")
                heappop(h)

            if not h or h[0] > v:
                answer.append("insert " + raw[1] + '\n')
                heappush(h, v)
        elif h:
            heappop(h)
        else:
            answer.append("insert 0\n")

        answer.append(q)

def print_answer():
    print(len(answer))
    print("".join(answer))

main()
print_answer()

from heapq import heappush , heappop

def main():

    heap = []
    ans = []
    n,hsize = int(input()),0

    for i in range(n):
        ss = input()
        if ss != "removeMin":
            a,bb = ss.split(); b = int(bb)

            if a == "insert":
                hsize += 1
                heappush(heap,b)
            else:
                while hsize > 0 and heap[0] < b:
                    ans += ['removeMin']
                    hsize -= 1
                    heappop(heap)
                if hsize == 0 or heap[0] != b:
                    ans += ['insert ' + bb]
                    heappush(heap,b)
                    hsize += 1

        else:
            if hsize == 0:
                ans += ['insert 0']
            else:
                heappop(heap)
                hsize -= 1
        ans += [ss]
    print(len(ans))
    print("\n".join(ans))






def __starting_point():
    main()
__starting_point()

from heapq import heappush , heappop

def main():

    heap = []
    ans = []
    n,hsize = int(input()),0

    for i in range(n):
        ss = input()
        if ss != "removeMin":
            a,bb = ss.split(); b = int(bb)

            if a == "insert":
                hsize += 1
                heappush(heap,b)
            else:
                while hsize > 0 and heap[0] < b:
                    ans.append('removeMin')
                    hsize -= 1
                    heappop(heap)
                if hsize == 0 or heap[0] != b:
                    ans.append('insert ' + bb)
                    heappush(heap,b)
                    hsize += 1

        else:
            if hsize == 0:
                ans.append('insert 0')
            else:
                heappop(heap)
                hsize -= 1
        ans.append(ss)
    print(len(ans))
    print("\n".join(ans))






def __starting_point():
    main()
__starting_point()

from heapq import heappush , heappop

def main():

    heap = []
    ans = []
    n,hsize = int(input()),0

    for i in range(n):
        ss = input()
        if ss != "removeMin":
            a,bb = ss.split(); b = int(bb)

            if a == "insert":
                hsize += 1
                heappush(heap,b)
            else:
                while hsize > 0 and heap[0] < b:
                    ans += ['removeMin']
                    hsize -= 1
                    heappop(heap)
                if hsize == 0 or heap[0] != b:
                    ans += ['insert ' + bb]
                    heappush(heap,b)
                    hsize += 1

        else:
            if hsize == 0:
                ans += ['insert 0']
            else:
                heappop(heap)
                hsize -= 1
        ans += [ss]
    print(len(ans))
    print("\n".join(ans))

main()

from heapq import heappush , heappop
import sys
inp = sys.stdin.readline

def main():

    heap = []
    ans = []
    n = int(inp())

    for i in range(n):
        ss = inp()
        if ss != "removeMin\n":
            a,bb = ss.split(); b = int(bb)

            if a == "insert":
                heappush(heap,b)
            else:
                while heap and heap[0] < b:
                    ans += ['removeMin\n']
                    heappop(heap)
                if not heap or heap[0] != b:
                    ans += ['insert %s\n'%bb]
                    heappush(heap,b)

        else:
            if not heap:
                ans += ['insert 0\n']
            else:
                heappop(heap)

        ans += [ss]

    print(len(ans))
    print("".join(ans))

main()

import sys

#@profile
def insert(heap, val):
    idx = len(heap)
    heap.append(val)

    while idx > 0:
        p = (idx - 1) >> 1

        if heap[p] <= heap[idx]: break

        heap[p], heap[idx] = heap[idx], heap[p]

        idx = p

#@profile
def removeMin(heap):
    last = heap.pop()

    L = len(heap)

    if L == 0: return
    heap[0] = last
    idx = 0
    while True:
        l = (idx << 1) + 1
        if l >= L: return

        r = l + 1
        best = r if r < L and heap[r] < heap[l] else l

        if heap[best] >= heap[idx]:
            return

        heap[best], heap[idx] = heap[idx], heap[best]

        idx = best

answer = []
n = int(input())

def main():
    h = []

    all_input = sys.stdin.readlines()

    for q in all_input:
        raw = q.split()

        if raw[0] == "insert":
            v = int(raw[1])
            insert(h, v)
        elif raw[0] == "getMin":
            v = int(raw[1])

            while h and h[0] < v:
                answer.append("removeMin\n")
                removeMin(h)

            if not h or h[0] > v:
                answer.append("insert " + raw[1] + '\n')
                insert(h, v)
        elif h:
            removeMin(h)
        else:
            answer.append("insert 0\n")

        answer.append(q)

def print_answer():
    print(len(answer))
    print("".join(answer))

main()
print_answer()

import sys
from heapq import *

answer = []
n = int(input())

def main():
    h = []

    all_input = sys.stdin.readlines()

    for q in all_input:
        raw = q.split()

        if raw[0] == "insert":
            v = int(raw[1])
            heappush(h, v)
        elif raw[0] == "getMin":
            v = int(raw[1])

            while h and h[0] < v:
                answer.append("removeMin\n")
                heappop(h)

            if not h or h[0] > v:
                answer.append("insert " + raw[1] + '\n')
                heappush(h, v)
        elif h:
            heappop(h)
        else:
            answer.append("insert 0\n")

        answer.append(q)

def print_answer():
    print(len(answer))
    print("".join(answer))

main()
print_answer()

from heapq import heappush, heappop

h = []
ans = []

def main():
	nonlocal h

	n = int(input())
	for i in range(n):
		s = input()
		if s[0] == 'i':
			data = int(s.split()[1])
			heappush(h, data)
			ans.append(s)
		elif s[0] == 'g':
			data = int(s.split()[1]) 
			while h and h[0] < data:
				heappop(h)
				ans.append('removeMin')
			if (not h) or (h[0] > data):
				heappush(h, data)
				ans.append('insert ' + str(data))
			ans.append(s)
		else:
			if not h:
				ans.append('insert 0')
			else:
				heappop(h)
			ans.append('removeMin')

	print(len(ans))
	print("\n".join(ans))


def __starting_point():
    main()
    

__starting_point()

from heapq import heappush , heappop
import sys
inp = sys.stdin.readline

def main():

    heap = []
    ans = []
    n = int(input())

    all = sys.stdin.readlines()
    for ss in all:
        if ss != "removeMin\n":
            a,bb = ss.split(); b = int(bb)

            if a == "insert":
                heappush(heap,b)
            else:
                while heap and heap[0] < b:
                    ans += ['removeMin\n']
                    heappop(heap)
                if not heap or heap[0] != b:
                    ans += ['insert %s\n'%bb]
                    heappush(heap,b)

        else:
            if not heap:
                ans += ['insert 0\n']
            else:
                heappop(heap)

        ans += [ss]

    print(len(ans))
    print("".join(ans))

def __starting_point():
    main()
__starting_point()

import heapq
n = int(input()); m = n; ans, hp_dgt = [], [] 
for i in range(n):
    s=input(); a=s.split()
    if a[0] == 'insert':
        heapq.heappush(hp_dgt, int(a[1])) 
    elif a[0] == 'removeMin':
        if hp_dgt:
            heapq.heappop(hp_dgt)
        else:
            m += 1; ans.append('insert 1')
    elif a[0] == 'getMin':
        x = int(a[1])
        while hp_dgt:
            if hp_dgt[0] < x:
                m += 1; ans.append('removeMin'); heapq.heappop(hp_dgt)
            else:
                break
        else:
            m += 1; ans.append('insert '+str(x)); heapq.heappush(hp_dgt, x)
        if hp_dgt[0] > x:
            m += 1; ans.append('insert '+str(x)); heapq.heappush(hp_dgt, x)
    ans.append(s)
print(m)
print('\n'.join(ans))


import heapq
n = int(input()); m = n; ans, hp_dgt = [], [] 
for i in range(n):
    s=input(); a=s.split()
    if a[0] == 'insert':
        heapq.heappush(hp_dgt, int(a[1])) 
    else:
        if a[0] == 'removeMin':
            if hp_dgt:
                heapq.heappop(hp_dgt)
            else:
                m += 1; ans.append('insert 1')
        else:
            x = int(a[1])
            while hp_dgt:
                if hp_dgt[0] < x:
                    m += 1; ans.append('removeMin'); heapq.heappop(hp_dgt)
                else:
                    break
            else:
                m += 1; ans.append('insert '+str(x)); heapq.heappush(hp_dgt, x)
            if hp_dgt[0] > x:
                m += 1; ans.append('insert '+str(x)); heapq.heappush(hp_dgt, x)
    ans.append(s)
print(m)
print('\n'.join(ans))


import sys
from heapq import *

answer = []
n = int(input())

def main():
    h = []

    all_input = sys.stdin.readlines()

    for q in all_input:
        raw = q.split()

        if raw[0] == "insert":
            v = int(raw[1])
            heappush(h, v)
        elif raw[0] == "getMin":
            v = int(raw[1])

            while h and h[0] < v:
                answer.append("removeMin\n")
                heappop(h)

            if not h or h[0] > v:
                answer.append("insert " + raw[1] + '\n')
                heappush(h, v)
        elif h:
            heappop(h)
        else:
            answer.append("insert 0\n")

        answer.append(q)

def print_answer():
    print(len(answer))
    print("".join(answer))

main()
print_answer()


from heapq import heappush, heappop

h = []
ans = []

def main():
	nonlocal h

	n = int(input())
	for i in range(n):
		s = input()
		if s[0] == 'i':
			data = int(s.split()[1])
			heappush(h, data)
			ans.append(s)
		elif s[0] == 'g':
			data = int(s.split()[1]) 
			while h and h[0] < data:
				heappop(h)
				ans.append('removeMin')
			if (not h) or (h[0] > data):
				heappush(h, data)
				ans.append('insert ' + str(data))
			ans.append(s)
		else:
			if not h:
				ans.append('insert 0')
			else:
				heappop(h)
			ans.append('removeMin')

	print(len(ans))
	print("\n".join(ans))


def __starting_point():
    main()
    


__starting_point()

def main():
    from heapq import heappop, heappush
    from sys import stdin
    h, res = [], []
    for _ in range(int(input())):
        s = input()
        if s == ("removeMin"):
            if h:
                heappop(h)
            else:
                res.append("insert 1")
        else:
            c, x = s.split()
            x = int(x)
            if c == "insert":
                heappush(h, x)
            else:
                while h and h[0] < x:
                    heappop(h)
                    res.append("removeMin")
                if not h or h[0] > x:
                    heappush(h, x)
                    res.append("insert %d" % x)
        res.append(s)
    print(len(res))
    print('\n'.join(res))


def __starting_point():
    main()

__starting_point()

def main():
    from heapq import heappop, heappush
    from sys import stdin
    _, *l = stdin.read().splitlines()
    h, res = [], []
    for s in l:
        if s == ("removeMin"):
            if h:
                heappop(h)
            else:
                res.append("insert 1")
        else:
            c, x = s.split()
            x = int(x)
            if c == "insert":
                heappush(h, x)
            else:
                while h and h[0] < x:
                    heappop(h)
                    res.append("removeMin")
                if not h or h[0] > x:
                    heappush(h, x)
                    res.append("insert %d" % x)
        res.append(s)
    print(len(res))
    print('\n'.join(res))


def __starting_point():
    main()

__starting_point()

from heapq import heappop, heappush
from sys import stdin
n, *l = stdin.read().splitlines()
heap, res = [], []
for s in l:
    array = s.split()
    if array[0] == 'insert':
        heappush(heap, int(array[1]))
    elif array[0] == 'getMin':
        key = int(array[1])
        while heap and heap[0] < key:
            heappop(heap)
            res.append('removeMin')
        if not heap or heap[0] != key:
            heappush(heap, key)
            res.append('insert ' + array[1])
    else:
        if heap:
            heappop(heap)
        else:
            res.append('insert 0')
    res.append(s)
print(len(res))
print('\n'.join(res))


from heapq import heappush, heappop
from sys import stdin
heap = []
L = []

n, *l = stdin.read().splitlines()
for string in l:
    array = string.split()
    if array[0] == 'insert':
        heappush(heap, int(array[1]))
    elif array[0] == 'getMin':
        key = int(array[1])
        while heap and heap[0] < key:
            heappop(heap)
            L.append('removeMin')
        if not heap or heap[0] > key:
            heappush(heap, key)
            L.append('insert ' + str(key))
    else:
        if heap:
            heappop(heap)
        else:
            L.append('insert 0')
    L.append(string)

print(len(L))
print('\n'.join(L))