A plane can go from city X to city Y in 1 hour and 20 minutes. However, when it returns from city Y to city X, with the same speed, it spends only 80 minutes! If you don’t know how might that happen, just remember that 1 hour and 20 minutes is the same as 80 minutes ;-) In this problem you will have 2 durations of time and you have to decide if they are equal or not.
The first line will be the number of test cases T. Each test case has two lines, the first line represents the first duration and contains 3 integers: h, m, s; these are the Hours, Minutes and Seconds. The second line represent the second duration with 3 integers also, in the same way. All integers are positive and below 5000.
For each test case, print one line which contains the number of the test case. Then print “Yes” if the 2 durations are equal and print “No” otherwise, see the samples and follow the output format.
3
1 20 0
0 80 0
0 2 10
0 0 130
2 10 5
2 11 0
Case 1: Yes
Case 2: Yes
Case 3: No
Khaled was sitting in the garden under an apple tree, suddenly! , well... you should guess what happened, an apple fell on his head! , so he came up with a new Cryptography method!!
The method deals only with numbers, so... If you want to encode a number, you must represent each of its digits with a set of strings, then the size of the set is the digit itself, No set should contain the same string more than once.
For example: the number 42, can be represented with the following two sets:
1) "dog" "load" "under" "nice".
2) "stack" "dog".
The first set contain four strings so it represent the digit 4.
The second set contain two strings so it represent the digit 2.
Given N strings, what is the smallest number you can get from dividing these strings into non-empty sets, and then decode the result by Khaled's Cryptography method? , You must use all the given strings, and no set should contain the same string more than once.
The input consists of several test cases, each test case starts with 0 < N ≤ 10000, the number of the given strings, then follows N space-separated string, each string will contain only lower-case English letters, and the length of each string will not exceeded 100.
You can assume that there are no more than nine distinct strings among the given strings.
A line containing the number 0 defines the end of the input you should not process this line.
For each test case print a single line in the following format: "Case c: x" where c is the test case number starting from 1 and x is the solution to the described problem above.
3 one two two
7 num go book go hand num num
25 aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
0
Case 1: 12
Case 2: 124
Case 3: 1111111111111111111111111
In the first sample, we divided the given strings into two sets, the first set contains two word: "one" and "two" so it represents the digit 2, the second set contains only one word: "two" so it represent the digit 1.
Optical Character Recognition (OCR) is one of the most famous fields of Artificial Intelligence. The main purpose of OCR is to recognize printed text (or handwriting) and convert it to the machine encoded-text. You may have seen similar applications in your smartphone: you use your camera to take a photo that contains text, then, the text is translated or saved in PDF, for example. In this problem we deal with a very limited case of OCR. You have a scanned character which is either ‘0’ (number zero) or ‘8’ (number eight) and you have to decide what number it is. The input will be an image that contains exactly one character (It is guaranteed that this character is either ‘0’ or ‘8’). The image has 2 colors: white (represented with dot ‘.’) and black (represented with asterisk ‘*’). For simplicity, the borders of the image are always white. It’s also guaranteed that black lines inside the image are either vertical or horizontal. So you may safely assume that the shapes of ‘0’ and ‘8’ inside the image are the same as their shapes in digital clocks. However, they might be stretched or not positioned in the center of the image.
The first line will be the number of test cases T (T<100). Each test case starts with two positive integers (n,m) denoting the dimensions of the image. (n,m < 20). Each of the following n lines contains m values which represent the image.
For each test case, print one line which contains the number of the test case, and the recognition result: ‘Zero’ or ‘Eight’. See the samples and follow the output format.
3
8 10
..........
..*****...
..*...*...
..*...*...
..*****...
..*...*...
..*****...
..........
6 10
..........
..*****...
..*...*...
..*...*...
..*****...
..........
10 7
.......
.......
.......
.......
..****.
..*..*.
..****.
..*..*.
..****.
.......
Case 1: Eight
Case 2: Zero
Case 3: Eight
Ameer is an upcoming and pretty talented problem solver who loves to solve problems using computers. Lately, He bought a very very very large square carpet that has an enormous area, so he stopped amazed as to how large is this carpet exactly… Unfortunately, Ameer has a small length measurement tool, so he can’t measure the area of the carpet as a whole. However, Ameer has a very smart algorithm for folding a square piece of paper reducing it to an exact fraction of its original size, and then he came up with another intelligent algorithm for measuring the area of the carpet. Ameer decided to fold the carpet N times, each time reducing it to 1/K of its remaining area, After that he would measure the remaining area of the carpet and apply his algorithm to calculate the original area. As Ameer is still a beginner problem solver he wants to check whether his algorithm is correct. Also, since the final answer might be incredibly large, Ameer wants to check the remainder of the answer over several prime numbers of his choosing. Can you help Ameer getting the correct answer so that he can compare it with his own ?
For each test case, you would be given three space separated integers on the first line N, K and A respectively, Where N and K are as described earlier and A is the area that Ameer has measured after folding the carpet N times. In the second line there will be an integer number C. The third line contains C integer prime numbers where the i-th number is called Pi. After the last test case, there will be a line containing three zeroes separated by a single space. 1 ≤ N, K, A ≤ 231 1 ≤ C ≤ 100 2 ≤ Pi < 231
For each test case you should output on the first line “Case c:” where ‘c’ is the case number, then one line containing ‘C’ space separated integers on a line where the i-th integer is the remainder of the original area over Pi
3 3 6
3
41 71 73
0 0 0
Case 1:
39 20 16
In the secret book of ACM, it’s said: “Glory for those who write short ICPC problems. May they live long, and never get Wrong Answers” . Everyone likes problems with short statements. Right? Let’s have five positive numbers: X1,X2,X3,X4,X5. We can form 10 distinct pairs of these five numbers. Given the sum of each one of the pairs, you are asked to find out the original five numbers.
The first line will be the number of test cases T. Each test case is described in one line which contains 10 numbers, these are the sum of the two numbers in each pair. Notice that the input has no particular order, for example: the first number doesn’t have to be equal to {X1+ X2}. All numbers are positive integers below 100,000,000.
For each test case, print one line which contains the number of the test case, and the five numbers X1,X2,X3,X4,X5 in ascending order, see the samples and follow the output format. There always exists a unique solution.
2
15 9 7 15 6 12 13 16 21 14
12 18 13 10 17 20 21 15 16 14
Case 1: 2 4 5 10 11
Case 2: 4 6 8 9 12
The ACM team is working on an AI project called (Eih Eye Three) that allows computers to write poems. One of the problems they stumbled upon is finding words with the same suffix. The ACM team constructed a dictionary of words, They are interested only in the longest common suffix, That is, a suffix common to three or more words in the dictionary… A suffix is any substring that starts from some arbitrary position in the string and reaches the end of the string. As the ACM team was also preparing for the ACM-TCPC2015 contest, they figured that the contestants can help in solving this problem. Your task is to write a program that finds a longest common suffix in a dictionary of words. An entry in the dictionary is a word of English letters only. Small letters are the same as capital letters. You can assume that there is exactly one unique solution for every test case.
The first line of the input contains an integer T, the number of test cases. Each test case starts with a line containing one integer K, then K lines follow, each containing one string “Si” that represents an entry in the dictionary. 0 < T ≤ 50 |Si| ≤ 100 0 < K ≤ 1000
For each test case, print on the first line “Case c:” where ‘c’ is the test case number. On the second line you should print an integer denoting the length of the longest common suffix and another integer denoting how many words have the suffix appeared in.
2
4
cocochannel
chrisschannel
MBCchannel
controlpanel
5
superman
batman
ironman
chrissbrown
MyCrown
Case 1:
7 3
Case 2:
3 3
Feras bought to his nephew Saleem a new game to help him learning calculating. The game consists of a board with 4 rows and 4 columns with 16 cubes. Every cube has a number from 1 to 16. Let's define the power of a column as the sum of its elements. In the same way, the power of a row is the sum of its elements. Saleem should arrange the cubes in the board such that the power of all columns and all rows are equal. To make the game easier, the nice uncle, Feras, will help him arranging 7 cubes, and Saleem should arrange the rest of the cubes.
Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100). Then the test cases. Each test case has four lines containing four integers. The j-th number in the i-th line describes the cell (i,j) of the board. If the number is -1 then the cell is empty and you have to fill it, otherwise, uncle Feras has already filled this cell.
For each test case print a line in the following format: "Case c:" where c is the test case number starting from 1 then print the board in four lines every line has four numbers separated by space. If there is more than one solution print the solution that has the smallest order (See the notes below).
1
-1 -1 -1 -1
-1 -1 -1 -1
-1 5 13 12
3 8 9 14
Case 1:
11 6 10 7
16 15 2 1
4 5 13 12
3 8 9 14
in the sample input there is more than one solution:
Solution1:
16 15 2 1
11 6 10 7
4 5 13 12
3 8 9 14
Solution2:
11 6 10 7
16 15 2 1
4 5 13 12
3 8 9 14
but we select solution2 because it has the smallest order when we write the rows in one line.
Solution1: 16 15 2 1 11 6 10 7 4 5 13 12 3 8 9 14
Solution2: 11 6 10 7 16 15 2 1 4 5 13 12 3 8 9 14
Feras, our beloved chef judge, bought a brand new iPhone 6 plus. he put some music on and went for a ride. Unfortunately when he got back, he found out that his new smart phone has bent !! He was furious, luckily he -like all chef judges- was a rich investor, he decided to make his own phone, he called his friends in HMK faculties, bought a factory and created some identical prototypes.
Feras, as a software engineer, knows very well the importance of testing new products, as well as his own only rule “never trust a HMK student with your money” decided to put those prototypes into real life test.
He bought a device to carry out the most important test of all tests, aka “The Bend Test”.
this device has exactly m pressure values to apply on the poor phone, 1,2,…,m. obviously if the phone bends, you cannot test it again. Also if the phone bends for a pressure value x, it will also bend for a any pressure value ≥ x. you can assume that the prototypes are identical ( which means they will bend for the same pressure values).
the ultimate goal of this problem is , given m and p (the number of prototypes), to help Feras know the minimum number of tests (in the worst case) he needs to carry out, in order to know the lowest pressure value on which the new phone will bend.
for example if m=100 and he has one prototype (p=1) then ,in the worst case, he needs 100 tests. trying the pressure values from 1 to 100 in sequence. However, in the case where he has 2 prototypes (p=2, m=100 still) and tried the first for a pressure value x, if it bends then he is in the case where he has one prototype remaining and he has to test it for values from 1 to x-1 in sequence, yielding x tests in total in the worst case (the first prototypes tested once,the second at most x-1). However, if the first prototype does not beak when tested for value x, he reduced the problem to test pressure values from x+1 to 100 (we must keep in mind that he used one test). in result the minimum number of tests, in the worst case, is the minimum over all x.
The first line of input contains a single integer C, ( 1 ≤ C ≤ 1000), which is the number of test cases.The following lines of input represent the test cases. Each test case consist of a single line containing two integers: P the number of prototypes ( 1 ≤ P ≤ 50 ), followed by a space, followed by M (1 ≤ M ≤ 1000).
For each test case print on line of output in the following format: "Case c: v" where c is an integer represent the test case number and v is the minimum number of tests needed in the worst case.
4
2 10
2 100
2 300
25 900
Case 1: 4
Case 2: 14
Case 3: 24
Case 4: 10
Saleem is a farmer. He has orange trees in his farm. The orange trees need a lot of water but this year there is not enough rain falls. Fortunately there is a well, but not all of this well is inside his farm. Saleem wants to make a deal with his neighbors. Everyone can take one gallon of water for every square meter of the well area inside his farm. you should help Saleem to know how many gallon of water he can take. If you know that:
- The farm is rectangle.
- The well is circle.
- The upper-left corner of his farm is inside the well.
- The width and the height of the farm are bigger than Diameter (2R) of the well.
Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 10000). Followed by the test cases, each test case is on two lines. the first line consists of three integers -1000 ≤ Xc,Yc,R ≤ 1000 where (Xc,Yc) is the center of well and R is the radius. the second line consists of four integers -1000 ≤ Xb,Yb,Xu,Yu ≤ 1000 where (Xb,Yb) is the bottom-left corner and (Xu,Yu) is the upper-right corner.
For each test case print a line is the following format: "Case c: x" where c is the test case number starting from 1 and x is the amount of water rounded to 5 decimal places.
1
0 0 2
0 -5 5 0
Case 1: 3.14159
“Weird Mazes” are defined as the following:
* The maze has rectangular shape, it has N rows and M columns of rooms.
* The rows are numbered from 1 to N top to down, the columns are numbered from 1 to M left to right.
* Each room is connected to at most 6 other rooms, through magical doors, these room are not necessarily the usual top, down, left, or right room.
* To move from room Rx1, y1 ,"row x1 and column y1", to room Rx2, y2, it costs an amount of money C ( 0 < C ≤ 1000 ). In addition, when you move from one room to another you spend T years, where ( - 100 ≤ T ≤ + 100 ), that means: if T is positive, then you are travelling to the future. If T is negative, then you are travelling to the past!
A friend of yours, Tareq, is at room Rx, y, it’s now the year 0. Tareq wants to travel to the room Ra, b, and arrive there exactly in year w, another big problem is: during the trip, the absolute value of time can never exceed 100, In other words: Tareq should always stay in the [-100, +100] time range, because if he didn't, he will be lost in the maze for ever !!
Can you help Tareq to know the minimum cost of money for him trip?
The first line will be the number of test cases Tc. Each test case starts with four integers in a single line: 0 < N ≤ 100, the number of rows in the maze, 0 < M ≤ 100, the number of columns, 0 < x ≤ N , 0 < y ≤ M , the initial position of Tareq meaning that he is in room Rx, y, (Remember he starts at year 0). The second line contains an integer p, the number of connections between rooms in the maze. Then p lines follow, each describe a connection and contains six integers: 0 < x1 ≤ N , 0 < y1 ≤ M , 0 < x2 ≤ N , 0 < y2 ≤ M , 0 < C ≤ 1000 , - 100 ≤ T ≤ + 100 , Which means that there is a one way connection from room Rx1, y1 , to room Rx2, y2 , with cost C of money and T of time. Follows a line containing one integer q, the numbers of queries, each query consists of three integers: 0 < a ≤ N , 0 < b ≤ M , - 100 ≤ w ≤ 100 , which means: what is the minimum cost of money that Tareq has to pay in order to reach room Ra, b at year w? Starting from the initial position Rx, y.
For each test case, you should print "Case c:" without quotes where c is the number of the test case starting from 1, then for each query you should print one integer on a separated line, the solution to the query. If it is impossible to achieve, just print the word "No" without quotes, see the sample output for more details.
3
2 2 1 1
1
1 1 2 2 5 1
1
2 2 1
3 6 1 1
5
1 1 2 5 1 -5
2 5 1 2 1 -7
1 1 1 2 1 5
1 1 1 3 1 3
1 2 1 3 1 8
4
1 1 0
1 2 5
1 3 13
1 3 3
2 2 1 1
4 1
1 2 2 1 5
2 2 1 1 2 5
1 1 2 2 3 -5
2 2 1 1 4 -5
1
2 2 17
Case 1:
5
Case 2:
0
1
2
1
Case 3:
No