And again the sum... (Easy)
Implement a data structure that manages a set S of integers, supporting the following operations:
add(i) - Add the integer i to the set S. If i is already in the set, no changes are made.
sum(l, r) - Calculate and output the sum of all elements x in S that satisfy the condition l ≤ x ≤ r.
Input
Initially, the set S is empty. The first line of the input contains n, the number of operations (1 ≤ n ≤ 100). The following n lines describe the operations. Each operation is either "+ i" or "? l r". The operation "? l r" corresponds to the query sum(l, r).
If a "+ i" operation appears at the start of the input or immediately after another "+" operation, it corresponds to add(i). However, if it follows a "?" query, and the result of that query was y, then the operation add((i + y) mod 10^9) is executed.
All parameters in the queries and addition operations range from 0 to 10^9.
Output
For each query, output a single number, which is the result of the query.