B - Get Min 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

中に何も入っていない袋があります。

Q 個のクエリが与えられるので、これらのクエリを順に処理したときのタイプ 2 の各クエリの答えを出力してください。

各クエリは、以下のいずれかの形式です。

  • タイプ 1 : 1 x の形式で入力として与えられる。整数 x が書かれたボールを 1 つ袋の中に入れる。

  • タイプ 2 : 2 の形式で入力として与えられる。袋に入っているボールのうち書かれている整数が最小のものを 1 つ取り出し、その整数を答えとする。ただし、袋の中にボールが入っていないときにはこのクエリは与えられない。

制約

  • 2 \leq Q \leq 100
  • タイプ 1 のクエリにおいて、1 \leq x \leq 100
  • タイプ 2 のクエリが与えられたとき、袋は空ではない
  • タイプ 2 のクエリが 1 つ以上与えられる
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

Q 
\text{query}_1
\text{query}_2
\ldots
\text{query}_Q

ただし、\text{query}_ii 番目のクエリであり、以下のいずれかの形式で与えられる。

1 x
2

出力

タイプ 2 のクエリの個数を q として、q 行出力せよ。

i 行目には、i 番目のタイプ 2 のクエリの答えを出力せよ。


入力例 1

5
1 6
1 7
2
1 1
2

出力例 1

6
1

はじめ、袋の中にボールは入っていません。

1 番目のクエリでは、袋の中に 6 が書かれたボールを入れます。

2 番目のクエリでは、袋の中に 7 が書かれたボールを入れます。

3 番目のクエリでは、袋の中には 6 が書かれたボールと 7 が書かれたボールが入っているため、6 が書かれたボールを取り出します。このクエリの答えは 6 となります。

4 番目のクエリでは、袋の中に 1 が書かれたボールを入れます。

5 番目のクエリでは、袋の中には 1 が書かれたボールと 7 が書かれたボールが入っているため、1 が書かれたボールを取り出します。このクエリの答えは 1 となります。


入力例 2

8
1 5
1 1
1 1
1 9
2
2
1 2
2

出力例 2

1
1
2

同じ整数が書かれたボールを複数個袋の中に入れることもあります。

Score : 200 points

Problem Statement

There is an empty bag.

You are given Q queries. Process these queries in order and output the answer to each type-2 query.

Each query is of one of the following types.

  • Type 1: Given as input in the format 1 x. Put a ball with the integer x written on it into the bag.

  • Type 2: Given as input in the format 2. Pick out one ball with the minimum integer written on it from the balls in the bag, and report that integer as the answer. This query is not given when the bag contains no balls.

Constraints

  • 2 \leq Q \leq 100
  • In a type-1 query, 1 \leq x \leq 100.
  • When a type-2 query is given, the bag is not empty.
  • At least one type-2 query is given.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

Q 
\text{query}_1
\text{query}_2
\ldots
\text{query}_Q

Here, \text{query}_i is the i-th query and is given in one of the following formats:

1 x
2

Output

Let q be the number of type-2 queries, and output q lines.

The i-th line should contain the answer to the i-th type-2 query.


Sample Input 1

5
1 6
1 7
2
1 1
2

Sample Output 1

6
1

Initially, the bag contains no balls.

The 1st query puts a ball with 6 written on it into the bag.

The 2nd query puts a ball with 7 written on it into the bag.

In the 3rd query, the bag contains a ball with 6 written on it and a ball with 7 written on it, so you pick out the ball with 6 written on it. The answer to this query is 6.

The 4th query puts a ball with 1 written on it into the bag.

In the 5th query, the bag contains a ball with 1 written on it and a ball with 7 written on it, so you pick out the ball with 1 written on it. The answer to this query is 1.


Sample Input 2

8
1 5
1 1
1 1
1 9
2
2
1 2
2

Sample Output 2

1
1
2

The bag may contain multiple balls with the same integer.