Aliens are visiting Earth and, as usual, they plan to abduct humans for their experiments. In the past, alien abductions have caused a lot of press coverage and wild speculation on Earth. Luckily for them, most people do not believe these stories and think that aliens are not real.
In order to keep a low profile in the future, the Galactic Committee for Person Captures (GCPC) has established rules for abductions. Besides a lot of boring paperwork, the aliens have to prepare the abduction carefully. While they can make multiple trips (in fact, alien travel is so fast in practice that this is not a limitation at all), they must be smart about it so that their secret is not revealed to humans. If aliens want to abduct a person, they are required to abduct all of their friends at the same time, so that no one notices that their friend is missing when they want to hang out. Of course, friendships on planet Earth are bidirectional, that is if Alice is a friend of Bob, then Bob is also a friend of Alice.
In preparation for the trip, the aliens have observed their targets and started taking note of all their friendships. In total, they must abduct $$$n$$$ people, including their friends. Now, they want to book a starship at their local dealership and wonder how much space they need to abduct all $$$n$$$ people. A starship's storage space is measured in terms of the number of people that can be transported simultaneously. What is the minimum storage space required to abduct all $$$n$$$ people?
The input consists of:
Output the minimum storage space needed to abduct all people.
5 31 22 34 5
3
3 0
1
8 81 22 33 41 41 52 63 74 8
8
Brianna is a bookworm. At home, she has a big bookshelf with all her favourite books. She has a large collection ranging from detective novels and science-fiction novels to biographies.
Recently, Brianna has expanded her collection with $$$n$$$ graphic novels. However, the new books currently lie around everywhere and form huge stacks on the floor. In the meantime, one of the shelf boards has collected dust and random household utensils that do not belong there. The new books just lying around have become too much to bear, and Brianna finally decided to put them on this shelf board. To do so, she first has to make room on it.
Visualization of Sample Input 3. Brianna wants to arrange the books in a single horizontal line without stacking multiple books on top of each other. While the shelf is wide enough to hold all books without problems, it takes time to make room on the shelf. Therefore, Brianna wants to minimize the width of the part of the shelf that she needs to clear.
Each book can be described as a cuboid with three side lengths $$$l$$$, $$$w$$$, and $$$h$$$. Since the room above the shelf board is limited by the next shelf board above it, she can only fit a book vertically if its vertical side length is at most the distance $$$H$$$ between the two shelf boards. Brianna may rotate each book in three-dimensional space as she wants. It is guaranteed that the shelf is deep enough so that the books will not fall off, no matter the orientation. However, all books must stand properly on the shelf board, meaning that every book touches the shelf board along an entire face and not just by an edge.
What is the minimum width of shelf Brianna's books need?
The input consists of:
Output the minimum width of shelf Brianna's books need, or "impossible" if it is impossible to place the books on the shelf.
1 310 2 5
5
1 310 4 5
impossible
2 1010 2 102 3 4
4
3 10000000001000000000 1000000000 10000000001000000000 1000000000 10000000001000000000 1000000000 1000000000
3000000000
Your university recently established the Graduate Code Plagiarism Control (GCPC) initiative to get hold of the ever-increasing load on the graders for the computer science assignments. Currently, the graders need to check the code of assignments manually for plagiarism. The GCPC aims to simplify this part of the graders' jobs by performing the plagiarism checks automatically.
Code consists of tokens separated by spaces. Tokens are strings of alphabetical letters, numerals, and brackets. If a token consists of only a single alphabetical letter (upper or lowercase), it is a variable in the code.
The GCPC wants the plagiarism checker to compare query pieces of code to a reference code. Specifically, it should check whether each query could have been obtained by selecting a contiguous string of tokens from the reference and consistently renaming variables. Variables are consistently renamed if no two occurrences of the same variable are renamed to different variables, and if no two different variables are renamed to the same variable.
The GCPC has asked you to develop the plagiarism checker.
The input consists of:
For each query, output "yes" if the query could have been obtained from the reference, and "no" otherwise.
9for i in range(10) do print i j end43print j i2do print6k in range(10) do print k6k in range(10) do print j
yes yes yes no
5i is i times j75i is i times j5a is a times b5j is j times c5a is i times j5j is i times j50 is 0 times j5i is i times i
yes yes yes no no no no
5A 1 ( ) b42b 22b 131 ) (5a 1 ( ) F
no yes no yes
One cold and foggy night, you walk down a shady alley. There should be a lamp every few metres but none of them seem to work, and in this night, not even the moon enlightens your path. Alone and in the dark, you wonder: "Even if there was a working lamp somewhere, how much would it lighten my way?". Now, back at home, you want to calculate this.
The alley can be modelled as a line with a length of $$$n$$$ metres. The fog has a uniform density and reduces the light of a lamp by a factor of $$$1-p$$$ every metre. The brightness at one point is the sum of the light that reaches this point from every lamp. You want to calculate this brightness at some points after placing some lamps.
The input consists of:
It can be shown that the brightness can be calculated as a fraction $$$\frac{P}{Q}$$$ where $$$Q$$$ is not divisible by $$$10^9+7$$$. For each query of type "?", print the brightness as $$$P\cdot Q^{-1} \bmod 10^9+7$$$ in a single line.
5 6 0.25+ 4 2? 1? 2? 3? 4? 5
3 4 3 250000004 187500003
5 7 0.33+ 9 1? 5+ 4 3? 2? 5- 9 1? 2
312342734 470000012 341542736 760000008
The brightness in the alley after placing the lamp will look like this:
| 3 | 4 | 3 | 2.25 | 1.6875 |
As every Saturday, Eve is paying her local game club a visit. Today, Bob has brought a new game he has designed on his own. After thorough investigation, you claim that there exists a dominant strategy, so one player can always win. Bob is hesitant to accept that his game is boring to play, so he challenges you to play a round! Since you claim that there exists a dominant strategy, you may determine who begins the game.
The cards in the two sample interactions. The rules are as follows. There are $$$n$$$ cards on the table, each containing a maths operation (+ or *) and an integer, as shown in Figure above. Eve and Bob alternate picking cards to manipulate a common number using one of the cards. For instance, if the current value of the number is $$$5$$$, and the card says $$$+3$$$, then the value gets updated to $$$8$$$. Each card can only be used once, and the game ends when all the cards have been used. The player who makes the first move wins if the final number is odd, and the other player wins if the final number is even. Given the list of cards and the starting value, help Eve win the game.
The interactor begins by outputting the starting state of the game in the following format:
Then, your submission must output one of "me" or "you", depending on if you want to go first or you want the interactor to go first.
Then your submission and the interactor alternate outputting cards in the same format as above. No card can be played more than once. Your submission must exit when all cards have been played, regardless of which player made the last move.
Your submission will be accepted if it follows all the rules above and the final value has the parity indicated on the first line of your output.
Make sure you flush the buffer after each write.
A testing tool is provided to help you develop your solution.
3 + 7 * 4 + 2 1 * 4
me + 2 + 7
2 + 8 * 5 10 + 8
you * 5
Frida's birthday is just coming up, and as her best friend, you obviously baked a cake for her. Since you know that Frida loves rotational symmetry, you thought to bake a cake that looks the same from above when rotated by $$$180^\circ$$$. Of course, you could have simply baked a boring round cake, but without a perfectly round cake tin, this sounds easier than done. Therefore, you decided to bake a cake whose shape can be described by straight line segments.
Visualization of Sample Input 2. The swirly cake looking like an S can be cut into the red and blue part with a single cut. However, after you are done with your cake, you notice that you also want to cut the cake into two equal pieces, one for Frida and one for yourself. More precisely, you wonder if it is possible to cut the cake along an infinite line such that it splits into exactly two parts of equal weight. You can assume that the cake has uniform density and height.
The input consists of:
Output two different points on the desired line as $$$x_1$$$/$$$c_1$$$ $$$y_1$$$/$$$d_1$$$ $$$x_2$$$/$$$c_2$$$ $$$y_2$$$/$$$d_2$$$, where $$$|x_i|$$$, $$$|y_i|$$$, $$$|c_i|$$$ and $$$|d_i|$$$ are integers and at most $$$10^9$$$, and $$$x_i$$$/$$$c_i$$$ is the first coordinate of point $$$i$$$ and $$$y_i$$$/$$$d_i$$$ is the second ($$$1\leq i\leq2$$$). If the denominator of a fraction is $$$1$$$ you may output only the numerator. Fractions do not have to be reduced. If there is no such line, output "impossible" instead.
It can be shown that if there is a line as desired, it is possible to represent it in the given format.
40 02 02 20 2
1 1 1337/42 3141/1000
207 18 28 57 64 64 43 43 76 77 82 81 71 42 35 35 56 56 23 22 1
11 13 -2 -4
1011 510 212 62 27 31 12 40 010 45 3
impossible
Pentominous is a grid logic puzzle based on the twelve pentominoes. A pentomino is a polygon formed by connecting five equal-sized squares edge to edge.
The twelve pentominoes (up to mirroring and rotations) and their names. The goal of this puzzle is to divide a grid into regions of size $$$5$$$ (that is, pentominoes), so that no two regions that share a side have the same shape. You are allowed to rotate and mirror the pentominoes, but such rotations and reflections count as the same shape. The twelve possible shapes can be seen in Figure above.
In a normal Pentominous puzzle, the player is given some pre-filled cells, for which the shape of their region is already predetermined. In this problem, you are working with a completely blank grid of dimensions $$$h\times w$$$, and your task is to create any valid arrangement of pentominoes.
The input consists of:
If there is no valid $$$h\times w$$$ Pentominous grid, output "no". Otherwise, output "yes", followed by $$$h$$$ lines of width $$$w$$$ each, a possible grid using the letters from the problem statement. If there is more than one solution, any one of them will be accepted.
3 5
yes UUXUU UXXXU UUXUU
2 10
yes LLLLNNNPPP LIIIIINNPP
99 17
no
6 10
yes IPPYYYYVVV IPPXYLLLLV IPXXXFZZLV ITWXFFFZUU ITWWNNFZZU TTTWWNNNUU
1 5
yes IIIII
Illustration of Sample Output 1.
Illustration of Sample Output 2.
Illustration of Sample Output 4.
The German ICPC scene is widely considered one of the most competitive. At least, that's what we tell our students. Countless rivalries form a complex web of envy, despair, glory, and triumph woven around and manifested in the unrelenting echoes of two scoreboards – Winter Contest and GCPC. While generations of participants tend to forget the grudges of their predecessors, we coaches, acting as timeless beacons of continuity, preserve these petty conflicts between long forgotten teams. Striving for perfect balance, we express our dedication to our coaching duties in a furious outcry on social media against every unfair news article. That is, a coach gets mad if a news article is published that contains a rival university name more often than their own.
To smoothen the waves of conflict in this ocean of rage, a newly appointed authority is tasked with proofreading media coverage of GCPC and Winter Contest to prevent uneven coverage.
The input consists of:
If a university $$$u$$$ is a rival of university $$$v$$$, then $$$v$$$ is also a rival of $$$u$$$. Moreover, there are no duplicate rivalries.
Names and articles are strings of lowercase Latin letters and spaces. The first and last character of a name or article are never a space. Names can overlap and be contained in other names.
The summed length of all names and articles is at most $$$10^6$$$, i.e. $$$\sum_{i=1}^{n} |p_i| + \sum_{i=1}^{k} |t_i| \leq 10^6$$$.
For each article, output "no" if it will draw the wrath of at least one coach and "yes" otherwise.
3 1 4hpifaukit1 3kit destroys hpi at wintercontestgcpc is greatteam moshpit from hpi beats kit teamswhats the abbreviation for university of erlangen nuremberg
yes yes no yes
6 3 5udscutumrwthuni ulmuni4 12 51 3last gcpc rwth had a team in top ten two places behind tumwho is team debuilding from constructor university brementop ten teams last year are from kit cu uds hpi tum and rwthuni ulm cu uni ulmsunday alright lets go
no yes no no yes
Physics can be so much fun! Yesterday, your teacher explained how interference works: If you have two waves, their heights add up over the whole waves' length! So if both waves have a peak, the resulting peak will be even higher. Likewise, if both waves have a wave trough below the water surface, the resulting wave has a trough that will be even further below. Technically, a wave's height is called amplitude and the distance between two wave peaks is called wavelength.
Today, your physics teacher describes the setup of an experiment she is about to perform. She will create stationary waves in a one-dimensional container of water. Due to her superior control over physical elements, all waves will have a precisely controlled amplitude and will only be created in an interval of given length. The wavelength of each wave is always $$$4$$$ and the first positive peak will always be at the first index of the interval. We only measure the wave's amplitude at integer points. For example, a wave with amplitude $$$2$$$ and length $$$9$$$ can be described as 2 0 -2 0 2 0 -2 0 2. If there is no wave at a point, the amplitude is $$$0$$$. Your task is to predict how high the resulting wave will be at given points in the container taking into account all the waves that were created up to that point.
The input consists of:
For each prediction task, output a line with a single integer, the height of the wave resulting from all former described waves at the requested position.
4 10! 2 7 1? 9? 7? 6
0 0 1
7 10! 2 6 1! 3 8 2! 5 2 3? 6! 5 5 4? 8? 9
1 0 2
6 12! 1 7 1! 7 3 2? 6? 7? 8? 10
0 1 0 0
6 11! 1 6 1? 6! 5 7 4? 6! 6 3 2? 6
0 0 2
Interference of three waves in Sample Input 2. The black dots represent the resulting wave's height.
Julia is preparing a present for James. She will give him some of her $$$n$$$ jigsaw puzzles, where puzzle $$$i$$$ ($$$1 \leq i \leq n$$$) consists of $$$x_i$$$ pieces and has a difficulty $$$y_i$$$ (can be negative if the puzzle is very easy).
James is already very excited and would like to know in advance what he will get. Therefore, he used some of his criminal energy to gather information about the gift. In particular, he has managed to obtain an encrypted message containing the total difficulty and total number of pieces of all the puzzles that he will receive.
Now he wonders whether it is worth spending some more time to decrypt the message. After all, it might be that this information is not enough to uniquely determine his gift. Since he was never good at these computer thingies, James asked for your assistance. Help him find out whether it is worth decrypting the message or not. If the answer is negative, you have to find two distinct gifts that result in the same encrypted message.
The input consists of
If James can uniquely determine his gift, then print "yes". Otherwise, you should print "no" followed by two lines, where each line contains the description of a present. The description of a present should start with an integer $$$k$$$, the number of puzzles, followed by $$$k$$$ distinct integers, the indices of the puzzles.
Note that the two presents have to be distinct, meaning that there should be at least one puzzle that is contained in one present but not the other.
If there are multiple presents that result in the same encrypted message, you can print any of them.
52 -13 23 11 -31 1
no 3 2 4 5 2 1 3
42 -13 23 11 -3
yes
In the first sample case, the first present consists of puzzles $$$2$$$, $$$4$$$, and $$$5$$$. The total number of pieces is $$$3 + 1 + 1 = 5$$$ and the total difficulty is $$$2 + (-3) + 1 = 0$$$. The second present consists of puzzles $$$1$$$ and $$$3$$$. The total number of pieces is $$$2 + 3 = 5$$$ and the total difficulty is $$$(-1) + 1 = 0$$$. Thus, if James only knows the total number of pieces and the total difficulty, he cannot recover his present. So it is not worth to decode the message.
In the second sample case, no matter what gift Julia prepares, if James knows the total number of pieces and the total difficulty, he can recover his present. So he should decode the message.
Karen has a beautiful precious glass object on the shelf in her living room. Unfortunately, her cat Klaus does not like it when there is stuff on his favourite shelf. Everything that is not bolted or glued in place, he will gradually push over the edge while looking Karen straight in the eyes.
Now, Klaus' paw slowly executes his diabolical deed. His cute fluffy face radiates inadvertent innocence. Knowing that any intervention would only delay the inevitable, Karen wonders what will happen to the string her sister Kim wrote on the precious glass object. After all, it took Kim a whole week to gather all the bdpq letters that make up the string.
Can you describe to Karen what the string will look like from her point of view while it tumbles towards destruction?
While falling off the shelf, Karen's precious glass object is subject to the following transformations, described as seen when looking at the object from the front.
No flips along or rotations about any other axes are possible.
The input consists of:
Output the string that can be seen at the moment the glass object touches the ground and just before it shatters into pieces.
bbqh
pdd
bbqv
ppd
bbqr
bqq
ppbddbqhvrhv
bqppqdd
Every Sunday is laundry day, and there is always a huge pile of clothes waiting to be washed, which is certainly going to take you forever. You are particularly annoyed by how careful you have to be when washing certain items, and how important it is that you choose an appropriate washing programme for each item.
Fortunately, your washing machine is quite old and only supports three different washing programmes: A, B, and C. You can put at most $$$k$$$ items in one load, and each load can be washed using one of the programmes.
Some items are easy to care for, and you can put them in any load you like. More delicate items must not be washed using a specific programme, but the other two are fine. Of course, the worst clothes are the ones for which only one programme is appropriate.
You have already sorted the items into seven piles by putting items together for which the same combination of programmes is fine, so you know how many items are in each pile.
What is the minimum number of loads you need to wash?
Illustration of Sample Input 2 with an optimal solution. The figure on the left shows seven piles, one for each combination. The figure on the right shows a (possible) optimal solution, where each pile is washed in one load. The numbers on the pile represent how many items of each combination are washed with this load. In particular, the leftmost pile is washed using programme A, the two piles in the middle with programme B, and the two piles on the right with programme C. Thus, we need five loads to wash all items, which is optimal since we have $$$15$$$ items in total. The input starts with a line containing one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$), the number of test cases. Then for each test case:
For each test case, output the minimum number of loads that are needed to wash all clothes.
41015 11 9 5 2 7 11200 0 0 0 0 0 065 6 8 9 1 0 01213295053681 137950336 87466375 956271897 344992260 31402049 988259763
6 0 6 2342454
131 2 1 3 3 2 3
5
Shortly before the concert starts, you notice that your piano is completely out of tune! Having the ability of relative pitch, you are able to discern the difference between the pitch of any piano key to the first piano key. While this does not help you find the absolute pitch, you decide to at least tune the keys relative to each other. To do this, you need to make sure that the pitch of each key is exactly one higher than the key before it and one lower than the key after it. As the concert will start shortly, you need to minimize the total tuning effort, which is the sum of the absolute changes in pitch you apply to each key. For example, the picture below illustrates a solution for Sample Input 3, resulting in a total tuning effort of 23.
Visualization of Sample Input 3. The input consists of:
Output the minimal total tuning effort.
70 1 2 3 4 5 6
0
50 1 4 3 6
4
60 -2 10 6 7 -1
23
40 -4 -2 1
7
90 23452 145043 -3423 -20 9845 435 -3 4453
186237