2015 Problems
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .gitattributes+5
- 2015/finals/fox_blocks.htmlAdded+77
- 2015/finals/fox_blocks.inAdded+3
- 2015/finals/fox_blocks.mdAdded+59
- 2015/finals/fox_blocks.outAdded+20
- 2015/finals/fox_focks.htmlAdded+59
- 2015/finals/fox_focks.inAdded+3
- 2015/finals/fox_focks.mdAdded+52
- 2015/finals/fox_focks.outAdded+20
- 2015/finals/fox_hawks.htmlAdded+94
- 2015/finals/fox_hawks.inAdded+3
- 2015/finals/fox_hawks.mdAdded+78
- 2015/finals/fox_hawks.outAdded+20
- 2015/finals/fox_lochs.htmlAdded+57
- 2015/finals/fox_lochs.inAdded+281
- 2015/finals/fox_lochs.mdAdded+44
- 2015/finals/fox_lochs.outAdded+20
- 2015/finals/fox_locks.htmlAdded+74
- 2015/finals/fox_locks.inAdded
- 2015/finals/fox_locks.mdAdded+67
- 2015/finals/fox_locks.outAdded+20
- 2015/quals/cooking_the_books.htmlAdded+45
- 2015/quals/cooking_the_books.inAdded+101
- 2015/quals/cooking_the_books.mdAdded+30
- 2015/quals/cooking_the_books.outAdded+100
- 2015/quals/laser_maze.htmlAdded+68
- 2015/quals/laser_maze.inAdded
- 2015/quals/laser_maze.mdAdded+48
- 2015/quals/laser_maze.outAdded+100
- 2015/quals/new_years_resolution.htmlAdded+41
- 2015/quals/new_years_resolution.inAdded+1006
- 2015/quals/new_years_resolution.mdAdded+31
- 2015/quals/new_years_resolution.outAdded+48
- 2015/round1/autocomplete.htmlAdded+54
- 2015/round1/autocomplete.inAdded+3
- 2015/round1/autocomplete.mdAdded+41
- 2015/round1/autocomplete.outAdded+26
- 2015/round1/corporate_gifting.htmlAdded+79
- 2015/round1/corporate_gifting.inAdded+3
- 2015/round1/corporate_gifting.mdAdded+68
- 2015/round1/corporate_gifting.outAdded+34
- 2015/round1/homework.htmlAdded+42
- 2015/round1/homework.inAdded+101
- 2015/round1/homework.mdAdded+48
- 2015/round1/homework.outAdded+100
- 2015/round1/winning_at_sports.htmlAdded+61
- 2015/round1/winning_at_sports.inAdded+101
- 2015/round1/winning_at_sports.mdAdded+45
- 2015/round1/winning_at_sports.outAdded+100
- 2015/round2/all_critical.htmlAdded+57
57 unmodified lines58596057 unmodified lines2014/finals/intervals_of_love.in filter=lfs diff=lfs merge=lfs -text2014/finals/lunch_at_facebook.in filter=lfs diff=lfs merge=lfs -text2014/finals/tours.in filter=lfs diff=lfs merge=lfs -text57 unmodified lines585960616263646557 unmodified lines2014/finals/intervals_of_love.in filter=lfs diff=lfs merge=lfs -text2014/finals/lunch_at_facebook.in filter=lfs diff=lfs merge=lfs -text2014/finals/tours.in filter=lfs diff=lfs merge=lfs -text2015/finals/fox_blocks.in filter=lfs diff=lfs merge=lfs -text2015/finals/fox_focks.in filter=lfs diff=lfs merge=lfs -text2015/finals/fox_hawks.in filter=lfs diff=lfs merge=lfs -text2015/round1/autocomplete.in filter=lfs diff=lfs merge=lfs -text2015/round1/corporate_gifting.in filter=lfs diff=lfs merge=lfs -text
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677<p>Today, Mr. Fox is taking it easy by playing with some blocks in a 2D world. Each block is an inch-by-inch square,and there are <strong>N</strong> stacks of blocks in a row, with the <strong>i</strong>th stack having <strong>H<sub>i</strong> blocks. For example, if <strong>N</strong>=6 and <strong>H</strong>={3, 1, 5, 4, 1, 6}, then the collection of blocks looks like this (where an "X" denotes a block):<p>
<p><pre>.....X..X..X..XX.XX.XX.XX.XX.XXXXXXX</pre></p>
<p>Ever curious, Mr. Fox would like to answer <strong>Q</strong> questions about his blocks (without actually modifying them), the <strong>i</strong>th one being as follows:</p>
<p>"If I were to consider only the stacks from <strong>A<sub>i</sub></strong> to <strong>B<sub>i</sub></strong> inclusive, getting rid of all of the other blocks, how many square inches of water would my block structure be able to hold?"</p>
<p>As one might imagine, a given square inch can hold water if it doesn't contain a block itself, but there is a block both somewhere to its leftand somewhere to its right at the same height. For example, if you were to take <strong>A<sub>i</sub></strong>=2 and <strong>B<sub>i</sub></strong>=6, you would be left with the following block structure to consider (where an "*" denotes an inch-by-inch square which can hold water):</p>
<p><pre>....X.X**X.XX*X.XX*X.XX*XXXXXX</pre></p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 20 <br/>1 ≤ <strong>N</strong> ≤ 300,000 <br />1 ≤ <strong>Q</strong> ≤ 300,000 <br />1 ≤ <strong>H<sub>i</sub></strong> ≤ 10<sup>9</sup> <br />1 ≤ <strong>A<sub>i</sub></strong> ≤ <strong>B<sub>i</sub></strong> ≤ <strong>N</strong> <br /></p>
<h3>Input</h3><p>Input begins with an integer <strong>T</strong>, the number of block structures Mr. Fox has.For each structure, there is first a line containing the space-separated integers <strong>N</strong> and <strong>Q</strong>. The next line contains the space-separated integers <strong>H<sub>i</sub></strong>.Then follow <strong>Q</strong> lines, the <strong>i</strong>th of which contains the space-separated integers<strong>A<sub>i</sub></strong> and <strong>B<sub>i</sub></strong>.</p>
<h3>Output</h3><p>For the <strong>i</strong>th structure, print a line containing "Case #<strong>i</strong>: " followed bythe sum of the answers to the <strong>Q</strong> questions modulo 10<sup>9</sup>+7.</p>
<h3>Explanation of Sample</h3><p>In the first case, we consider prefixes of the block structure. The answers to the queries are 0, 0, 0, 0, 0, 5, 5, 7, 7, 18, 18 for a total of 60.</p>123version https://git-lfs.github.com/spec/v1oid sha256:69c748bc3d1a448fe7f376cb4cacd7b4eefae27a6aa2103899f4da2919c6b233size 278324831234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859Today, Mr. Fox is taking it easy by playing with some blocks in a 2D world.Each block is an inch-by-inch square, and there are **N** stacks of blocks ina row, with the **i**th stack having **Hi** blocks. For example, if **N**=6and **H**={3, 1, 5, 4, 1, 6}, then the collection of blocks looks like this(where an "X" denotes a block):
.....X ..X..X ..XX.X X.XX.X X.XX.X XXXXXX
Ever curious, Mr. Fox would like to answer **Q** questions about his blocks(without actually modifying them), the **i**th one being as follows:
"If I were to consider only the stacks from **Ai** to **Bi** inclusive,getting rid of all of the other blocks, how many square inches of water wouldmy block structure be able to hold?"
As one might imagine, a given square inch can hold water if it doesn't containa block itself, but there is a block both somewhere to its left and somewhereto its right at the same height. For example, if you were to take **Ai**=2 and**Bi**=6, you would be left with the following block structure to consider(where an "*" denotes an inch-by-inch square which can hold water):
....X .X**X .XX*X .XX*X .XX*X XXXXX
### Constraints
1 ≤ **T** ≤ 20 1 ≤ **N** ≤ 300,000 1 ≤ **Q** ≤ 300,000 1 ≤ **Hi** ≤ 109 1 ≤ **Ai** ≤ **Bi** ≤ **N**
### Input
Input begins with an integer **T**, the number of block structures Mr. Foxhas. For each structure, there is first a line containing the space-separatedintegers **N** and **Q**. The next line contains the space-separated integers**Hi**. Then follow **Q** lines, the **i**th of which contains the space-separated integers **Ai** and **Bi**.
### Output
For the **i**th structure, print a line containing "Case #**i**: " followed bythe sum of the answers to the **Q** questions modulo 109+7.
### Explanation of Sample
In the first case, we consider prefixes of the block structure. The answers tothe queries are 0, 0, 0, 0, 0, 5, 5, 7, 7, 18, 18 for a total of 60.
1234567891011121314151617181920Case #1: 60Case #2: 27Case #3: 31Case #4: 0Case #5: 9Case #6: 0Case #7: 824489226Case #8: 228416209Case #9: 14231442Case #10: 31749050Case #11: 871842030Case #12: 496227686Case #13: 740455790Case #14: 687834190Case #15: 415275284Case #16: 815170510Case #17: 737257432Case #18: 204464835Case #19: 550439741Case #20: 3282564611234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859<p>Mr. Fox has opened up a fabulous Fock farm! A Fock is a cute little animal which can have either red, green, or blue fur (these 3 possible colors can be numbered 1, 2, and 3, respectively). Furthermore, a Fock's fur color can change every second!</p>
<p>Mr. Fox owns a flock of <strong>N</strong> Focks, with the <strong>i</strong>th one initially having a color of <strong>C<sub>i</sub></strong>.Every second, if the <strong>i</strong>th Fock currently has a color of <strong>a</strong>, it will switch to having a color of <strong>b</strong> for the next second with probability <strong>P<sub>i,a,b</sub></strong>%. All Focks change color simultaneously.</p>
<p>After a very large amount of time has gone by, Mr. Fox will take a single photo of all of his Focks to help advertise his farm. In particular, he picks an integer <strong>t</strong> at uniform random from the range [10<sup>100</sup>, 10<sup>1000</sup>] and waits that many seconds.He's hoping that the photo will make it look like his farm has a well-balanced mix of Fock colors — it'll be no good if the photo ends up featuring a strict majority of a single color (that is, strictly more than <strong>N</strong>/2 of the Focks having the same color). What's the probability of this occurring?</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 20<br />1 ≤ <strong>N</strong> ≤ 50,000<br />1 ≤ <strong>C<sub>i</sub></strong> ≤ 3 for all <strong>i</strong><br />0 ≤ <strong>P<sub>i,a,b</sub></strong> ≤ 100for all <strong>i</strong>, <strong>a</strong> and <strong>b</strong><br /><strong>P<sub>i,a,1</sub></strong> + <strong>P<sub>i,a,2</sub></strong> + <strong>P<sub>i,a,3</sub></strong> = 100 for all <strong>i</strong> and <strong>a</strong><br /></p>
<h3>Input</h3><p>Input begins with an integer <strong>T</strong>, the number of Fock farms Mr. Fox has.For each farm, there is first a line containing the integer <strong>N</strong>.Then, for each Fock <strong>i</strong>, 4 lines follow.The first of these lines contains the integer <strong>C<sub>i</sub></strong>.The next three lines contain three space-separated integers each, with the <strong>b</strong>th integer on the <strong>a</strong>th line being <strong>P<sub>i,a,b</sub></strong>.</p>
<h3>Output</h3><p>For the <strong>i</strong>th farm, print a line containing "Case #<strong>i</strong>: " followed bythe probability that the <strong>i</strong>th picture contains a strict majority of some color of Fock, rounded to 6 decimal places.</p>
<p>Absolute errors of up to 2e-6 will be ignored.</p>
<h3>Explanation of Sample</h3><p>In the first case, the first Fock never changes color, so it'll still have color 1 in the photo.The second Fock is likely to have color 2 for a while, but by the time the photo is taken, it'll certainly have color 3.The third Fock will have either color 2 or 3 in the photo, with equal probability. Therefore, the photo will have a 50% chance of having a strict majority of color 3, and a 50% chance of no strict majority.</p>123version https://git-lfs.github.com/spec/v1oid sha256:bf3025efbfee6b3d52c0372283c0712b33eab850e808172bd5c830b61e17610csize 1788922412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152Mr. Fox has opened up a fabulous Fock farm! A Fock is a cute little animalwhich can have either red, green, or blue fur (these 3 possible colors can benumbered 1, 2, and 3, respectively). Furthermore, a Fock's fur color canchange every second!
Mr. Fox owns a flock of **N** Focks, with the **i**th one initially having acolor of **Ci**. Every second, if the **i**th Fock currently has a color of**a**, it will switch to having a color of **b** for the next second withprobability **Pi,a,b**%. All Focks change color simultaneously.
After a very large amount of time has gone by, Mr. Fox will take a singlephoto of all of his Focks to help advertise his farm. In particular, he picksan integer **t** at uniform random from the range [10100, 101000] and waitsthat many seconds. He's hoping that the photo will make it look like his farmhas a well-balanced mix of Fock colors — it'll be no good if the photo ends upfeaturing a strict majority of a single color (that is, strictly more than**N**/2 of the Focks having the same color). What's the probability of thisoccurring?
### Constraints
1 ≤ **T** ≤ 20 1 ≤ **N** ≤ 50,000 1 ≤ **Ci** ≤ 3 for all **i** 0 ≤ **Pi,a,b** ≤ 100 for all **i**, **a** and **b** **Pi,a,1** \+ **Pi,a,2** \+ **Pi,a,3** = 100 for all **i** and **a**
### Input
Input begins with an integer **T**, the number of Fock farms Mr. Fox has. Foreach farm, there is first a line containing the integer **N**. Then, for eachFock **i**, 4 lines follow. The first of these lines contains the integer**Ci**. The next three lines contain three space-separated integers each, withthe **b**th integer on the **a**th line being **Pi,a,b**.
### Output
For the **i**th farm, print a line containing "Case #**i**: " followed by theprobability that the **i**th picture contains a strict majority of some colorof Fock, rounded to 6 decimal places.
Absolute errors of up to 2e-6 will be ignored.
### Explanation of Sample
In the first case, the first Fock never changes color, so it'll still havecolor 1 in the photo. The second Fock is likely to have color 2 for a while,but by the time the photo is taken, it'll certainly have color 3. The thirdFock will have either color 2 or 3 in the photo, with equal probability.Therefore, the photo will have a 50% chance of having a strict majority ofcolor 3, and a 50% chance of no strict majority.
1234567891011121314151617181920Case #1: 0.500000Case #2: 0.000000Case #3: 1.000000Case #4: 0.777778Case #5: 0.812282Case #6: 1.000000Case #7: 0.333333Case #8: 0.511290Case #9: 0.333334Case #10: 0.590398Case #11: 0.526490Case #12: 0.333333Case #13: 0.333333Case #14: 0.510803Case #15: 0.333334Case #16: 0.333334Case #17: 0.515045Case #18: 0.518484Case #19: 0.333334Case #20: 0.51111912345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394<p>Mr. Fox always puts aside some time on the weekends to practice his falconry. Mr. Fox owns <strong>N</strong> hawks, numbered from1 to <strong>N</strong>. While numbering is somewhat impersonal, it quickly becomes infeasible to name each hawk individually whenyou have as many hawks as Mr. Fox.</p>
<p>Every year, the local falconer club hosts a festival for falconers from across the nation. Mr. Fox shows off some of his hawks at each festival,and this year is no different. Selecting a set of hawks to display is not a straightforward task however. Hawks can be temperamental creatures,and they'll refuse to perform if they don't like the situation they find themselves in. Luckily, after careful study, Mr. Fox has been able tocapture the hawks' preferences in a simple boolean expression.</p>
<p>For example, let's say Mr. Fox has 4 hawks. Hawk 1 will only perform if some other hawk is present. Hawks 2 and 3 will only perform if hawks1 or 4 are present. Hawk 4 is much more easy-going and will perform in all situations. We can express these preferences with the followingexpression:
<pre>((1 & (2 | 3)) | 4)</pre></p>
<p>Each number is a boolean variable indicating whether or not Mr. Fox brings that hawk. If the expression is satisfied, then all of the hawks hebrings will perform. If the expression is not satisfied, the hawks will be moody and that means no blue ribbons for Mr. Fox.</p>
<p>Mr. Fox is keen not to bore his audience, so he always brings a different set of hawks each year.
This is the <strong>K</strong>th annual festival, so he would like to bring the set of performing hawks with the <strong>K</strong>th lowest value. Mr. Fox defines the value of a set of hawks as follows: the empty set has a value of 0, and hawk <strong>i</strong> adds 2<sup><strong>i</strong></sup> to the value of a set.
So with 3 hawks, the sets in increasing order are:
<pre>{1}{2}{1, 2}{3}{1, 3}{2, 3}{1, 2, 3}</pre>
Note that Mr. Fox always brings a non-empty set of hawks.</p>
<h3>Input</h3><p>Input begins with an integer <strong>T</strong>, the number of festivals under consideration.For each festival, there is first a line containing the space-separated integers <strong>N</strong> and <strong>K</strong>. The next line contains the boolean expression encoding the hawks' preferences.</p>
<h3>Output</h3><p>For the <strong>i</strong>th festival, print a line containing "Case #<strong>i</strong>: " followed byvalue of the set of hawks that Mr. Fox brings modulo 10<sup>9</sup>+7.</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 20 <br />1 ≤ <strong>N</strong> ≤ 200,000 <br />1 ≤ <strong>K</strong> ≤ 10<sup>18</sup> <br />Expressions contain no more than 2,500,000 characters each. <br />It is guaranteed that there are at least <strong>K</strong> sets of performing hawks. <br /></p>
<p>The boolean expression adheres to the following grammar:
<pre>[expression] ::= "(" "~" [expression] ")" | "(" [expression] [binary-operator] [expression] ")" | [variable][binary-operator] ::= "|" | "^" | "&"[variable] ::= [digit] | [digit] [variable][digit] ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"</pre>
Each hawk appears in the boolean expression exactly once. <br />Whitespace may appear arbitrarily in the expression (except within variables) to improve readability. <br /></p>
<h3>Explanation of Sample</h3><p>In the first and second cases, the first 4 performing sets, in order, are {1, 2}, {1, 3}, {1, 2, 3}, and {4}, with values of 6, 10, 14, and 16 respectively.</p>
123version https://git-lfs.github.com/spec/v1oid sha256:56fc5974bcd713444e7a8c1ffd6c88234796e487ba059f644f022bacb7ee0cc2size 12921762123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778Mr. Fox always puts aside some time on the weekends to practice his falconry.Mr. Fox owns **N** hawks, numbered from 1 to **N**. While numbering issomewhat impersonal, it quickly becomes infeasible to name each hawkindividually when you have as many hawks as Mr. Fox.
Every year, the local falconer club hosts a festival for falconers from acrossthe nation. Mr. Fox shows off some of his hawks at each festival, and thisyear is no different. Selecting a set of hawks to display is not astraightforward task however. Hawks can be temperamental creatures, andthey'll refuse to perform if they don't like the situation they findthemselves in. Luckily, after careful study, Mr. Fox has been able to capturethe hawks' preferences in a simple boolean expression.
For example, let's say Mr. Fox has 4 hawks. Hawk 1 will only perform if someother hawk is present. Hawks 2 and 3 will only perform if hawks 1 or 4 arepresent. Hawk 4 is much more easy-going and will perform in all situations. Wecan express these preferences with the following expression:
((1 & (2 | 3)) | 4)
Each number is a boolean variable indicating whether or not Mr. Fox bringsthat hawk. If the expression is satisfied, then all of the hawks he bringswill perform. If the expression is not satisfied, the hawks will be moody andthat means no blue ribbons for Mr. Fox.
Mr. Fox is keen not to bore his audience, so he always brings a different setof hawks each year. This is the **K**th annual festival, so he would like tobring the set of performing hawks with the **K**th lowest value. Mr. Foxdefines the value of a set of hawks as follows: the empty set has a value of0, and hawk **i** adds 2**i** to the value of a set. So with 3 hawks, the setsin increasing order are:
{1} {2} {1, 2} {3} {1, 3} {2, 3} {1, 2, 3}
Note that Mr. Fox always brings a non-empty set of hawks.
### Input
Input begins with an integer **T**, the number of festivals underconsideration. For each festival, there is first a line containing the space-separated integers **N** and **K**. The next line contains the booleanexpression encoding the hawks' preferences.
### Output
For the **i**th festival, print a line containing "Case #**i**: " followed byvalue of the set of hawks that Mr. Fox brings modulo 109+7.
### Constraints
1 ≤ **T** ≤ 20 1 ≤ **N** ≤ 200,000 1 ≤ **K** ≤ 1018 Expressions contain no more than 2,500,000 characters each. It is guaranteed that there are at least **K** sets of performing hawks.
The boolean expression adheres to the following grammar:
[expression] ::= "(" "~" [expression] ")" | "(" [expression] [binary-operator] [expression] ")" | [variable] [binary-operator] ::= "|" | "^" | "&" [variable] ::= [digit] | [digit] [variable] [digit] ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
Each hawk appears in the boolean expression exactly once. Whitespace may appear arbitrarily in the expression (except within variables)to improve readability.
### Explanation of Sample
In the first and second cases, the first 4 performing sets, in order, are {1,2}, {1, 3}, {1, 2, 3}, and {4}, with values of 6, 10, 14, and 16 respectively.
1234567891011121314151617181920Case #1: 6Case #2: 14Case #3: 4Case #4: 2Case #5: 508Case #6: 2Case #7: 6Case #8: 510Case #9: 26Case #10: 98Case #11: 878266293Case #12: 746859548Case #13: 7038259Case #14: 454681413Case #15: 138253392Case #16: 299215939Case #17: 646605572Case #18: 783424637Case #19: 873419939Case #20: 959061046123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657<p>Mr. Fox is going on a trip to Scotland to witness its many beautiful lochs! He's heard that skimboarding is a fun pastime, somewhat similar to surfing, and he'd like to give it a try while he's there.</p>
<p>He soon finds himself on a flat beach by the side of a loch. The beach can be represented by an infinite 2D plane, with <strong>N</strong> axis-aligned rectangular pools of shallow water on it. The <strong>i</strong>th pool has a pair of opposite corners at coordinates (<strong>x<sub>1</sub></strong>, <strong>y<sub>1</sub></strong>) and (<strong>x<sub>2</sub></strong>, <strong>y<sub>2</sub></strong>). All of the pools can arbitrarily overlap with one another, the result being that there's shallow water everywhere within the union of the pools' rectangles (including right on its edges), and no water anywhere else (Mr. Fox isn't brave enough to venture into the loch itself yet!).</p>
<p>Mr. Fox would like to get a running start and then launch himself across the water at some location, skimboarding across the pools in a straight line until he hits a point with no water. In other words, his skimboarding debut will consist of a line segment contained within the union of the pools' rectangles (inclusive of borders). What's the maximum length this line segment can have?</p>
<h3>Input</h3><p>Input begins with an integer <strong>T</strong>, the number of places Mr. Fox goes skimboarding.For each place, there is first a line containing the integer <strong>N</strong>. Then <strong>N</strong> lines follow, the <strong>i</strong>th of which contains the space-separated integers<strong>x<sub>1</sub></strong>, <strong>y<sub>1</sub></strong>, <strong>x<sub>2</sub></strong>, and <strong>y<sub>2</sub></strong>.</p>
<h3>Output</h3><p>For the <strong>i</strong>th place, print a line containing "Case #<strong>i</strong>: " followed bythe length of longest possible skimboarding path rounded to 6 decimal places.</p>
<p>Absolute errors of up to 2e-6 will be ignored.</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 20 <br />1 ≤ <strong>N</strong> ≤ 20 <br />-1,000,000 ≤ <strong>x<sub>1</sub></strong> < <strong>x<sub>2</sub></strong> ≤ 1,000,000 <br />-1,000,000 ≤ <strong>y<sub>1</sub></strong> < <strong>y<sub>2</sub></strong> ≤ 1,000,000 <br /></p>
<h3>Explanation of Sample</h3><p>In the first case, (2, 0) to (5, 5) is an optimal path.</p>
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812022 0 4 33 2 5 510 0 3 430 0 3 20 1 3 30 2 3 430 0 1 12 0 4 25 0 8 33-3 -3 3 3-2 -2 2 2-1 -1 1 120 0 3 70 0 6 330 0 1 11 1 2 22 2 3 330 0 1 51 5 2 100 10 1 1520-286959 -309830 334986 31073733558 -723747 52007 -389359-268327 -620833 82947 -478539-152349 -646539 -4651 -257395-503006 -723965 -401305 -650415151877 90069 803553 170528-111556 74872 395038 200804-642206 -690890 -485591 -630053-858953 -421459 -788731 -165102-392378 -786805 156551 -591853-383323 -501911 180233 107362-454245 -457792 -434302 -24990-148004 -843252 97841 -468546-701841 -388101 -195752 -273116-559696 -394542 -317264 283349118386 -157347 302171 142939-739140 -571503 -103371 -221701-838348 -67776 -576656 -19-205798 -548617 323327 -119097-315029 -201609 45362 47427220-56698 -76497 229042 -49564-468342 74546 -358948 2372527070 -242470 140836 -214080-166709 98233 -143885 178953-474396 -147112 -443646 -7063965062 -466898 386507 -435564-325446 -371266 8155 -339461-145641 86478 33245 4177121412 58495 265795 325852-200837 -387826 95655 -126137-349463 -478682 -250910 -365103-376558 -301409 -330534 4060-340910 -24425 -336269 79805-342914 85227 -198322 386595-162775 -74349 83589 -25287-491645 -453352 -185269 -156616-217061 -484110 13086 -476098-351803 -20542 -201697 187589-172586 -338264 53442 -197491-110964 -341694 209002 -12006820-9072 -248220 83415 -203481-170983 -316985 16689 -267759-171040 -139842 -144962 -26127-268542 28784 -167429 144428-271051 66459 -161643 106674-324382 33354 -251785 94597-106430 -83021 82658 3095735223 -329483 248486 -99458-35622 -114816 49117 118263-332013 -2285 -176099 218858-122000 -184394 -78831 -35414-134236 -80732 37417 -53269-324531 -22448 -228942 191073-216533 -223571 -96868 -38054-289292 -35608 -191713 41863-196386 -300406 -59213 -225864-113985 4446 108796 21078513025 -232421 161903 -75201-71335 4779 -58763 7346536680 -232827 136759 -99643205579 -246611 32830 -113542-93905 -232057 -39380 -199416-154243 25712 -17335 102898-249508 -24333 -167958 49577-135636 -231069 -89903 -131140-191417 -94448 -87629 -7193710274 -197755 89917 -8721014739 -209727 168254 -96253-228532 -115472 -202255 39421-197083 -47195 -116247 2423425944 -78346 34459 -71634-202746 -122860 -150961 -55443-204969 -129370 -73072 3439913023 -138975 75333 -690867099 40102 11815 183412-241157 -8200 -103580 -2399-84614 -15688 72061 158538-52888 -19329 -3013 85879-208920 -23497 -94905 63983-205259 10742 -138022 15667020-147440 -178232 -29838 -157769-192795 -193111 -179992 -64460-52052 25852 -35729 73137-189013 -83926 -144121 27031-167256 -76822 -65383 1552-102965 -97543 10034 -84305-190814 -160649 -123915 -2462020799 -58018 61773 -21843-80004 35359 -18846 145438-51745 -20134 33773 45507-13672 -35014 85518 47094-103513 -27412 -96996 -6257-87270 -13638 24988 50441-137356 -162232 -107018 -160117-1878 -167191 14278 -44636-50105 -41441 35376 69976-105041 -45907 4214 51770-160512 17115 -110644 26204-190316 -163258 -159765 -45180-170333 -94239 -54171 835220-17455 -74758 36301 8458-116932 -29616 -86407 -14124-102390 -105717 -36616 -92015-46311 -80330 25809 -1681-59512 -3365 -28955 79789-159133 -53948 -94500 -48983-7897 -11787 27456 670797640 -159791 57214 -109531-104552 -138433 -101879 -47182-129159 -80554 -18336 -3705210858 -110133 23607 -3947-70012 -49126 -21294 -1865-136528 31026 -78300 41005-29498 -969 -3260 54784-14159 -149687 38880 -133605-70323 15009 14200 45372-113458 -55704 -112510 -2456523826 -11480 46306 41872-40612 -91079 59178 5869-15838 -166587 -8220 -16458720-17572 -53841 -181 3051-20709 -131747 -8694 -88323-22701 9893 43653 77685-126897 24627 -109680 57123-103003 -49152 -23091 -25020-84271 -88731 15354 -81316-24434 -108880 3060 -19269-55147 -40417 -14478 -22457-64899 -127179 -59272 -114018-102804 -110689 -72485 -94457-7751 2228 1307 6539724055 19982 52083 51941-8345 -27087 5629 282-83445 -116242 -58723 -75591-48987 -94471 -19733 -52461-22666 -142121 40579 -50429-98752 -93233 -86806 -76446-55080 -111344 -29543 -100929-17838 -50404 65601 -12087-95013 -23764 -46180 2908520-87550 -101178 -51779 -99855-9766 -38636 41757 -1116622762 -65842 73389 -18143-23117 1473 -5446 60301-8146 -30366 6864 -21041-7616 11491 48692 76162-53000 -34734 -20977 19735-3691 -88225 11252 -6150-19468 12823 13191 40608-59210 13809 16067 18458-99759 -58683 -18285 -8418-82595 5044 -79233 13699-124017 -32968 -55394 -2289316418 -89047 47872 -55673-79007 -65672 -71587 -54575-111743 19148 -69193 19263-103893 -21530 -18622 3716921799 -120029 87722 -117247-74348 -38929 -19163 1216317077 -50400 77264 3033120-56640 -8303 15376 62896-27746 -86147 -2573 -8422-63624 -69749 -15681 -247687611 -68224 79058 -47319-32360 -27295 -1703 -21666527 -4517 70622 13555124 -14917 17478 599632290 6420 29184 77225-2998 -81277 34722 -424631197 -65052 42889 -519516031 -109329 37529 -663466022 -102492 61782 -727637297 -75249 74658 -798016290 -28199 47092 46586-53286 -95120 -35670 -35681-10628 3751 36173 1471212704 -7833 69424 37141-44089 -88604 -10643 -738029538 -102748 85961 -80402-9780 -29025 64016 -357020-48533 -8968 -22352 46291-88263 -62589 -45656 -60097-54735 1230 -6907 14679-56687 6797 -20806 50977-2399 -89810 47880 -20712-1648 -89075 37023 -48638-98627 -6831 -96537 27407-685 -48031 53809 2301-70452 -38969 -42920 -35580-82666 -55649 -37460 -4001-72750 -92869 -59839 -594642873 4631 72004 527452393 9971 48670 64638-24002 -70573 -22003 -25585-61524 -82097 -38016 -46947-23737 13271 40241 38043-76971 -43961 -55528 6815-65252 -93 -20706 26810-64026 8111 -26672 2610113923 -79634 74725 -7137820-76912 -48008 -65471 -26195-74401 -71091 -40758 -15699-86942 -749 -66637 45740-72617 -33078 -27480 -30641911 -12941 1636 39602-87746 -45994 -37784 11359-85385 -7190 -39515 -1582-51334 -54155 -20347 -478-35514 -62145 -18819 -12539-29588 14631 -23940 68827-9643 -55660 -3198 -20861-38674 -13854 -18982 15986-28253 4686 -17157 51408-65274 13567 -41888 59376-6352 -23950 37207 98-44782 -77533 -40738 -76307-4536 -67308 26807 -6150814894 -84834 40902 -798283434 -26027 50346 -15738-13336 -76227 -7978 -3162720-27361 -74150 -7367 -53554-3283 -79619 36724 -73508-34876 -8866 -25718 33301-64304 -57439 -14760 -11866-21065 -14369 -10867 42597-70002 -28140 -67632 -26453-70686 -27308 -52392 -621411979 -78639 39735 -44027-30308 2134 9087 21944-17073 -1104 38844 21617-22661 9895 -19355 53076-58070 -5105 -41902 -2664-6487 -4027 8257 33446-22206 -30805 878 -5010-30766 -36212 -3548 -29303-51240 -44079 3373 -24353-33817 -76274 -18268 -54160-37690 -29943 -4121 970-44221 -53656 4794 -19338-689 -26180 4766 283721234567891011121314151617181920212223242526272829303132333435363738394041424344Mr. Fox is going on a trip to Scotland to witness its many beautiful lochs!He's heard that skimboarding is a fun pastime, somewhat similar to surfing,and he'd like to give it a try while he's there.
He soon finds himself on a flat beach by the side of a loch. The beach can berepresented by an infinite 2D plane, with **N** axis-aligned rectangular poolsof shallow water on it. The **i**th pool has a pair of opposite corners atcoordinates (**x1**, **y1**) and (**x2**, **y2**). All of the pools canarbitrarily overlap with one another, the result being that there's shallowwater everywhere within the union of the pools' rectangles (including right onits edges), and no water anywhere else (Mr. Fox isn't brave enough to ventureinto the loch itself yet!).
Mr. Fox would like to get a running start and then launch himself across thewater at some location, skimboarding across the pools in a straight line untilhe hits a point with no water. In other words, his skimboarding debut willconsist of a line segment contained within the union of the pools' rectangles(inclusive of borders). What's the maximum length this line segment can have?
### Input
Input begins with an integer **T**, the number of places Mr. Fox goesskimboarding. For each place, there is first a line containing the integer**N**. Then **N** lines follow, the **i**th of which contains the space-separated integers **x1**, **y1**, **x2**, and **y2**.
### Output
For the **i**th place, print a line containing "Case #**i**: " followed by thelength of longest possible skimboarding path rounded to 6 decimal places.
Absolute errors of up to 2e-6 will be ignored.
### Constraints
1 ≤ **T** ≤ 20 1 ≤ **N** ≤ 20 -1,000,000 ≤ **x1** < **x2** ≤ 1,000,000 -1,000,000 ≤ **y1** < **y2** ≤ 1,000,000
### Explanation of Sample
In the first case, (2, 0) to (5, 5) is an optimal path.
1234567891011121314151617181920Case #1: 5.830952Case #2: 5.000000Case #3: 5.000000Case #4: 4.242641Case #5: 8.485281Case #6: 8.750000Case #7: 4.242641Case #8: 15.000000Case #9: 1439133.979724Case #10: 884005.747931Case #11: 650595.679101Case #12: 406740.250958Case #13: 375892.303625Case #14: 261653.376275Case #15: 223308.221962Case #16: 200551.423396Case #17: 214887.140352Case #18: 172942.536512Case #19: 131482.402853Case #20: 129424.5762941234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374<p>Mr. Fox has just won the lottery! As a result, he's treated himself to some gifts — a few socks, a few rocks, a few blocks... oh, and the entire Panama canal system.</p>
<p>The system has <strong>K</strong> canals, the <strong>i</strong>th of which consists of a line of <strong>N<sub>i</sub></strong> equally-sized sections. The <strong>j</strong>th section of the <strong>i</strong>th canalinitially contains <strong>W<sub>i,j</sub></strong> gallons of water. There's also an initially closed lock (a retractable wall) betweeneach pair of adjacent sections (that is, between sections 1 and 2, sections 2 and 3, and so on). As such, there are <strong>N<sub>i</sub></strong>-1 such locks in the <strong>i</strong>th canal.</p>
<p>The canals are all linked to each other by an additional central hub section (also of equal size to the other sections), which initially contains <strong>H</strong> gallons of water. This section is adjacent to the 1st section of each of the canals, separated by a special initially closed lock. As such, there are <strong>K</strong> such central locks.</p>
<p>Mr. Fox is relaxing in a yacht (oh, right, he also bought himself one of those) floating in the central hub section. Just for fun, he'd like to raise the water level in this section as high as possible. To do so, he may give any (potentially empty) sequence of commands to his Panama employees, one per minute. Each command consists of selecting a single lock anywhere in the canal system and toggling it from being closed to being open (or vice versa). In the following minute, the water will level out (as water tends to do) byflowing through open locks such that, for any pair of adjacent sections which are separated by an open lock, they will end up with equalamounts of water. Mr. Fox does need to obey the Panama canal system's safety regulations, however, which impose one restriction on hiscommands: whenever one of the <strong>K</strong> central locks adjacent to the central hub section is opened, it must be closed aminute later and then never re-opened.</p>
<p>Mr. Fox loves watching water flow through his locks, especially when it allows his yacht to magically rise up. Wheeeee! By commanding his employees carefully, how much water can Mr. Fox get into the central hub section?</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 20 <br/>1 ≤ <strong>K</strong> ≤ 50 <br/>0 ≤ <strong>H</strong> ≤ 10^9 <br/>1 ≤ <strong>N<sub>i</sub></strong> ≤ 100,000 <br/><strong>N<sub>i</sub></strong> > 1 implies <strong>N<sub>i+1</sub></strong> ≥ 2*<strong>N<sub>i</sub></strong> (for 1 ≤ <strong>i</strong> < <strong>K</strong>) <br/>0 ≤ <strong>W<sub>i,j</sub></strong> ≤ 10^9 <br/></p>
<h3>Input</h3><p>Input begins with an integer <strong>T</strong>, the number of canal systems Mr. Fox owns.For each system, there is first a line containing the space-separated integers <strong>K</strong> and <strong>H</strong>.Then, <strong>K</strong> lines follow, the <strong>i</strong>th of which contains the integer <strong>N<sub>i</sub></strong>followed by the space-separated integers <strong>W<sub>i,1</sub></strong> ... <strong>W<sub>i,N<sub>i</sub></sub></strong>.</p>
<h3>Output</h3><p>For the <strong>i</strong>th canal system, print a line containing "Case #<strong>i</strong>: " followed bythe maximum amount of water (in gallons) that can end up in the central hub section, rounded to 6 decimal places.</p>
<p>Absolute errors of up to 5e-6 will be ignored.</p>
<h3>Explanation of Sample</h3><p>In the first case, the optimal solution is to first open and close the lock between the central hub and canal 1.This leaves the central hub with 0.5 gallons of water. Then, opening the lock between the central hub and canal 2 leaves the central hubwith 1.25 gallons of water.</p>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667Mr. Fox has just won the lottery! As a result, he's treated himself to somegifts — a few socks, a few rocks, a few blocks... oh, and the entire Panamacanal system.
The system has **K** canals, the **i**th of which consists of a line of **Ni**equally-sized sections. The **j**th section of the **i**th canal initiallycontains **Wi,j** gallons of water. There's also an initially closed lock (aretractable wall) between each pair of adjacent sections (that is, betweensections 1 and 2, sections 2 and 3, and so on). As such, there are **Ni**-1such locks in the **i**th canal.
The canals are all linked to each other by an additional central hub section(also of equal size to the other sections), which initially contains **H**gallons of water. This section is adjacent to the 1st section of each of thecanals, separated by a special initially closed lock. As such, there are **K**such central locks.
Mr. Fox is relaxing in a yacht (oh, right, he also bought himself one ofthose) floating in the central hub section. Just for fun, he'd like to raisethe water level in this section as high as possible. To do so, he may give any(potentially empty) sequence of commands to his Panama employees, one perminute. Each command consists of selecting a single lock anywhere in the canalsystem and toggling it from being closed to being open (or vice versa). In thefollowing minute, the water will level out (as water tends to do) by flowingthrough open locks such that, for any pair of adjacent sections which areseparated by an open lock, they will end up with equal amounts of water. Mr.Fox does need to obey the Panama canal system's safety regulations, however,which impose one restriction on his commands: whenever one of the **K**central locks adjacent to the central hub section is opened, it must be closeda minute later and then never re-opened.
Mr. Fox loves watching water flow through his locks, especially when it allowshis yacht to magically rise up. Wheeeee! By commanding his employeescarefully, how much water can Mr. Fox get into the central hub section?
### Constraints
1 ≤ **T** ≤ 20 1 ≤ **K** ≤ 50 0 ≤ **H** ≤ 10^9 1 ≤ **Ni** ≤ 100,000 **Ni** > 1 implies **Ni+1** ≥ 2***Ni** (for 1 ≤ **i** < **K**) 0 ≤ **Wi,j** ≤ 10^9
### Input
Input begins with an integer **T**, the number of canal systems Mr. Fox owns.For each system, there is first a line containing the space-separated integers**K** and **H**. Then, **K** lines follow, the **i**th of which contains theinteger **Ni** followed by the space-separated integers **Wi,1** ...**Wi,Ni**.
### Output
For the **i**th canal system, print a line containing "Case #**i**: " followedby the maximum amount of water (in gallons) that can end up in the central hubsection, rounded to 6 decimal places.
Absolute errors of up to 5e-6 will be ignored.
### Explanation of Sample
In the first case, the optimal solution is to first open and close the lockbetween the central hub and canal 1. This leaves the central hub with 0.5gallons of water. Then, opening the lock between the central hub and canal 2leaves the central hub with 1.25 gallons of water.
1234567891011121314151617181920Case #1: 1.250000Case #2: 7.500000Case #3: 9.428571Case #4: 9.100000Case #5: 121.465278Case #6: 7.272727Case #7: 9.500000Case #8: 977326399.687126Case #9: 960513538.070536Case #10: 933171236.379669Case #11: 916380015.475403Case #12: 978947197.076133Case #13: 959541028.712926Case #14: 939205642.630288Case #15: 935796566.343075Case #16: 992620512.365391Case #17: 944841437.133588Case #18: 978504891.417060Case #19: 980182123.567300Case #20: 975118031.550553123456789101112131415161718192021222324252627282930313233343536373839404142434445<p>Every business can make use of a good accountant and, if they're not big on following the law, sometimes a bad one.Bad accountants try to make more money for their employers by fudging numbers without getting caught. </p>
<p>Sometimes a bad accountant wants to make a number larger, and sometimes smaller.It is widely known that tax auditors will fail to notice two digits being swapped in any given number,but any discrepancy more egregious will certainly be caught. It's also painfully obvious when anumber has fewer digits than it ought to, so a bad accountant will never swap the first digit of a numberwith a 0.</p>
<p>Given a number, how small or large can it be made without being found out?</p>
<h3>Input</h3>
<p>Input begins with an integer <strong>T</strong>, the number of numbersthat need tweaking. Each of the next <strong>T</strong> lines contains a integer <strong>N</strong>.</p>
<h3>Output</h3>
<p>For the <em>i</em>th number, print a line containing "Case #<em>i</em>: " followed by the smallest and largestnumbers that can be made from the original number <strong>N</strong>, using at most a single swap and following therules above.</p>
<h3>Constraints</h3>
<p>1 ≤ <strong>T</strong> ≤ 100 <br />0 ≤ <strong>N</strong> ≤ 999999999 <br /><strong>N</strong> will never begin with a leading 0 unless <strong>N</strong> = 0<br /></p>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011003152489712310599999999901099909999392145027734521111421551006042316728574120482876891594229318957281540349262880773800454768698417564729563286795482732458522279688816290675530868627782071817910198360661217272099643853630067590596718317732334411536122973549462671381531546657218992305715842108751964411462388568647078002290009020504349673301819730951240587315664387142977752240021033902754822906039147069557347471225940888682421679318931414673957961734393698191208297360134351747331343270731407053764921681621007349218198062327532194420150411555305341813552593422446564760186902676168149760966372414439130426294655612982820715607545178093749039533474867873994967987877115755572373221102163946763307818571198404469689830411524629197557112729970282237348734699523404445587276919176173630335263646698748643294931413825592106130640187092376660869123456789101112131415161718192021222324252627282930Every business can make use of a good accountant and, if they're not big onfollowing the law, sometimes a bad one. Bad accountants try to make more moneyfor their employers by fudging numbers without getting caught.
Sometimes a bad accountant wants to make a number larger, and sometimessmaller. It is widely known that tax auditors will fail to notice two digitsbeing swapped in any given number, but any discrepancy more egregious willcertainly be caught. It's also painfully obvious when a number has fewerdigits than it ought to, so a bad accountant will never swap the first digitof a number with a 0.
Given a number, how small or large can it be made without being found out?
### Input
Input begins with an integer **T**, the number of numbers that need tweaking.Each of the next **T** lines contains a integer **N**.
### Output
For the _i_th number, print a line containing "Case #_i_: " followed by thesmallest and largest numbers that can be made from the original number **N**,using at most a single swap and following the rules above.
### Constraints
1 ≤ **T** ≤ 100 0 ≤ **N** ≤ 999999999 **N** will never begin with a leading 0 unless **N** = 0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100Case #1: 13524 51324Case #2: 798 987Case #3: 123 321Case #4: 10 10Case #5: 5 5Case #6: 999999999 999999999Case #7: 0 0Case #8: 10 10Case #9: 9099999 9999990Case #10: 139294502 993214502Case #11: 173452117 775432111Case #12: 102155104 542151100Case #13: 104236672 704231662Case #14: 157482048 887412045Case #15: 187689259 987689152Case #16: 122934895 922931845Case #17: 128754034 827154034Case #18: 226988077 986282077Case #19: 300845476 830045476Case #20: 169848756 968841756Case #21: 272956348 972456328Case #22: 27954867 97654827Case #23: 224585223 824535222Case #24: 196888762 976888162Case #25: 306755908 986755300Case #26: 286277860 886277620Case #27: 118179107 918177101Case #28: 183606692 986606312Case #29: 102727996 972720916Case #30: 338536400 834536300Case #31: 575906967 975905667Case #32: 113877323 813177323Case #33: 144115363 644115331Case #34: 223795494 929735424Case #35: 126713865 826713615Case #36: 135466572 715466532Case #37: 109923857 989123057Case #38: 108421587 858421017Case #39: 119644154 915644114Case #40: 263885686 823885666Case #41: 27078004 87074002Case #42: 200009029 990002020Case #43: 304349675 904345673Case #44: 101839730 901813730Case #45: 15924058 98124055Case #46: 137566438 831566437Case #47: 17429777 91427777Case #48: 122400250 542200210Case #49: 239037548 933027548Case #50: 129060392 929060321Case #51: 370695574 970645573Case #52: 174742259 974712254Case #53: 208886844 808886424Case #54: 116793289 916793182Case #55: 114346739 914146733Case #56: 17965734 97561734Case #57: 193698193 993698131Case #58: 200297368 908227360Case #59: 114353747 734351741Case #60: 133343270 731343230Case #61: 137407053 771403053Case #62: 164921687 964721681Case #63: 126007349 921007346Case #64: 118298062 918128062Case #65: 12753239 92753213Case #66: 142015044 542014041Case #67: 105535534 555530134Case #68: 118355259 981355251Case #69: 242344656 642244653Case #70: 176048690 976018640Case #71: 16761682 86761621Case #72: 397609664 997604663Case #73: 124144397 924144371Case #74: 20426394 90426234Case #75: 155662982 955612682Case #76: 120785607 870715602Case #77: 145578093 945178053Case #78: 349039537 949037533Case #79: 374867874 874867473Case #80: 499967987 999967487Case #81: 177185755 877715155Case #82: 172373225 772353221Case #83: 101263946 902163146Case #84: 163307878 863307817Case #85: 171598404 971158404Case #86: 369689840 969684830Case #87: 114524629 911524624Case #88: 117557192 917557112Case #89: 229970287 929770282Case #90: 23334877 83734273Case #91: 269954340 969452340Case #92: 244558747 844554727Case #93: 191917667 991617617Case #94: 263033536 663033523Case #95: 344669876 964663874Case #96: 26438949 96432948Case #97: 114338255 814133255Case #98: 12106930 96102130Case #99: 140687092 940187062Case #100: 306667869 9766608631234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768<p>Standard mazes lose their mystery as one grows older. But throw in some lasers,and suddenly you've got yourself a recipe for cross-generational appeal.The object in any maze is to find your way from your starting point to somegoal. In a <em>Laser Maze</em> you must additionally contend with laser turrets.</p>
<p>A laser turret is a stationary pillar that both blocks your movement and fireslasers from one side. Every time you take a step (either up, down, left, or right), every laser turret in the maze thenrotates 90 degrees clockwise, and then shoots a momentary laser blast in the direction that itis facing. Needless to say, if you find yourself in the path of one of theselasers, you won't be around long enough to find a way out. A wall is a stationary pillar thatblocks your movement, but does not fire lasers.</p>
<p>Lasers are powerful, but they do not pass through walls or laser turrets.The laser turrets respond to your movements, so you can't stand still and waitfor the turrets to turn. If you reach the goal, but are immediately shot by alaser, your efforts will have been in vain, so make sure you reach the goalsafely.</p>
<h3>Input</h3>
<p>Input begins with an integer <strong>T</strong>, the number of mazesyou'll explore. For each maze, there is first a line containing two integers,<strong>M</strong> and <strong>N</strong>, the height and width of the maze,respectively. The next <strong>M</strong> lines contain <strong>N</strong> characters each, describing the maze:</p>
<p>. (empty space) <br /># (wall) <br />S (starting position) <br />G (goal) <br />< > ^ v (laser turrets) <br /></p>
<p>The four symbols for laser turrets signify turrets that are initially pointingleft, right, up, or down respectively before you take your first step.</p>
<h3>Output</h3>
<p>For the <em>i</em>th maze, print a line containing "Case #<em>i</em>: " followed bythe smallest number of steps necessary to get to the exit without beinghit by a laser, or the string "impossible'' if there is no way to reach thegoal safely.</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 100 <br />1 ≤ <strong>M</strong>, <strong>N</strong> ≤ 100 <br />Each maze will contain exactly one 'S' and exactly one 'G'.</p>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748Standard mazes lose their mystery as one grows older. But throw in somelasers, and suddenly you've got yourself a recipe for cross-generationalappeal. The object in any maze is to find your way from your starting point tosome goal. In a _Laser Maze_ you must additionally contend with laser turrets.
A laser turret is a stationary pillar that both blocks your movement and fireslasers from one side. Every time you take a step (either up, down, left, orright), every laser turret in the maze then rotates 90 degrees clockwise, andthen shoots a momentary laser blast in the direction that it is facing.Needless to say, if you find yourself in the path of one of these lasers, youwon't be around long enough to find a way out. A wall is a stationary pillarthat blocks your movement, but does not fire lasers.
Lasers are powerful, but they do not pass through walls or laser turrets. Thelaser turrets respond to your movements, so you can't stand still and wait forthe turrets to turn. If you reach the goal, but are immediately shot by alaser, your efforts will have been in vain, so make sure you reach the goalsafely.
### Input
Input begins with an integer **T**, the number of mazes you'll explore. Foreach maze, there is first a line containing two integers, **M** and **N**, theheight and width of the maze, respectively. The next **M** lines contain **N**characters each, describing the maze:
. (empty space) # (wall) S (starting position) G (goal) < > ^ v (laser turrets)
The four symbols for laser turrets signify turrets that are initially pointingleft, right, up, or down respectively before you take your first step.
### Output
For the _i_th maze, print a line containing "Case #_i_: " followed by thesmallest number of steps necessary to get to the exit without being hit by alaser, or the string "impossible'' if there is no way to reach the goalsafely.
### Constraints
1 ≤ **T** ≤ 100 1 ≤ **M**, **N** ≤ 100 Each maze will contain exactly one 'S' and exactly one 'G'.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100Case #1: 6Case #2: 4Case #3: 3Case #4: impossibleCase #5: 8Case #6: impossibleCase #7: 1Case #8: impossibleCase #9: 4Case #10: 7Case #11: 19Case #12: 8Case #13: 18Case #14: 27Case #15: 19Case #16: 27Case #17: 24Case #18: 20Case #19: impossibleCase #20: 62Case #21: 38Case #22: 48Case #23: 43Case #24: 3Case #25: 27Case #26: impossibleCase #27: 35Case #28: 65Case #29: 34Case #30: 53Case #31: 14Case #32: 17Case #33: 53Case #34: impossibleCase #35: 38Case #36: 1Case #37: 44Case #38: 63Case #39: impossibleCase #40: 30Case #41: 46Case #42: 12Case #43: 56Case #44: 30Case #45: 39Case #46: 14Case #47: 110Case #48: impossibleCase #49: 87Case #50: 31Case #51: 17Case #52: 6Case #53: impossibleCase #54: 9Case #55: impossibleCase #56: 4Case #57: impossibleCase #58: 65Case #59: 18Case #60: 58Case #61: 105Case #62: 12Case #63: 22Case #64: 53Case #65: impossibleCase #66: 125Case #67: impossibleCase #68: 53Case #69: 54Case #70: impossibleCase #71: impossibleCase #72: 41Case #73: 68Case #74: 71Case #75: 76Case #76: 14Case #77: 16Case #78: 78Case #79: impossibleCase #80: impossibleCase #81: impossibleCase #82: impossibleCase #83: 99Case #84: 56Case #85: 143Case #86: impossibleCase #87: impossibleCase #88: 11Case #89: impossibleCase #90: 15Case #91: 118Case #92: 36Case #93: 99Case #94: 101Case #95: 141Case #96: impossibleCase #97: 24Case #98: 14Case #99: 117Case #100: impossible1234567891011121314151617181920212223242526272829303132333435363738394041<p>Alex's New Year's resolution for 2015 is to eat healthier foods. He's done someresearch and has found out that calories come from three main sources, calledmacronutrients: protein, carbohydrates, and fat. Alex wants to get the rightbalance of protein, carbohydrates, and fat to have a balanced diet.For each available food, Alex can only choose to eat it or not eat it. Hecan't eat a certain food more than once, and he can't eat a fractional amountof a food.</p>
<h3>Input</h3>
<p>Input begins with an integer <strong>T</strong>, the number of test cases. For each test case, the first line consists of three space-separatedintegers: <strong>G<sub>P</sub></strong>, <strong>G<sub>C</sub></strong>, and <strong>G<sub>F</sub></strong>, which represent the amount ofprotein, carbohydrates, and fat that Alex wants to eat. The next line has the number of foods for that test case, an integer <strong>N</strong>. The next <strong>N</strong> lines each consist of three space-separated integers: <strong>P</strong>, <strong>C</strong>, and <strong>F</strong>,which represent the amount of protein, carbohydrates, and fat in that food, respectively.</p>
<h3>Output</h3>
<p>For each test case <em>i</em>, print a line containing "Case #<em>i</em>: " followed byeither "yes" if it is possible for Alex to eat the exact amount of eachmacronutrient, or "no" if it is not possible.</p>
<h3>Constraints</h3>
<p>1 ≤ <strong>T</strong> ≤ 20 <br/>1 ≤ <strong>N</strong> ≤ 20 <br/>10 ≤ <strong>G<sub>P</sub></strong>, <strong>G<sub>C</sub></strong>, <strong>G<sub>F</sub></strong> ≤ 1000 <br/>10 ≤ <strong>P</strong>, <strong>C</strong>, <strong>F</strong> ≤ 1000 <br/></p>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100648100 100 1001100 100 100100 100 100310 10 4010 30 1010 60 50100 100 100540 70 3030 10 4020 20 5010 50 9040 10 20292 264 51220909 302 261705 597 823291 51 12628 697 57593 31 826311 256 57292 14 4729 730 71612 529 146768 16 43937 472 15350 192 34163 468 23869 173 10203 72 690424 875 213223 593 292151 46 1088 90 16773 653 711991 827 3522029 560 929139 681 102144 853 1084 729 80218 20 67140 80 901428 20 500520 970 128422 419 30413 101 192467 448 50132 939 68434 20 38251 317 132588 437 10648 21 79391 25 14499 22 24854 77 361405 25 20905 801 6862096 702 733255 767 766813 66 80561 418 21637 778 95765 818 433869 761 45270 635 304623 356 44871 407 1312 303 607972 148 951374 280 16179 191 58338 552 1922 91 66243 981 1013 171 86491 11 129168 728 757686 595 7220484 559 115352 42 89244 674 953686 616 366992 981 409421 30 197744 359 16716 150 32750 518 235207 212 17720 430 588551 690 97025 238 40844 14 14068 708 337235 952 28368 851 12021 790 505275 336 987131 552 16788 804 78120447 71 70274 994 525577 199 427543 963 263438 11 11484 844 3854 125 371123 10 217797 403 1841 527 163487 10 17116 762 91210 932 68694 118 222759 10 22670 917 553107 871 413119 82 410614 472 670230 100 99868 903 7892012 103 782696 535 181632 98 10154 74 99810 240 30095 10 69826 196 686384 930 41412 163 161163 38 440422 15 637355 25 10740 26 930277 740 302328 129 13520 714 25039 730 61822 578 333639 23 10485 16 75588 838 67820314 743 943659 696 1010 10 352223 53 91733 594 19384 64 48715 11 770569 639 471590 613 747777 99 21712 666 132396 456 914186 72 157505 952 153143 56 197380 988 876869 213 67276 388 74468 504 684833 56 709861 761 4362053 70 126176 143 95758 312 907409 183 29887 63 355781 941 21235 192 35843 20 93106 138 551196 10 576195 875 263213 449 401639 73 934655 222 9853 71 141537 976 662669 26 11294 729 93436 17 15246 341 467401 536 64620706 58 26248 13 296716 181 18273 362 14642 629 45174 37 1361 486 435742 480 405353 14 54166 119 60714 408 18112 425 17121 661 194327 499 63311 234 10314 624 86114 491 84482 610 8815 19 72211 293 688734 644 88720676 968 23946 215 329122 851 31219 99 845311 57 422229 117 452114 78 48329 388 63855 924 12335 774 659463 361 424308 947 550191 252 23910 245 760133 369 824860 193 53010 485 782487 197 15852 61 373118 426 365827 994 94020262 846 39019 543 52839 400 40523 859 592420 513 357562 331 218497 141 492748 632 52415 722 4880 521 176815 533 62508 51 17119 291 136674 895 157325 10 62209 362 43912 50 1088 373 71113 58 274287 342 443201 548 84720216 624 923662 104 10910 123 865577 48 802109 200 929411 12 198162 13 43544 150 494156 746 353146 25 12650 42 16747 210 189244 40 83368 16 942606 203 44213 908 775276 35 401384 559 659657 43 21629 210 622812 491 53420663 690 103165 644 33449 26 10267 184 231242 323 17131 273 777549 35 588824 28 53553 68 206772 97 6421 698 55831 10 84910 261 792836 756 11403 860 794670 234 13196 646 532841 396 370994 67 441108 84 243601 522 59720107 130 37748 878 702250 217 15102 122 80271 229 51072 30 15422 124 414784 295 10550 564 649359 792 5795 12 248112 270 247446 281 6411 379 328918 147 824187 156 112114 28 48216 809 8319 64 123701 48 25985 848 92620179 356 1244 490 297126 181 5855 225 110321 99 486115 70 171602 187 844391 11 18853 76 20329 374 30778 959 34182 24 828318 296 43244 72 530161 730 76751 808 296487 54 106857 36 588231 12 118291 62 35415 542 4102022 585 1999 661 543173 46 1210 38 7374 598 7746 730 93549 950 123523 11 17747 751 281691 301 34374 48 608968 10 924400 484 90611 738 36298 270 12238 20 136314 818 666345 374 77472 301 517101 10 129181 750 8192060 10 576303 39 917158 159 4216 499 333115 959 782841 229 358142 10 742181 750 81953 588 951668 160 1810 66 238865 416 10374 107 988149 926 47059 223 91411 564 20123 24 2810 359 455818 159 841132 963 10552 962 91520213 199 214461 68 13463 907 73065 595 10224 466 531526 10 61057 10 181678 30 12511 536 368296 18 772254 10 495784 40 6512 63 668723 11 306255 706 292202 104 51141 46 500478 159 68344 319 28271 192 163524 829 4302045 392 93140 56 3029 42 621249 829 584886 53 26691 215 765174 160 47765 481 36762 239 74148 361 10950 657 39582 712 883202 21 249973 273 110123 277 87111 15 6765 192 182730 28 717168 952 72055 829 760390 818 74520208 14 139694 107 39523 987 1925 786 329493 104 401200 122 2350 386 241827 128 7345 961 682206 366 8615 71 28212 293 553650 454 495148 385 497392 968 334199 387 39973 51 280354 11 672493 127 17540 308 143425 837 6062036 382 976898 10 596773 773 287160 170 135166 13 340412 94 139441 348 778676 103 850134 37 24412 146 165542 14 623264 248 1089 71 18173 27 452340 222 22762 560 446139 245 4815 830 769774 655 30429 216 92459 394 6562042 63 38296 248 2681 18 12617 232 81683 539 847642 336 827449 20 40050 57 83523 301 69564 917 28647 366 151532 768 739812 402 741139 237 80455 148 357173 84 184284 92 851646 18 568318 656 760313 12 79740 805 93520671 884 37365 527 774619 185 48333 125 542355 739 513299 249 12238 247 66810 365 12215 744 212992 709 80620 368 520889 217 399528 547 355314 24 215130 363 807441 556 923477 124 172528 95 447389 129 28936 12 620393 821 88320389 586 269363 927 476156 65 85292 924 14640 332 572205 135 10169 62 351156 849 1035 18 438355 39 774478 477 44259 744 795188 213 13611 712 410703 728 36591 960 33336 157 517880 71 23253 46 520924 39 79292 381 5582010 38 21812 148 67310 471 330844 732 240406 298 322691 617 121752 545 241410 301 823155 641 273955 165 12184 320 6456 60 9318 48 239928 925 34308 625 18213 13 701630 13 212124 304 913289 242 458696 822 421708 39 46420691 490 3210 10 785130 230 9283 66 21730 106 57610 734 10870 193 173501 467 154873 696 10259 285 183205 26 42310 100 10544 920 63357 856 93503 13 41372 62 393438 181 35877 369 662636 897 27323 987 807669 872 6982031 186 451121 759 10517 497 500222 271 26570 347 5381 160 859349 182 365270 845 83949 430 36958 658 421672 117 151102 968 223245 365 12210 25 193672 34 26034 39 65990 163 3613 394 1010 166 5510 504 114291 999 57220514 631 123688 547 135822 542 5295 22 10025 100 38428 174 41337 474 15702 511 46510 26 742616 863 74815 850 707364 10 56348 43 225725 75 62991 270 10026 131 867168 803 59289 408 2370 54 234459 876 640713 395 7422023 71 10354 698 38138 691 86944 11 726166 974 477375 331 445426 182 17938 288 68510 371 43230 808 202955 279 805678 408 752430 62 748269 19 174636 317 203266 296 67613 582 811260 812 1143 805 113813 492 552536 749 7762055 10 724122 264 65410 980 98494 242 170159 814 813615 278 95251 298 381310 43 52735 913 69195 29 26615 324 26812 831 1119 148 1230 323 24417 186 702799 890 33879 615 470540 62 142206 132 220347 15 916397 405 83520335 775 229103 640 993166 43 570560 10 11359 73 39358 11 74163 342 886116 284 622415 788 10126 100 4523 606 19719 107 16013 328 856111 51 45112 32 22755 620 35710 685 618434 49 261615 10 94366 535 921382 993 45920917 103 568776 500 37218 900 1392 367 16803 755 41494 321 521746 421 216313 321 18628 147 561451 65 898747 179 336249 37 590397 166 431248 550 43342 76 1094 56 10353 963 11307 821 10029 994 478588 35 454197 605 39220291 432 777994 340 355166 146 272831 109 693226 501 21884 12 63290 181 10518 977 43146 558 526142 272 660439 315 28413 269 25492 164 320207 902 232137 529 535126 815 38874 450 917584 405 15010 224 589530 282 795771 534 96120291 72 44415 249 256192 25 311325 131 1066 10 67969 135 19360 43 129187 104 756105 226 694179 41 837359 762 422278 241 278534 53 29314 123 740820 299 60562 920 10017 16 21111 64 16125 562 929661 269 546330 906 8472039 716 70142 19 752683 311 640846 374 77314 818 12586 30 36188 887 95242 951 355255 112 650286 978 6415 73 4532 688 37690 481 831187 29 61236 860 147393 897 150558 717 77471 483 682582 108 65102 251 953658 874 11620201 149 22418 834 78941 90 2328 615 25435 144 568777 41 921129 375 447256 804 531439 63 10223 324 10554 204 977669 10 6623 99 12132 600 90302 77 38354 406 307328 182 5314 203 633914 978 14300 15 542410 787 59320157 816 30951 78 20281 125 72029 881 20591 476 664552 985 252414 753 5898 261 469684 57 494206 276 570233 731 65516 226 81428 617 242756 600 176292 259 708949 52 31211 452 87448 919 29120 20 20281 54 17212 742 8822060 808 88705 10 132473 456 113599 186 220182 932 3431 10 719132 843 813383 223 950326 68 61909 564 7432 175 784305 20 62280 193 919746 96 44197 209 10315 989 764320 37 281773 852 4411 920 679371 540 596978 383 5802058 445 25462 16 36444 639 3722 876 239437 128 293540 588 21304 22 249310 957 58729 589 1099 983 76396 49 987119 10 62654 53 10151 435 1513 300 449399 656 10210 158 322215 688 11210 116 576207 283 517826 133 22520109 598 886630 811 280463 241 444101 746 1014 847 92745 742 96110 720 111800 773 320391 13 234594 21 99232 112 126304 965 351907 46 310189 40 16839 80 443234 29 846647 40 56307 66 548407 93 878848 15 186861 317 8922018 145 886649 860 629155 836 119430 13 420712 461 98292 604 10304 69 68128 30 814138 217 72676 17 255332 399 820256 366 30907 304 18676 49 439796 289 27316 515 35510 10 223596 355 758429 218 10573 213 10855 390 62920387 456 303689 97 355440 293 29733 777 143148 769 21729 811 90717 954 233761 15 172102 38 2122 199 198614 916 62042 56 55603 32 829139 53 968689 168 6114 680 22952 147 134307 632 625290 57 77310 13 152828 683 56420526 612 93785 194 532729 56 19029 46 518363 18 13460 741 529321 353 87490 376 7111 391 8352 179 772832 292 690524 434 459571 38 1032 415 5896 352 80247 848 436980 73 621174 60 1060 339 25064 39 423737 308 8152011 117 7213 23 13220 939 229215 852 8820 563 36544 713 52498 626 33315 401 27035 232 110546 458 95525 351 19427 239 494675 206 3840 107 84416 69 753431 504 12333 10 11938 82 14151 186 974230 174 22861 695 6252010 77 445958 23 124398 967 1223 379 811714 78 38459 37 1613 569 71113 129 32688 20 215158 267 96823 123 170353 483 10964 560 1775 11 15421 356 12510 281 16760 157 65613 651 599888 314 10474 876 65912345678910111213141516171819202122232425262728293031Alex's New Year's resolution for 2015 is to eat healthier foods. He's donesome research and has found out that calories come from three main sources,called macronutrients: protein, carbohydrates, and fat. Alex wants to get theright balance of protein, carbohydrates, and fat to have a balanced diet. Foreach available food, Alex can only choose to eat it or not eat it. He can'teat a certain food more than once, and he can't eat a fractional amount of afood.
### Input
Input begins with an integer **T**, the number of test cases. For each testcase, the first line consists of three space-separated integers: **GP**,**GC**, and **GF**, which represent the amount of protein, carbohydrates, andfat that Alex wants to eat. The next line has the number of foods for thattest case, an integer **N**. The next **N** lines each consist of three space-separated integers: **P**, **C**, and **F**, which represent the amount ofprotein, carbohydrates, and fat in that food, respectively.
### Output
For each test case _i_, print a line containing "Case #_i_: " followed byeither "yes" if it is possible for Alex to eat the exact amount of eachmacronutrient, or "no" if it is not possible.
### Constraints
1 ≤ **T** ≤ 20 1 ≤ **N** ≤ 20 10 ≤ **GP**, **GC**, **GF** ≤ 1000 10 ≤ **P**, **C**, **F** ≤ 1000
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748Case #1: yesCase #2: noCase #3: yesCase #4: noCase #5: yesCase #6: yesCase #7: noCase #8: noCase #9: noCase #10: noCase #11: noCase #12: yesCase #13: yesCase #14: yesCase #15: noCase #16: noCase #17: noCase #18: noCase #19: noCase #20: yesCase #21: noCase #22: noCase #23: noCase #24: noCase #25: yesCase #26: yesCase #27: noCase #28: noCase #29: yesCase #30: noCase #31: yesCase #32: noCase #33: noCase #34: noCase #35: yesCase #36: noCase #37: noCase #38: yesCase #39: yesCase #40: yesCase #41: noCase #42: noCase #43: yesCase #44: yesCase #45: yesCase #46: noCase #47: yesCase #48: yes123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354<p>Since you crave state-of-the-art technology, you've just purchased a phone with a great new feature: autocomplete!Your phone's version of autocomplete has some pros and cons. On the one hand, it's very cautious. It only autocompletes a word when it knows exactly what you're trying to write. On the other hand, you have to teach it every word you want to use.</p>
<p>You have <strong>N</strong> distinct words that you'd like to send in a text message in order.Before sending each word, you add it to your phone's dictionary.Then, you write the smallest non-empty prefix of the word necessary for your phone to autocomplete the word.This prefix must either be the whole word, or a prefix which is not a prefix of any other word yet in the dictionary.</p>
<p>What's the minimum number of letters you must type to send all <strong>N</strong> words?</p>
<h3>Input</h3>
<p>Input begins with an integer <strong>T</strong>, the number of test cases.For each test case, there is first a line containing the integer <strong>N</strong>.Then, <strong>N</strong> lines follow, each containing a word to send in the order you wish to send them.</p>
<h3>Output</h3>
<p>For the <strong>i</strong>th test case, print a line containing "Case #<strong>i</strong>: " followed bythe minimum number of characters you need to type in your text message.</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 100 <br />1 ≤ <strong>N</strong> ≤ 100,000 <br /></p>
<p>The <strong>N</strong> words will have a total length of no more than 1,000,000 characters. <br />The words are made up of only lower-case alphabetic characters. <br />The words are pairwise distinct. <br /></p>
<p><strong>NOTE:</strong> The input file is about 10-20MB.</p>
<h3>Explanation of Sample</h3><p>In the first test case, you will write "h", "he", "l", "hil", "hill", for a total of 1 + 2 + 1 + 3 + 4 = 11 characters.</p>123version https://git-lfs.github.com/spec/v1oid sha256:a8269902a9c44cbcddece37288fa31a4a5a6fabe963b509b61abad752a4c24eesize 158007921234567891011121314151617181920212223242526272829303132333435363738394041Since you crave state-of-the-art technology, you've just purchased a phonewith a great new feature: autocomplete! Your phone's version of autocompletehas some pros and cons. On the one hand, it's very cautious. It onlyautocompletes a word when it knows exactly what you're trying to write. On theother hand, you have to teach it every word you want to use.
You have **N** distinct words that you'd like to send in a text message inorder. Before sending each word, you add it to your phone's dictionary. Then,you write the smallest non-empty prefix of the word necessary for your phoneto autocomplete the word. This prefix must either be the whole word, or aprefix which is not a prefix of any other word yet in the dictionary.
What's the minimum number of letters you must type to send all **N** words?
### Input
Input begins with an integer **T**, the number of test cases. For each testcase, there is first a line containing the integer **N**. Then, **N** linesfollow, each containing a word to send in the order you wish to send them.
### Output
For the **i**th test case, print a line containing "Case #**i**: " followed bythe minimum number of characters you need to type in your text message.
### Constraints
1 ≤ **T** ≤ 100 1 ≤ **N** ≤ 100,000
The **N** words will have a total length of no more than 1,000,000 characters. The words are made up of only lower-case alphabetic characters. The words are pairwise distinct.
**NOTE:** The input file is about 10-20MB.
### Explanation of Sample
In the first test case, you will write "h", "he", "l", "hil", "hill", for atotal of 1 + 2 + 1 + 3 + 4 = 11 characters.
1234567891011121314151617181920212223242526Case #1: 11Case #2: 15Case #3: 11Case #4: 9Case #5: 3Case #6: 5Case #7: 7Case #8: 21Case #9: 11Case #10: 8Case #11: 6Case #12: 392349Case #13: 392300Case #14: 392395Case #15: 392443Case #16: 392341Case #17: 392317Case #18: 392436Case #19: 392416Case #20: 1Case #21: 180Case #22: 183Case #23: 182Case #24: 179Case #25: 12Case #26: 1112345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879<p>The fine people of Corpro Corp. are a festive bunch. Every holiday season, everybody buys a gift for their manager. A cynic might say that the employees are just trying to bribe their way to a better performance review, but if you asked them yourself, they'd say they just wanted to spread cheer.</p>
<p>The fine people of Corpro Corp. are a frugal bunch. When they buy gifts, they cooperate to collectively buy the least expensive gifts that they can. A cynic might say that the employees are cheap, but if you asked them yourself, they'd say it's the thought that counts.</p>
<p>There are <strong>N</strong> employees working at Corpro Corp., and each of them has a manager, except for the CEO who has no manager (the CEO also buys a gift every year, but she donates it to charity). The employees each have a unique employee ID which is an integer from 1 to <strong>N</strong>. As you might expect, the CEO has the ID 1.</p>
<p>If there exists a set of two or more employees{<strong>p<sub>1</sub></strong>, ..., <strong>p<sub>k</sub></strong>}such that, for all <strong>i</strong> < <strong>k</strong>,<strong>p<sub>i</sub></strong> is the manager of <strong>p<sub>i+1</sub></strong>,then we say that <strong>p<sub>1</sub></strong> is "responsible for" <strong>p<sub>k</sub></strong>.There are never two employees who are responsible for each other.That would be a silly hierarchy indeed.</p>
<p>There are <strong>N</strong> kinds of gifts available for purchase, and the <strong>i</strong>th kind of gift costs <strong>i</strong> dollars. That is, the prices of the different kinds of gifts are {$1, $2, $3, ... $<strong>N</strong>}. There are <strong>N</strong> copies of each gift available for purchase.</p>
<p>The only thing that stops all employees from purchasing gifts that cost $1 is the awkwardness of buying a gift for their manager that's the same as the one their manager is giving away. No employee would ever do such a thing! </p>
<p>For example, in a company with just 2 employees, at least $3 must be spent in total. If employee #1 (the CEO) buys a $1 gift to donate to charity, then employee #2 cannot buy a $1 gift for employee #1 (their manager), but they can buy a $2 gift instead. Note that it would be equally optimal for the CEO to buy a $2 gift, while receiving a $1 gift from her subordinate.</p>
<p>What's the minimum possible total expenditure across the whole company during the gift exchange?</p>
<h3>Input</h3>
<p>Input begins with an integer <strong>T</strong>, the number of corporate hierarchies to consider. Each hierarchy is made up of two lines.The first line contains the integer <strong>N</strong>.The second line contains <strong>N</strong> space-separated integers.The <strong>i</strong>th integer is the employee ID of the manager of employee <strong>i</strong>,with the exception that the first integer is always 0, denoting that the CEO has no manager.</p>
<h3>Output</h3>
<p>For the <strong>i</strong>th hierarchy, print a line containing "Case #<strong>i</strong>: " followed by the smallest amount of money the entire company would need to spend.</p>
<h3>Constraints</h3>
<p>1 ≤ <strong>T</strong> ≤ 100 <br />1 ≤ <strong>N</strong> ≤ 200,000 <br /></p>
<p><strong>NOTE:</strong> The input file is about 10-20MB.</p>
<h3>Explanation of Sample</h3><p>In the first test case, the CEO will spend $2, and the other employees will spend $1.</p>
<p>In the second test case, employees #2 and #3 will spend $2, and the other employees will spend $1.</p>123version https://git-lfs.github.com/spec/v1oid sha256:e5d12d3817b9daeef9b5ea9fc8f6eecf5f0aeccbd49632908ca9bb6f10b613b1size 264958921234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768The fine people of Corpro Corp. are a festive bunch. Every holiday season,everybody buys a gift for their manager. A cynic might say that the employeesare just trying to bribe their way to a better performance review, but if youasked them yourself, they'd say they just wanted to spread cheer.
The fine people of Corpro Corp. are a frugal bunch. When they buy gifts, theycooperate to collectively buy the least expensive gifts that they can. A cynicmight say that the employees are cheap, but if you asked them yourself, they'dsay it's the thought that counts.
There are **N** employees working at Corpro Corp., and each of them has amanager, except for the CEO who has no manager (the CEO also buys a gift everyyear, but she donates it to charity). The employees each have a uniqueemployee ID which is an integer from 1 to **N**. As you might expect, the CEOhas the ID 1.
If there exists a set of two or more employees {**p1**, ..., **pk**} suchthat, for all **i** < **k**, **pi** is the manager of **pi+1**, then we saythat **p1** is "responsible for" **pk**. There are never two employees who areresponsible for each other. That would be a silly hierarchy indeed.
There are **N** kinds of gifts available for purchase, and the **i**th kind ofgift costs **i** dollars. That is, the prices of the different kinds of giftsare {$1, $2, $3, ... $**N**}. There are **N** copies of each gift availablefor purchase.
The only thing that stops all employees from purchasing gifts that cost $1 isthe awkwardness of buying a gift for their manager that's the same as the onetheir manager is giving away. No employee would ever do such a thing!
For example, in a company with just 2 employees, at least $3 must be spent intotal. If employee #1 (the CEO) buys a $1 gift to donate to charity, thenemployee #2 cannot buy a $1 gift for employee #1 (their manager), but they canbuy a $2 gift instead. Note that it would be equally optimal for the CEO tobuy a $2 gift, while receiving a $1 gift from her subordinate.
What's the minimum possible total expenditure across the whole company duringthe gift exchange?
### Input
Input begins with an integer **T**, the number of corporate hierarchies toconsider. Each hierarchy is made up of two lines. The first line contains theinteger **N**. The second line contains **N** space-separated integers. The**i**th integer is the employee ID of the manager of employee **i**, with theexception that the first integer is always 0, denoting that the CEO has nomanager.
### Output
For the **i**th hierarchy, print a line containing "Case #**i**: " followed bythe smallest amount of money the entire company would need to spend.
### Constraints
1 ≤ **T** ≤ 100 1 ≤ **N** ≤ 200,000
**NOTE:** The input file is about 10-20MB.
### Explanation of Sample
In the first test case, the CEO will spend $2, and the other employees willspend $1.
In the second test case, employees #2 and #3 will spend $2, and the otheremployees will spend $1.
12345678910111213141516171819202122232425262728293031323334Case #1: 4Case #2: 10Case #3: 7Case #4: 12Case #5: 11Case #6: 19Case #7: 29Case #8: 16Case #9: 15Case #10: 300000Case #11: 266675Case #12: 250006Case #13: 240007Case #14: 233343Case #15: 228579Case #16: 225006Case #17: 222229Case #18: 220009Case #19: 218187Case #20: 200001Case #21: 200201Case #22: 259808Case #23: 156560Case #24: 83876Case #25: 270049Case #26: 280835Case #27: 289329Case #28: 289267Case #29: 289121Case #30: 289201Case #31: 289287Case #32: 289251Case #33: 289164Case #34: 289301123456789101112131415161718192021222324252627282930313233343536373839404142<p>Your first-grade math teacher, Mr. Book, has just introduced you to an amazing new concept — primes! According to your notes, a prime is a positive integer greater than 1 that is divisible by only 1 and itself. </p>
<p>Primes seem fun, but without giving you and your 6-year-old colleagues time to consider their implications, he's promptly gone on to define another term: primacity. He explains that the primacity of an integer is the number of distinct primes which divide it. For example, the primacity of 12 is 2 (as it's divisible by primes 2 and 3), the primacity of 550 is 3 (as it's divisible by primes 2, 5, and 11), and the primacity of 7 is 1 (as the only prime it's divisible by is 7).</p>
<p>Following his lesson, Mr. Book has given you homework with some rather mean questions of the following form: Given 3 integers <strong>A</strong>, <strong>B</strong>, and <strong>K</strong>, how many integers in the inclusive range [<strong>A</strong>, <strong>B</strong>] have a primacity of exactly <strong>K</strong>?</p>
<p>Mr. Book probably expects his little homework assignment to take you and your classmates the rest of the year to complete, giving him time to slack off and nap during the remaining math classes. However, you want to learn more things from him instead! Can you use the skills you've learned in your first-grade computer science classes to finish Mr. Book's homework before tomorrow's math class?</p>
<h3>Input</h3>
<p>Input begins with an integer <strong>T</strong>, the number of homework questions. For each question, there is one line containing 3 space-separated integers: <strong>A</strong>, <strong>B</strong>, and <strong>K</strong>.</p>
<h3>Output</h3>
<p>For the <strong>i</strong>th question, print a line containing "Case #<strong>i</strong>: " followed by the number of integers in the inclusive range [<strong>A</strong>, <strong>B</strong>] with a primacity of <strong>K</strong>.</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 100 <br />2 ≤ <strong>A</strong> ≤ <strong> B</strong> ≤ 10<sup>7</sup> <br />1 ≤ <strong>K</strong> ≤ 10<sup>9</sup> <br /></p>
<h3>Explanation of Sample</h3><p>In the first test case, the numbers in the inclusive range [5, 15] with primacity 2 are 6, 10, 12, 14, and 15. All other numbers in this range have primacity 1.</p>
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011005 15 22 10 124 42 31000000 1000000 11000000 1000000 22 10000000 12 10000000 22 10000000 32 10000000 42 10000000 52 10000000 62 10000000 72 10000000 82 10000000 92 10000000 108871874 9106921 3331489 365258 31673990 4964281 42538323 6179886 21025453 8126648 33361449 8066195 52174560 8350603 51924670 7300066 43356201 7892516 16106950 8813219 23727417 4063511 43906481 8482851 11190025 5884818 43530768 3862846 23639960 4537222 24676591 6532150 35920093 9632621 25974475 8755316 52055959 3285607 15962779 7546760 47616599 9656814 3819395 5881718 34540063 9776151 33149358 4816092 4859164 9298582 35182061 8775862 5106155 1892761 11183683 1981007 22607093 8066130 22774448 6482213 26088359 9056768 4152581 3587075 36558386 7695670 13076816 8569562 44384507 7991697 51620670 8969214 42758646 8066510 41832012 3474647 54681249 9985120 21542709 7820522 36581283 7345664 45400108 8500614 471201 3452422 56236504 6406553 31212007 8814797 5280161 4022288 45998828 9313139 33334556 6692366 24238738 8482756 21397629 4490703 15239504 5466741 11115185 2191541 51004498 3467821 3249829 4915791 11268386 7040359 53165210 8983866 2313542 9645661 43316911 8040431 41294444 1873758 25151921 6733095 23466230 7052925 45217611 9465564 2372758 8901763 13650751 7274864 3328169 7413213 31537426 4324540 23472440 5658810 1732178 3267497 46742737 8769166 21645327 6034975 31119888 3311178 38087077 9505792 41515067 4051848 37034691 7549385 43254111 9037177 35931909 6822709 39044939 9418713 51074662 6227284 28201820 9209955 36245823 9177823 4426284 9502658 4847145 6488989 4115606 3742378 36055091 6351638 15154586 9431441 4123456789101112131415161718192021222324252627282930313233343536373839404142434445464748Your first-grade math teacher, Mr. Book, has just introduced you to an amazingnew concept — primes! According to your notes, a prime is a positive integergreater than 1 that is divisible by only 1 and itself.
Primes seem fun, but without giving you and your 6-year-old colleagues time toconsider their implications, he's promptly gone on to define another term:primacity. He explains that the primacity of an integer is the number ofdistinct primes which divide it. For example, the primacity of 12 is 2 (asit's divisible by primes 2 and 3), the primacity of 550 is 3 (as it'sdivisible by primes 2, 5, and 11), and the primacity of 7 is 1 (as the onlyprime it's divisible by is 7).
Following his lesson, Mr. Book has given you homework with some rather meanquestions of the following form: Given 3 integers **A**, **B**, and **K**, howmany integers in the inclusive range [**A**, **B**] have a primacity ofexactly **K**?
Mr. Book probably expects his little homework assignment to take you and yourclassmates the rest of the year to complete, giving him time to slack off andnap during the remaining math classes. However, you want to learn more thingsfrom him instead! Can you use the skills you've learned in your first-gradecomputer science classes to finish Mr. Book's homework before tomorrow's mathclass?
### Input
Input begins with an integer **T**, the number of homework questions. For eachquestion, there is one line containing 3 space-separated integers: **A**,**B**, and **K**.
### Output
For the **i**th question, print a line containing "Case #**i**: " followed bythe number of integers in the inclusive range [**A**, **B**] with a primacityof **K**.
### Constraints
1 ≤ **T** ≤ 100 2 ≤ **A** ≤ ** B** ≤ 107 1 ≤ **K** ≤ 109
### Explanation of Sample
In the first test case, the numbers in the inclusive range [5, 15] withprimacity 2 are 6, 10, 12, 14, and 15. All other numbers in this range haveprimacity 1.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100Case #1: 5Case #2: 7Case #3: 2Case #4: 0Case #5: 1Case #6: 665134Case #7: 2536838Case #8: 3642766Case #9: 2389433Case #10: 691209Case #11: 72902Case #12: 1716Case #13: 1Case #14: 0Case #15: 0Case #16: 84004Case #17: 12862Case #18: 784848Case #19: 914083Case #20: 2583098Case #21: 347576Case #22: 448087Case #23: 1299171Case #24: 292564Case #25: 660355Case #26: 81003Case #27: 293161Case #28: 1120812Case #29: 83853Case #30: 225659Case #31: 670494Case #32: 904582Case #33: 214116Case #34: 83227Case #35: 389544Case #36: 730874Case #37: 1852500Case #38: 1883852Case #39: 401548Case #40: 3065358Case #41: 274279Case #42: 131610Case #43: 210840Case #44: 1357770Case #45: 927957Case #46: 732942Case #47: 1273260Case #48: 72187Case #49: 1341249Case #50: 270356Case #51: 1782942Case #52: 1292370Case #53: 107363Case #54: 1297115Case #55: 2280812Case #56: 187946Case #57: 763312Case #58: 195522Case #59: 61141Case #60: 542559Case #61: 867607Case #62: 1190648Case #63: 836738Case #64: 1044902Case #65: 208557Case #66: 14697Case #67: 64356Case #68: 907868Case #69: 321263Case #70: 401231Case #71: 1437409Case #72: 2242791Case #73: 1152983Case #74: 153111Case #75: 390411Case #76: 873270Case #77: 1038350Case #78: 564961Case #79: 1311058Case #80: 2589986Case #81: 714582Case #82: 142655Case #83: 589256Case #84: 493366Case #85: 1600348Case #86: 807495Case #87: 352127Case #88: 930137Case #89: 127024Case #90: 2087426Case #91: 320918Case #92: 29704Case #93: 1310383Case #94: 361290Case #95: 724433Case #96: 2183450Case #97: 1346130Case #98: 1344370Case #99: 18994Case #100: 105429212345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061<p>In the game of <em>Sports</em>, the object is have more points than the otherteam after a certain amount of time has elapsed. Scores are denoted bytwo hyphen-separated integers. For example, scores may include 3-2,4-1, or 10-0. The first number is how many points you've scored, and the secondis the number of points scored by the opposing team. You're very good at <em>Sports</em>, and consequently you always win. However, you don't alwaysachieve victory the same way every time.</p>
<p>The two most extreme kinds of victory are called <strong>stress-free</strong> and <strong>stressful</strong>. In a <strong>stress-free</strong> victory, you score the firstpoint and from then on you always have more points than your opponent.In a <strong>stressful</strong> victory, you never have more points than your opponentuntil after their score is equal to their final score.</p>
<p>Given the final score of a game of <em>Sports</em>, how many ways could youarrange the order in which the points are scored such that you secure a<strong>stress-free</strong> or <strong>stressful</strong> win?</p>
<h3>Input</h3>
<p>Input begins with an integer <strong>T</strong>, the number of gamesyou'll play. For each game, there is one line containing the final score ofthe game in the format described above.</p>
<h3>Output</h3>
<p>For the <strong>i</strong>th game, print a line containing "Case #<strong>i</strong>: " followed by two space-separated integers, the numberof ways you can achieve a <strong>stress-free</strong> or <strong>stressful</strong> win,respectively. Since these numbers may be very large, output them modulo1,000,000,007.</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 100 <br /></p>
<p>Since you always win, the first number in any final scorewill always be larger than the second. Both scores will be non-negative integers not exceeding 2000.</p>
<h3>Explanation of Sample</h3><p>In the third test case, you can get a stress-free win by scoring points 1, 2, and 4, or points 1, 2, and 3.You can get a stressful win by scoring points 2, 4, and 5, or points 3, 4, and 5.</p>
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011002-13-13-210-51000-5001-02000-02000-19991549-2211411-12151930-8501582-9711446-363703-1491999-474444-2641500-4811919-4081244-1138614-1161872-15351925-491877-7851978-17441014-220708-6041215-11021966-4521506-184647-3131302-8831940-1927862-6101571-15331831-1271700-1584827-274955-524712-1391641-9531677-2141055-3651423-1321669-711581-13151335-1101537-888764-521443-8001130-271542-4691919-371221-3001486-11251117-3541791-4961363-931782-4001516-3361841-1045649-3121208-1941013-706532-41580-11681284-602174-152609-2831009-9121096-301980-8501958-14271531-534562-1651857-16731669-3691598-929135-731210-8661192-1471636-53481-1911693-9251999-15921159-2491286-7091488-14841361-28670-484769-295565-220740-1601563-737873-2951254-4781725-736543-3711551-1296461-263853-800123456789101112131415161718192021222324252627282930313233343536373839404142434445In the game of _Sports_, the object is have more points than the other teamafter a certain amount of time has elapsed. Scores are denoted by two hyphen-separated integers. For example, scores may include 3-2, 4-1, or 10-0. Thefirst number is how many points you've scored, and the second is the number ofpoints scored by the opposing team. You're very good at _Sports_, andconsequently you always win. However, you don't always achieve victory thesame way every time.
The two most extreme kinds of victory are called **stress-free** and**stressful**. In a **stress-free** victory, you score the first point andfrom then on you always have more points than your opponent. In a**stressful** victory, you never have more points than your opponent untilafter their score is equal to their final score.
Given the final score of a game of _Sports_, how many ways could you arrangethe order in which the points are scored such that you secure a **stress-free** or **stressful** win?
### Input
Input begins with an integer **T**, the number of games you'll play. For eachgame, there is one line containing the final score of the game in the formatdescribed above.
### Output
For the **i**th game, print a line containing "Case #**i**: " followed by twospace-separated integers, the number of ways you can achieve a **stress-free**or **stressful** win, respectively. Since these numbers may be very large,output them modulo 1,000,000,007.
### Constraints
1 ≤ **T** ≤ 100
Since you always win, the first number in any final score will always belarger than the second. Both scores will be non-negative integers notexceeding 2000.
### Explanation of Sample
In the third test case, you can get a stress-free win by scoring points 1, 2,and 4, or points 1, 2, and 3. You can get a stressful win by scoring points 2,4, and 5, or points 3, 4, and 5.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100Case #1: 1 1Case #2: 2 1Case #3: 2 2Case #4: 1001 42Case #5: 70047606 591137401Case #6: 1 1Case #7: 1 1Case #8: 319838403 319838403Case #9: 407599208 416582650Case #10: 931707689 601702223Case #11: 617690761 720720066Case #12: 837137729 227376481Case #13: 824539579 949882401Case #14: 633156245 354441979Case #15: 116188991 469122262Case #16: 558565127 312949408Case #17: 424855816 964380814Case #18: 678762874 810834988Case #19: 944478903 247049988Case #20: 679221065 901403157Case #21: 568451865 402056534Case #22: 424370264 960630947Case #23: 715062585 794279542Case #24: 149556166 176349646Case #25: 407453334 785126250Case #26: 264377506 533391397Case #27: 788649722 763674423Case #28: 143957840 638571138Case #29: 885201846 81012050Case #30: 9814502 808219050Case #31: 128185490 648087915Case #32: 370665806 539919518Case #33: 109667929 662611179Case #34: 328184308 627650788Case #35: 603377488 631844581Case #36: 992276375 336710496Case #37: 56103256 467176030Case #38: 452477938 341584130Case #39: 704322164 767415875Case #40: 326766250 712856433Case #41: 513721593 19870649Case #42: 940446741 464107227Case #43: 299357201 465463045Case #44: 918270667 185042843Case #45: 133432101 839838061Case #46: 14099157 687851011Case #47: 228180963 73438287Case #48: 942083314 323205961Case #49: 816502871 4028078Case #50: 696316964 550429273Case #51: 65627243 455845943Case #52: 886784720 966114350Case #53: 616614881 718512182Case #54: 838827309 74747751Case #55: 616119039 957096711Case #56: 763445604 37769293Case #57: 914446682 326487736Case #58: 640809903 497153305Case #59: 758592999 530342463Case #60: 483725318 646137453Case #61: 285278399 723024629Case #62: 16605071 73744548Case #63: 927054563 881639757Case #64: 350000919 14Case #65: 275736028 844497257Case #66: 380983406 319827269Case #67: 250782506 49035108Case #68: 858463859 925866024Case #69: 128635484 500668215Case #70: 410450602 18714029Case #71: 238405893 720720066Case #72: 23789578 923029325Case #73: 507059447 741860141Case #74: 428961024 264105011Case #75: 254458120 204820879Case #76: 798717050 797874213Case #77: 658595747 24605944Case #78: 330170277 458247558Case #79: 150263723 650437050Case #80: 216067901 112571416Case #81: 65720917 812467623Case #82: 460115761 208324196Case #83: 910296350 834019692Case #84: 128284947 22214272Case #85: 839667341 31578719Case #86: 568486330 666795455Case #87: 689903668 992420028Case #88: 914956340 949904131Case #89: 997814136 441095159Case #90: 304284048 947787397Case #91: 896508018 785126250Case #92: 794540851 361798437Case #93: 885842866 220639770Case #94: 132989766 947787397Case #95: 199657043 899965082Case #96: 622770288 707003450Case #97: 165622659 835003284Case #98: 225795326 523210601Case #99: 612020853 406955973Case #100: 694658552 4028078123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657<p>In the game <em>Theatrhythm Final Fantasy</em>, you poke a screen with a stickto the beat of various songs. The goal is to poke the screen as accurately aspossible. If you hit a note at just the right time, you're awarded a <strong>critical</strong>. Every song is broken into 20 sections, and if you get a <strong>critical</strong> on every note in a section, then you get that section's golden <strong>critical bar</strong>.</p>
<p>You would like to collect all 20 <strong>critical bars</strong> for every song. Songs vary in difficulty, but each song has a fixed probability <strong>p</strong>, whichis the chance that you manage to secure any one <strong>critical bar</strong>on a single playthrough.The chances are independent, so for any given pair of sections, the probability ofgetting both <strong>critical bars</strong> in a single playthrough is <strong>p</strong><sup>2</sup>, and so on.<strong>Critical bars</strong> are saved between playthroughs, so you don't have to winall of the <strong>critical bars</strong> in a single play of the song. You might winthe first 10 on one play, and then the last 10 on another.</p>
<p>On average, how many times will you have to play a song to win all 20<strong>critical bars</strong>?</p>
<h3>Input</h3>
<p>Input begins with an integer <strong>T</strong>, the number of songsyou'll play. For each song, there is a line containing a floating point number,<strong>p</strong>, the probability of winning any particular <strong>critical bar</strong> on a single play of the song.</p>
<h3>Output</h3>
<p>For each song, output the expected number of times you need to play the songbefore acquiring all 20 <strong>critical bars</strong>, rounded to five decimal points.</p>
<p>Absolute errors of up to 10<sup>-5</sup> will be ignored.</p>
<h3>Constraints</h3><p>1 ≤ <strong>T</strong> ≤ 20 <br />0.01 ≤ <strong>p</strong> ≤ 1.0 <br /></p>
.gitattributes+5
2015/finals/fox_blocks.htmlAdded+77
2015/finals/fox_blocks.inAdded+3
2015/finals/fox_blocks.mdAdded+59
2015/finals/fox_blocks.outAdded+20
2015/finals/fox_focks.htmlAdded+59
2015/finals/fox_focks.inAdded+3
2015/finals/fox_focks.mdAdded+52
2015/finals/fox_focks.outAdded+20
2015/finals/fox_hawks.htmlAdded+94
2015/finals/fox_hawks.inAdded+3
2015/finals/fox_hawks.mdAdded+78
2015/finals/fox_hawks.outAdded+20
2015/finals/fox_lochs.htmlAdded+57
2015/finals/fox_lochs.inAdded+281
2015/finals/fox_lochs.mdAdded+44
2015/finals/fox_lochs.outAdded+20
2015/finals/fox_locks.htmlAdded+74
2015/finals/fox_locks.inAdded
2015/finals/fox_locks.mdAdded+67
2015/finals/fox_locks.outAdded+20
2015/quals/cooking_the_books.htmlAdded+45
2015/quals/cooking_the_books.inAdded+101
2015/quals/cooking_the_books.mdAdded+30
2015/quals/cooking_the_books.outAdded+100
2015/quals/laser_maze.htmlAdded+68
2015/quals/laser_maze.inAdded
2015/quals/laser_maze.mdAdded+48
2015/quals/laser_maze.outAdded+100
2015/quals/new_years_resolution.htmlAdded+41
2015/quals/new_years_resolution.inAdded+1006
2015/quals/new_years_resolution.mdAdded+31
2015/quals/new_years_resolution.outAdded+48
2015/round1/autocomplete.htmlAdded+54
2015/round1/autocomplete.inAdded+3
2015/round1/autocomplete.mdAdded+41
2015/round1/autocomplete.outAdded+26
2015/round1/corporate_gifting.htmlAdded+79
2015/round1/corporate_gifting.inAdded+3
2015/round1/corporate_gifting.mdAdded+68
2015/round1/corporate_gifting.outAdded+34
2015/round1/homework.htmlAdded+42
2015/round1/homework.inAdded+101
2015/round1/homework.mdAdded+48
2015/round1/homework.outAdded+100
2015/round1/winning_at_sports.htmlAdded+61
2015/round1/winning_at_sports.inAdded+101
2015/round1/winning_at_sports.mdAdded+45
2015/round1/winning_at_sports.outAdded+100
2015/round2/all_critical.htmlAdded+57