Next#686

Next

1 second
128 megabytes
Very easy

Implement a data structure that supports a set of integers, with which it is allowed to perform the following operations:

Input

The set is initially empty. The first line contains the number of operations (1 \leq n \leq 300\ 000). The next lines contain the operations. Each operation has a type either "+ " or "? ". The operation "? " gives the query next().

If the operation "+ " is executed at the start or after another operation +, it specifies the operation add(). If the operation goes after the query ? with result , then the operation add((i+y) \bmod 10^9) is executed.

In all queries and add operations, the parameters lie in the range from to 10^9.

Output

For each query, print one number—the answer to it.

Examples

Example 1

Loading
Loading