Bored


  • محدودیت زمان: ۳ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Jeff got bored in Semnan and decided to pass his time thinking about gcd. We define gcd(a,b)gcd(a, b) as the greatest common divisor of two natural numbers aa and bb. Jeff defines F(X,Y)F(X, Y) between two non empty lists X1X_1, X2X_2, ..., XnX_n and Y1Y_1, Y2Y_2, ..., YmY_m like this:

F(X,Y)=max(gcd(Xi,Yj))1in,1jm F(X, Y) = max(gcd(X_i, Y_j)) \quad 1 \leq i \leq n, 1 \leq j \leq m

In other words, F(X,Y)F(X, Y) is the greatest gcd between one member of the XX-list and another member from YY-list. if one of the XX or YY is empty consider F(X,Y)=1F(X, Y) = 1.

Sehri decides to make Jeff's life harder by inserting and deleting numbers in Jeff's lists QQ times. more formally for each 1iQ1 \le i \le QSehri chooses one of lists XX or YY and a number nin_i, then decides to add nin_i to the chosen list or remove one of the occurrences of nin_i in the chosen list. After each of Sehri's attempts to make Jeff's life harder, Jeff wonders what is F(X,Y)F(X, Y) and since his life is hard enough already, he asks you to calculate F(X,Y)F(X, Y) for him. the lists XX, YY are empty at first. note that it is garanteed that Sehri will always remove an existing nn.

input🔗

the first line consists QQ number of Sehri's attempts. for the next Q lines, i-th line consists of a character '+' or '-' to denote Sehri decided to insert or delete a number. then another character 'X' or 'Y' shows which list Sehri has chosen and then the number nin_i.

1Q100,0001 \le Q \le 100,000

1ni1000,0001 \le n_i \le 1000,000

output🔗

output should consist of Q number F(X, Y) after each of Sehri's attempts.

example🔗

sample input 1🔗

6
+ X 3
+ Y 1
+ Y 6
+ X 12
- Y 1
+ Y 12
Plain text

sample output 1🔗

1
1
3
6
6
12
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.