#P9809. Minimum Remainder Query

    ID: 22955 Type: Default 1000ms 256MiB

Minimum Remainder Query

Minimum Remainder Query

You are given an initially empty set \( S \). You need to perform a total of \( N \) operations. There are two types of operations:

  • Operation 1: Insert a new element with value \( X \) into \( S \). It is guaranteed that \( X \) does not already exist in \( S \).
  • Operation 2: Given an integer \( Y \), query the set \( S \) and find the minimum value of \( x \bmod Y \) for all \( x \) in \( S \).

Note: It is guaranteed that for every query (Operation 2), the set \( S \) is non-empty.

inputFormat

The first line contains a single integer \( N \), the number of operations.

Each of the following \( N \) lines describes an operation in one of the following formats:

  • "1 X" — Operation 1: Insert an element with value \( X \) into \( S \).
  • "2 Y" — Operation 2: Query the minimum of \( x \bmod Y \) over all \( x \) in \( S \).

outputFormat

For each Operation 2, output one line containing a single integer which is the minimum remainder when each element in \( S \) is divided by \( Y \).

sample

4
1 5
1 3
2 4
2 3
1

0

</p>