# Problem : Urns and Probability

If an urn contains 4 colored balls, composed of 3 blue balls and 1 red ball, and 2 balls were taken at random, it can be seen that the probability of taking two blue balls, P(BB) = (3/4)x(2/3) = 1/2.

Next to such arrangement with 50% Probability of getting 2 blue balls at random occurs when the urn has 21 total balls with 15 blue and 6 red balls [(15/21) x (14/20)].

Given an arbitrary probability (p) and an integer N, find the number of urns with a total number of balls <= N such that there is a composition of blue and red balls such that the probability of drawing two blue balls is equal to p.**Input Format:**

The input consists of an integer N followed by a value p in a single line.**Output Format:**

The output is a single integer value giving the number of urns with total number of balls <= N, such that there is a composition

of blue and red balls, such that the probability of drawing two blue balls is equal to p.**Constraints:**

2 < N ≤ 20000

0 < p ≤ 1**Example 1**

Input

500 0.5

Output

3**Explanation**

With N=500, these are the possible combinations

Total number of balls = 4, number of blue balls = 3

Total number of balls = 21, number of blue balls = 15

Total number of balls = 120, number of blue balls = 85**Example 2**

Input

100 0.5

Output

2**Explanation**

With N=100, these are the possible combinations

Total number of balls = 4, number of blue balls = 3

Total number of balls = 21, number of blue balls = 15

# Problem : Robbery

Sam is a robber. He decides to rob a diamond from a museum. There are 4 levels of security.

First level:- At museum gate. Security Guards work in shifts of 1 hour. After which, another security guard comes in (after a gap of 5 minutes) and works again for 1 hour and so on.

Time taken to go from first level to second level is 2 minutes.

Second level:- At Museum door. One security guard works for 2 hours. After that, another security guard comes in (after a gap of 5 minutes) and works again for 2 hours and so on.

Time taken to go from second level to third level is 2 minutes.

Third level:- CCTV Surveillance. The robber can hack CCTV surveillance. Hacking process takes 60 minutes.

Time taken to go from third level to fourth level is 2 minutes.

Fourth level:- Laser Surveillance . The robber can hack laser surveillance. Hacking process takes 10 minutes.

Time taken to go from fourth level to museum treasury is 2 minutes.

He needs the same time to come out, and needs to hack in the system (or use his key) both ways**Sam the hacker wants to know whether he will be caught or not. The heist has following constraints:**

1) The hacker can hack the Electronic Surveillances maximum of 3 times. He also has a key, which he can use just once to

bypass one Electronic Surveillance and pass from one level to another level easily with no need for hacking.

2) The security guards start their shift at 12:00 A.M. The robbery can be successful only if Sam can get out of the museum on

the same day. If the Sam crosses 23:59 P.M, he will be caught.

3) Sam is very superstitious, and only enters or leaves the museum at times whose minutes are multiples of 5.

4) The time zone is in 24 Hour format.

Calculate minimum time taken by Sam, to get inside, take the diamond, and safely get out without getting caught.**Input Format:**

Time of arrival of the robber at the museum in 24 hour format**Output Format:**

Total time in minutes for the robbery to be completed

Time at which the robber leaves the museum if the robbery is successful else “ROBBER CAUGHT”**Constraints:****Example 1**

Input

03:30**Output**

305

08:35**Explanation**

Total Time taken for the Robbery is 305 Minutes. The time at which the robber will move out of Museum is 08:35. Time taken

by Sam to move from level 1 to level 2 = 42 minutes, similarly to move from level 2 to 3 and 3 to 4 and getting out back safely

he will take 263 minutes, thus total of 305 minutes.

# Problem : Identify bases in which a given number representation is prime

We are familiar with base 10 (also called decimal) representation of numbers. For example, 234 is 2 x 100 + 3 x 10 + 4.

Numbers can be represented in any base, B. Here, any number is expressed as n 1 , n 2 ,…. n k representing the value n k + B n k-1 +…. + n 1 B k-1 . Note than all 0 ≤ n i < B

The number 10 in decimal representation has value 2 in base 2 representation and value 3 in base 3 representation. Both 2 and 3 are primes even though the decimal representation has a value that is not prime.

Given a representation α β where α, β can be 0, 1, 2,…9, A, B,… Z, where A has value 10, B has value 11, and so on up to Z has value 36 (in decimal), we need to find all bases (in the range 2 to 36) in which α, β is a prime number. For example, 2J in base 20 is 2 x 20 + 19 = 59, a prime number.**Input Format:**

T an integer indicating the number of test cases

T lines each containing a string of length 2; characters in the string would be from the set 0, 1, 2, …9, A, B, …, Z**Output Format:**

Output

T lines each line containing a space separated list of numbers (in the range 2-36) in which the given string has prime value or

NONE if no such base exists.**Constraints:**

None**Example 1****Input**

1

A0**Output**

NONE**Explanation**

The string A0 is not a valid representation in the bases 2 to 10. In bases from 11 to 36, its value is 10 times the base, and is

not a prime. Hence NONE is the output.**Example 2****Input**

1

2J**Output**

20 21 24 26 27 30 32 35