The 2018 World Cup will be hosted in Russia. 32 national teams will be divided into 8 groups. Each group consists of 4 teams. In group matches, each pair (unordered) of teams in the group will have a match. Top 2 teams with the highest score in each group will advance to eighth-finals. Winners of each eighth-final will advance to quarter-finals. Then, the winners of each quarter-final will advance to semi-finals. Eventually, the World Champion will be the winner of the World Final which is played between the two winners of the semi-finals.
Each match is labeled with a match ID sequenced from 1 to 63, with group matches followed by eighth-final matches followed by quarter-final matches followed by semi-finals matches and finally the final match.
Zhuojie is going to watch the 2018 World Cup. Since the World Champion of ACM-ICPC is very rich, he decides to spend 0.01% of his daily salary to buy tickets. However, there are only match IDs on the tickets and the prices are missing. Can you calculate how much Google pays Zhuojie every workday? Note that Zhuojie can buy multiple tickets for one match.
The input starts with one line containing exactly one integer T, the number of test cases.
Each test case contains 3 lines. The first line contains 5 integers, indicating the ticket price for group match, eighth-final match, quarter-final match, semi-final match and the final match. The second line contains one integer N, the number of tickets Zhuojie buys. The third line contains N integers, each indicating the match ID on the ticket.
.
. For each test case, output one line containing "Case #x: y" where x is the test case number (starting from 1) and y is daily salary of Zhuojie.
1
11 12 13 14 15
2
1 49
Case #1: 230000
Aori is very careless so she is always making troubles. One day she does it again, with N big troubles! But this time she seems to be at ease because she has found M Inklings to take all the blames. Each trouble can be measured by a severity number ai. Each trouble needs at least one Inkling to take the blame, and each Inkling can help Aori to take the blame for exactly one trouble. If two or more Inklings take the same trouble, they will take this blame together and discuss how to divide this trouble into.. some trivial things.. to reduce the pressure on each Inkling, as long as the total severity on Inklings is equal to the severity of this trouble.
Inklings are so warm so that Aori wants to think a way to let the variance of severity on each Inkling to be minimal. Could you help Aori make her scapegoats?
Formally, the variance of variables is the expectation of the squared deviation of a variable from its mean:

The first line of the input gives the number of test cases, T. T test cases follow.
For each test case, the first line contains two integers N and M, where N is the number of troubles, and M is the number of Inklings. The next line contains N integers a1, a2, ..., aN representing the severity of the troubles that Aori makes.
. For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the minimal variance.
y will be considered correct if it is within an absolute or relative error of 10 - 8 of the correct answer.
3
3 6
1 2 3
5 10
5 6 7 8 9
6 6
1 1 4 5 1 4
Case #1: 0.000000000000
Case #2: 0.400000000000
Case #3: 2.888888888889
For the first sample, Aori can let one Inkling to take the first trouble's blame, two Inklings for the second, and three Inklings for the third. The severity on each Inkling is 1 unit, so their variance should be 0.
One year ago, Mr. Ang joined a great company and he rented a house on the same street as the company. The company is so great that Mr. Ang doesn't need to punch in and out. He can have a good sleep and gets up at any time.
Every day, he walks along the street, goes through N traffic lights numbered 1, 2, 3, ..., N and arrives the company. It takes Mr. Ang S0 seconds from the house to first traffic light. Si seconds from traffic light i to traffic light i + 1 and SN seconds from Nth traffic light to company. The time spent on the way to company depends on the state of traffic lights.
Mr. Ang got interested in the traffic lights and hacked into the system. After reading the code, he found that for traffic light i on his way, it stays Ai seconds green and then stays Bi seconds red and repeats. He also found that for all traffic lights, Ai + Bi are the same. He can modify the code to set different offsets OFFi for the traffic lights. Formally, Mr. Ang can set the offsets for the traffic lights to OFFi so that for each traffic light, Mr. Ang can go through it in time range [OFFi + k × (Ai + Bi), OFFi + k × (Ai + Bi) + Ai) and must wait in time range [OFFi + k × (Ai + Bi) + Ai, OFFi + (k + 1) × (Ai + Bi)) for all integers k.
Now Mr. Ang would like to make his commuting time from house to company as short as possible in the worst case. Find out the minimal time in second.
The first line of the input gives the number of test cases, T. T test cases follow.
Each test case starts with a line which consists of one number N, indicating the number of traffic lights.
The next line consists of N + 1 numbers S0, S1, ..., SN indicating the walking time between house, traffic lights and company in seconds as described in the problem.
Then followed by N lines each consists of 2 numbers Ai, Bi indicating the length of green light and red light of the ith traffic light.
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the minimal time in second from house to company in the worst case.
y will be considered correct if it is within an absolute or relative error of 10 - 8 of the correct answer.
2
1
30 70
15 15
2
30 15 70
10 20
20 10
Case #1: 115.000000
Case #2: 135.000000
In the first test case, it takes Mr. Ang 30 seconds to the first traffic light, in the worst case he had to wait 15 seconds until it gets green. Then 70 seconds to the company. Total time is 30 + 15 + 70 = 115 seconds;
In the second test case, it still takes Mr. Ang 30 seconds to the first traffic light, as Mr. Ang could make OFF1 = 0, OFF2 = 25. If Mr. Ang meets red light at the first traffic light, he will definitely meet green light at the seconds one. So in the worst case, it takes Mr. And 30 + 20 + 15 + 0 + 70 = 135 seconds.
Mr. Panda likes playing with numbers. One day he picked up a number 3612 and found it's interesting. 3612 can be divided into 3 numbers 3, 6 and 12 which forms an integer geometric sequence.
An integer geometric sequence is a sequence of at least 3 positive integer numbers a0, a1, ..., an - 1, also there is a positive number D (D > 1) that for each i(0 ≤ i < n - 1), ai × D = ai + 1.
Mr. Panda named this kind of numbers "Happy Number". He also announced that leading zeros are forbidden, which means there should be no extra zeros before the numbers. Now Mr. Panda would like to know how many Happy Numbers are between L and R inclusive.
The first line of the input gives the number of test cases, T. T test cases follow. Each test case contains one line which consists of two numbers L and R.
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the number of Happy Numbers between L and R inclusive.
4
123 124
468 470
248 248
124816 124832
Case #1: 1
Case #2: 1
Case #3: 1
Case #4: 1
In the first test case, the only Happy Number between 123 and 124 is 124, in which 1 × 2 = 2 and 2 × 2 = 4.
In the second test case, the only Happy Number is 248.
In the third test case, the only Happy Number is 469, the common radio is
.
In the fourth test case, the only Happy number between 124816 and 124832 is 124816, in which 1 × 2 = 2, 2 × 2 = 4, 4 × 2 = 8 and 8 × 2 = 16.
Do you like puzzles, fruits and the notion of crossing a snake with a bird for no good reason? If the answer to at least one of those questions is yes, then Snakebird might be the game for you. Solve your way through this head-scratcher of a puzzle game and help the snakebirds sate their hunger.
The game starts with a board of M × N cells, at the beginning each cell is one of the following types.
On each move, you can select one of the snakebirds, and move it's head to one of the adjacent cells(four directions) to enter an empty/fruit cell. After each move, something magic is happening, your snakebirds are subject to gravity, which means all snakebirds without support start falling until they land on some obstacles(or other snakebirds with support) or dead. Falling on spike or falling out of the board causes dead. The shape of the snakebird doesn't change during the falling.
It's guaranteed that nothing is going to fall at the beginning.
To help Redbird, Greenbird and Bluebird win the game, you need to send all snakebirds to heaven alive. Find out the minimal number of moves needed.
The first line of the input gives the number of test cases, T. T test cases follow.
The first line of each test case contains 2 numbers M, N, the rows and columns of the board. The following M lines, each line contains N characters representing the board.
For each test case, output one line containing "Case #x: y" in the one line. x is the test case number (starting from 1) and y is the minimum moves needed to send all snakebirds to heaven. If it's impossible to do that, output -1 instead.
8
4 4
....
...v
X..G
##.#
4 4
....
...v
X..G
#..#
4 4
..X.
....
.R.@
####
4 7
.......
.......
>>B|..X
#######
4 7
.......
v......
>>B|..X
#######
4 5
>R...
##...
##.X.
##...
4 5
>R...
##...
##|X.
##...
9 11
.......X...
...........
....#......
...........
.#.........
.#.........
.#..#...B<<
....#..G<<^
.......####
Case #1: 3
Case #2: -1
Case #3: 6
Case #4: -1
Case #5: 6
Case #6: 2
Case #7: -1
Case #8: 46
In the first test case, the green snakebird can go to left and enter the exit.
In the second test case, as the gap is too big, it's impossible to enter the exit.
In the third test case, the red snakebird needs to go right to eat the fruit, then enter the exit.
In the forth test case, there is a spike in the middle, the snakebird of length 3 is not able to cross through.
In the fifth test case, the snakebird of length 4 is able to cross through.
In the sixth test case, the snakebird can just go right twice and jump to the exit.
In the seventh test case, the snakebird can also jump to the exit, but a spike kills it at the same time it reaches the exit.
The last sample looks like the picture below.
Given a positive integer M that consists of k digits in decimal notation without leading zeros, a 'digit rotation' of M means a number that is generated by swapping the first j digits and the rest (k - j) digits on M, for any j (0 ≤ j < k). For example, both 231 and 312 are digit rotations of 123, and neither 321 nor 132 is.
A positive integer G is a good number if any digit rotation of G does not exceed G.
Given a positive integer N, return the largest good number that does not exceed N.
The first line of the input gives the number of test cases, T. T test cases follow.
Each line contains an integer N which is represented in decimal notation.
. For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the largest good number that does not exceed N.
4
110
10010
45363
8394634
Case #1: 110
Case #2: 10000
Case #3: 44444
Case #4: 8383837
In the first sample case, 110 is a good number since all the digit rotations of it 101 and 011 are smaller than 110.
In the second sample case, 10010 itself is not a good number because one of the digit rotations 10100 is larger than 10010. 10001 to 10009 either, since 10001's rotation is 11000, 10009's rotation is 91000, similar for 10002 to 10008. Therefore, 10000 is the largest good number.
There are N binary images numbered from 0 to N - 1. Each image contains M pixels numbered from 0 to M - 1. Each pixel is either black or white. Images are pairwise different by at least one pixel.
Now there are some queries. Each query contains a subset of these images. For each query, you want to find a set of pixels that can distinguish every pair of images in it. Two images can be distinguished from each other by a given set of pixels if they have different pixel values in at least one of the given pixels. The number of pixels selected should be less than the number of images in each query.
The first line of the input gives the number of test cases, T. T test cases follow.
The first line of each test case consists of three integers N, M, and Q, indicating the number of images, the number of pixels in each image, and the number of queries. The following N lines describe the content of each image. Each line contains a 01 string of length M representing the content of the image. The following Q lines describe the queries. Each query starts with an integer Ki indicating the number of images of this query, then comes a list of space separated integers indicating the indices of the images.
.
. For each test case, output one line containing "Case #x:", where x is the test case number (starting from 1), then follows Q lines. Each line starts with an integer indicating the number of pixels needed to distinguish the images in the query, then comes a list of space separated integers indicating the indices of the pixels. There could be multiple answers to each query. You may output any of them as long as the number of pixels selected is less than Ki.
1
3 3 4
101
110
001
2 0 1
2 0 2
2 1 2
3 0 1 2
Case #1:
1 1
1 0
1 0
2 0 1
Mrs. Panda’s birthday is coming. Mr. Panda wants to compose a song as gift for her birthday.
It is known that Mrs. Panda does not like a song if and only if its lyrics contain X vowels in a row, or Y consonants in a row (Otherwise, Mrs. Panda likes the song). The letters 'a', 'e', 'i', 'o', 'u' are vowels, and all others are consonants.
Though Mr. Panda is a gifted singer, he is bad at composing lyrics. Mr. Panda wants the song to be special. Thus, he searched Google for a template for lyrics of the song.
The template consists of lowercase English letters and possibly question marks. For example, "happybirthday" (without quotes, the same below), "????ybirthday" are valid templates but neither "happy birthday" nor "HappyBirthday" is. Mr. Panda needs to substitute all the question marks with lowercase English letters so that it becomes actual lyrics of the song.
Mr. Panda wants to give a surprise to Mrs. Panda. So, Mr. Panda hopes to compose not only a song from the template that Mrs. Panda likes but also a song from the same template that Mrs. Panda dislikes.
Because Mr. Panda is really bad at composing lyrics, even with a template, the task has confused him for days. Luckily, Mr. Panda knows you are in the contest and wants to ask you for help.
For a given template, output either "DISLIKE" (without quotes, the same below) if Mrs. Panda dislikes all the songs that are generated from the template (that means you cannot substitute letters for question marks so that Mrs. Panda likes the song), "LIKE" if Mrs. Panda likes all the songs that are generated from the template, or "SURPRISE" if Mr. Panda can compose a song Mrs. Panda likes and another song Mrs. Panda dislikes.
The first line of the input gives the number of test cases, an integer T. T test cases follow.
Each test case consists of a line containing a string S, the template that Mr. Panda gets, an integer X, the minimum number of continuous vowels that Mrs. Panda dislikes, and an integer Y, the minimum number of continuous consonants that Mrs. Panda dislikes. In the template S, each character can be either one of lowercase English letters ('a’ to 'z’) or question mark ('?’).
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y can be either "LIKE", "DISLIKE" or "SURPRISE" as mentioned in the problem description.
5
happybirthda? 3 4
happybirth?ay 3 5
happybirthd?y 3 5
hellow?rld 3 5
helllllowooorld 3 5
Case #1: DISLIKE
Case #2: LIKE
Case #3: SURPRISE
Case #4: SURPRISE
Case #5: DISLIKE
PLAYERUNKNOWN'S BATTLEGROUNDS (PUBG, also known as "Chicken Dinner") is the most popular survival shooter game in recent months. Players are dropped into a wide, open area, and they must fight with each other until the last person survives. Specifically, there is a shrinking circle called safe area in the battlefield, while players outside this area will suffer continued damage, which forces them to confront each other and creates chances of skirmish.
Some players are particularly stupid, so they became users of the WG company. But recently, WG company often receive complaints from users that they often die outside the safe area. After carefully study, WG company found that their users are too stupid to know how to run into the safe area. Therefore, they decided to assist their users to complete this action.
After creating a coordinate system on the map, the player is at (x0, y0) point at moment 0, with movement speed v. At this moment, there is a circle C1 with radius of r1 and center at (x1, y1) indicating the safe area now. And players outside the safe area will get d1 continued damage per unit of time. The safe area will start to shrink at time t1 and becomes a smaller circle C2 at time t2, whose center is (x2, y2) and has radius r2. Since then, players outside the safe area will get d2 damage per unit of time.
C2 is strictly in C1, and the change of circle radius and the movement of circle center are at a constant speed. However, damages outside the safe area will change from d1 to d2 instantly at t2.
Your mission is to calculate the minimum damage the player incurs from the moment 0 till he/she reaches the final safe area C2 if the player moves optimally.
The first line of the input gives the number of test cases, T. T test cases follow.
Each test case contains three lines. The first line contains three integers x0, y0 and v, indicating the initial position and moving speed of player. The second line contains five integers x1, y1, r1, d1 and t1, while the third line also contains five integers x2, y2, r2, d2 and t2, as described above respectively.
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the minimum damages. y will be considered correct if it is within an absolute or relative error of 10 - 4 of the correct answer.
3
700 100 50
600 600 600 5 0
800 400 200 10 2
700 0 80
600 600 600 5 0
800 400 200 10 2
100 100 150
600 600 600 5 1
800 800 200 10 4
Case #1: 4.2537599506
Case #2: 16.5388203202
Case #3: 28.4702942691
A straight is a poker hand containing five cards of sequential rank, not necessarily to be the same suit. For example, a hand containing 7 club, 6 spade, 5 spade, 4 heart and 3 diamond forms a straight. In this problem, we extend the definition of a straight to allow 3 to 5 cards of sequential rank. Hence a hand containing K spade, Q club, and J heart is also a straight.
Mr. Panda is playing a poker game called Straight Master. The game uses a large deck of card that has N ranks from 1 to N. The rule of the game is simple: split the cards in Mr. Panda's hand into several straights of length from 3 to 5.
Now given a hand of cards, can you help Mr. Panda to determine if it is possible to split the cards into straights?
The first line of the input gives the number of test cases, T. T test cases follow.
Each test case contains two lines. The first line contains an integer N, indicating the number of ranks in the deck. The next line contains N integers a1, a2, ..., aN indicating the number of cards for each rank in Mr. Panda's hand.
. For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is Yes if Mr. Panda can split all his cards into straights of length from 3 to 5, or No otherwise.
2
13
1 2 2 1 0 0 0 0 0 0 0 0 0
13
1 1 1 1 0 1 1 0 0 0 0 0 0
Case #1: Yes
Case #2: No
In the first test case, Mr. Panda can split his cards into two straights: [1, 2, 3] and [2, 3, 4]. In the second test case, there is no way to form a straight for card 6 and 7.
The God of Sheep plays an RPG game recently. The game has a level system that records a player's level with a pair of positive integers A and B where A is the major level and B is the minor level. For each major level k, you have to reach minor level Lk in order to upgrade to the next level k + 1. Different major levels may have different number of minor levels. For example, the God of Sheep is currently on level 3-4, and level 3 contains 4 minor levels: 3-1, 3-2, 3-3, and 3-4. Once the God of Sheep upgrades, he will be on level 4-1.
The God of Sheep has work to do now. Countless sheep are suffering in slaughter houses, woolsheds, and dairy farms. The God of Sheep has to rescue his fellow sheep citizens. He will be busy with the rescue plan for a couple of days and meanwhile the level of the game will be downgraded each day as a penalty. The downgrade penalty works like this: with each day the God of Sheep not playing the game, his level A-B will firstly be transformed to A minor levels (with minor level B discarded), and then be cast to an equivalent
-
pair as his new level. For example, suppose both level 1 and level 2 have 2 minor levels, and the God of Sheep is currently on level 3-3. For the first day of his absence, the level will become 2-1, the second day the level will become 1-2, the third day the level will become 1-1, and from the third day on the level will keep the same level as 1-1.
The God of Sheep wonders which level will he be when he comes back from the rescue?
The first line of the input gives the number of test cases, T. T test cases follow.
Each test case contains two lines. The first line contains three integers: A, B and N, indicating the current major level, minor level, and the number of days the God of Sheep will be away from the game. The next line contains A integers: L1, L2, ..., LA indicating the number of minor levels in each major level.
For each test case, output one line containing "Case #x: y-z", where x is the test case number (starting from 1), y and z are the major level and the minor level when the God of Sheep is back to the game.
2
3 2 2
2 2 2
3 1 2
1 1 1
Case #1: 1-2
Case #2: 3-1
Mr. Panda and Mr. Sheep are playing a game on a 1 × N game board. Initially, all the cells are empty. Mr. Panda and Mr. Sheep take alternate moves and Mr.Panda moves first.
On each move, a player must fill an 'S' or 'O' into an empty cell. After the move, if there are 3 consecutive cells from left to right form the word "SOS", the player wins the game and the game finished.
If the board gets filled up without SOS appearing consecutively, no one wins the game, the game end with draw.
Now, if both Mr. Panda and Mr. Sheep play optimally, find out the result of the game.
The first line of the input gives the number of test cases, T. T test cases follow.
Each test case contains one line consists of one number N, indicating the size of the game board.
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the game result if both players play optimally. "Panda" for Mr. Panda winning the game, "Sheep" for Mr. Sheep winning the game, "Draw" for draw game.
2
3
7
Case #1: Draw
Case #2: Panda
In the first test case, as there are only 3 cells, both players cannot win as Mr. Sheep only has one move and after his move, there is still one cell left empty. So Mr. Sheep is impossible to win, but it's easy for him to avoid Mr. Panda to win. He can either fill 'O' in the first or third cell, or fill 'S' in the second cell to make it a draw game.
It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: since every 3 or more persons could make a chat group, there can be 42 different chat groups.
Given N persons in a dormitory, and every K or more persons could make a chat group, how many different chat groups could there be?
The input starts with one line containing exactly one integer T which is the number of test cases.
Each test case contains one line with two integers N and K indicating the number of persons in a dormitory and the minimum number of persons that could make a chat group.
For each test case, output one line containing "Case #x: y" where x is the test case number (starting from 1) and y is the number of different chat groups modulo 1000000007.
1
6 3
Case #1: 42