- محدودیت زمان: ۳ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
Jeff got bored in Semnan and decided to pass his time thinking about gcd. We define as the greatest common divisor of two natural numbers and . Jeff defines between two non empty lists , , ..., and , , ..., like this:
In other words, is the greatest gcd between one member of the -list and another member from -list. if one of the or is empty consider .
Sehri decides to make Jeff's life harder by inserting and deleting numbers in Jeff's lists times. more formally for each Sehri chooses one of lists or and a number , then decides to add to the chosen list or remove one of the occurrences of in the chosen list. After each of Sehri's attempts to make Jeff's life harder, Jeff wonders what is and since his life is hard enough already, he asks you to calculate for him. the lists , are empty at first. note that it is garanteed that Sehri will always remove an existing .
input
the first line consists 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 .
output
output should consist of Q number F(X, Y) after each of Sehri's attempts.
example
sample input 1
sample output 1
ارسال پاسخ برای این سؤال