Problem F
Reverse Prime

Input: Standard Input

Output: Standard Output

 

There are a few 7 digit positive numbers whose reverse number is a prime number and less than 10^6.  For example: 1000070, 1000090 and 1000240 are first few reverse prime numbers because all of the numbers are 7 digit numbers whose reverse number is a prime number and less than 10^6. You have to find out all the 7 digit reverse prime numbers and also it’s number of prime factors. Prime factors of a positive integer are the prime numbers that divide into that integer exactly, without leaving a remainder. For example, prime factors of 24 are 2, 2, 2 and 3.

 

In this problem, you’ll encounter 2 types of input –

 

Query:

This type of input will be formatted like this – “q i. For this input, you have to calculate the cumulative summation of the number of prime factors of reverse prime numbers from 0-th to i-th index.

 

Deletion:

This type of input will be formatted like this – “d reverse_prime. For this input, you have to delete reverse_prime from the set and update your summation. No output is required in such cases.

 

It is guaranteed that i will be a valid index and reverse_prime will be a valid 7 digit reverse prime number. It is also guaranteed that no two reverse_prime will be same.

 

There will be at most 71000 query lines and 3500 deletion lines in the data set. The program will terminated by EOF.

 

 

Sample Input                                                                               Output for Sample Input

q 0

q 1

q 2

d 1000070

d 1000090

q 0

d 1000240

q 0

q 1

4

10

16

6

3

7

 

 

 

 

Problem Setter: Mohiul Alam Prince

Special Thanks: Sabbir Yousuf Sanny