#P9809. [SHOI2006] 作业 Homework

[SHOI2006] 作业 Homework

Problem Description

You are given a set SS, which is initially empty. You need to perform the following two operations a total of NN times.

Operation 1: Add a new element to the set SS, with label XX. It is guaranteed that XX does not exist in the current set.

Operation 2: In the current set SS, query the minimum value of amodYa \bmod Y among all elements.

Input Format

The first line contains a positive integer NN.

The next NN lines each contain one character and one positive integer. If the character is A, this operation is Operation 1. If the character is B, this operation is Operation 2.

Output Format

For each Operation 2, output one line containing an integer representing the answer.

5
A 3
A 5
B 6
A 9
B 4
3
1

Hint

For 100%100\% of the testdata, N105N \leq 10^5, X,Y3×105X, Y \leq 3 \times 10^5. The testdata guarantees that the first operation is Operation 1.

Translated by ChatGPT 5