2011 Problems
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- 2011/finals/alien_game.htmlAdded+19
- 2011/finals/alien_game.inAdded
- 2011/finals/alien_game.mdAdded+54
- 2011/finals/alien_game.outAdded+50
- 2011/finals/party_time.htmlAdded+84
- 2011/finals/party_time.inAdded
- 2011/finals/party_time.mdAdded+60
- 2011/finals/party_time.outAdded+50
- 2011/finals/safest_place.htmlAdded+16
- 2011/finals/safest_place.inAdded
- 2011/finals/safest_place.mdAdded+31
- 2011/finals/safest_place.outAdded+50
- 2011/quals/double_squares.htmlAdded+18
- 2011/quals/double_squares.inAdded+64
- 2011/quals/double_squares.mdAdded+23
- 2011/quals/double_squares.outAdded+63
- 2011/quals/peg_game.htmlAdded+63
- 2011/quals/peg_game.inAdded
- 2011/quals/peg_game.mdAdded+60
- 2011/quals/peg_game.outAdded+60
- 2011/quals/studious_student.htmlAdded+15
- 2011/quals/studious_student.inAdded+40
- 2011/quals/studious_student.mdAdded+29
- 2011/quals/studious_student.outAdded+39
- 2011/round1a/diversity_number.htmlAdded+17
- 2011/round1a/diversity_number.inAdded+121
- 2011/round1a/diversity_number.mdAdded+32
- 2011/round1a/diversity_number.outAdded+60
- 2011/round1a/turn_on_the_lights.htmlAdded+25
- 2011/round1a/turn_on_the_lights.inAdded+1051
- 2011/round1a/turn_on_the_lights.mdAdded+30
- 2011/round1a/turn_on_the_lights.outAdded+60
- 2011/round1a/wine_tasting.htmlAdded+29
- 2011/round1a/wine_tasting.inAdded+51
- 2011/round1a/wine_tasting.mdAdded+34
- 2011/round1a/wine_tasting.outAdded+50
- 2011/round1b/chess_2.htmlAdded+66
- 2011/round1b/chess_2.inAdded+1462
- 2011/round1b/chess_2.mdAdded+101
- 2011/round1b/chess_2.outAdded+50
- 2011/round1b/diminishing_circle.htmlAdded+2
- 2011/round1b/diminishing_circle.inAdded+61
- 2011/round1b/diminishing_circle.mdAdded+2
- 2011/round1b/diminishing_circle.outAdded+60
- 2011/round1b/slot_machine_hacker.htmlAdded+34
- 2011/round1b/slot_machine_hacker.inAdded+56
- 2011/round1b/slot_machine_hacker.mdAdded+42
- 2011/round1b/slot_machine_hacker.outAdded+55
- 2011/round1c/n_factorful.htmlAdded+12
- 2011/round1c/n_factorful.inAdded+51
12345678910111213141516171819<p>Aliens on the Unknown planet have a tradition of playing a game called Loiten. It is played by two players who alternate turns. There are <strong>N</strong> buckets with apples standing in one line in front of the players. They are numbered from left to right with integers starting from 1. </p>
<p>In one turn a player can select one of the buckets, which is not the first and not the last and has a positive number of apples in it, and move all of that bucket's apples to the bucket adjacent to the left and at the same time move all of them to the bucket adjacent to the right. That's right, the number of apples can be negative as it is a really strange planet. Thus, if there are 3 consecutive buckets with the number of apples being <strong>x</strong>, <strong>y</strong>, <strong>z</strong>, then you can perform the move if <strong>y</strong> is greater than zero. The resulting capacity of the buckets will be as follows: <strong>x+y</strong>, <strong>-y</strong>, <strong>z+y</strong>. The first player who can't make a move loses. </p>
<p>You happen to know one of the aliens from the Unknown planet, named Popo. He is a very good Loiten player, and has reached the Loiten Finals. On the day prior to the game, he found out the number of apples in each of the buckets. Unfortunately, his memory is not that good, and he can't remember the number of apples in the <strong>P</strong>-th bucket. He just remembers that it is a number with absolute value not greater than <strong>F</strong>. </p>
<p>Now, he is asking you to help him to calculate his chances. The players at the Finals are so good that they only make optimal moves to maximize their chance of winning. If neither player can win, the game is considered a draw. You are to find the number of possible apple counts for the bucket with an unknown number of apples where Popo will win. Popo is also sure that he is the one to make the first turn.</p>
<h2>Input</h2>The first line of the input file consists of a single number <strong>T</strong>, the number of test cases. Each test case begins with a line containing two integers <strong>N</strong>, the number of buckets and <strong>P</strong>, the number of the bucket with the unknown amount of apples. It is followed by a line containing <strong>N</strong> integers, the numbers of apples in the corresponding buckets. The <strong>P</strong><sup>th</sup> number on this line is the positive integer <strong>F</strong> and corresponds to the constraint on the number of apples in the <strong>P</strong>-th bucket.<br/><br/>
<h2>Output</h2>Output <strong>T</strong> lines, with the answer to each test case on a single line, the number of possible values for unknown bucket.<br/><br/>
<h2>Constraints</h2><strong>T</strong> = 50<br/>1≤ <strong>P</strong> ≤ <strong>N</strong> ≤ 2,000.<br/>1≤ <strong>F</strong> ≤ 1,000,000,000,000.<br/>The number of apples in each bucket at the start of the game has an absolute value not greater than 1,000,000,000,000.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354Aliens on the Unknown planet have a tradition of playing a game called Loiten.It is played by two players who alternate turns. There are **N** buckets withapples standing in one line in front of the players. They are numbered fromleft to right with integers starting from 1.
In one turn a player can select one of the buckets, which is not the first andnot the last and has a positive number of apples in it, and move all of thatbucket's apples to the bucket adjacent to the left and at the same time moveall of them to the bucket adjacent to the right. That's right, the number ofapples can be negative as it is a really strange planet. Thus, if there are 3consecutive buckets with the number of apples being **x**, **y**, **z**, thenyou can perform the move if **y** is greater than zero. The resulting capacityof the buckets will be as follows: **x+y**, **-y**, **z+y**. The first playerwho can't make a move loses.
You happen to know one of the aliens from the Unknown planet, named Popo. Heis a very good Loiten player, and has reached the Loiten Finals. On the dayprior to the game, he found out the number of apples in each of the buckets.Unfortunately, his memory is not that good, and he can't remember the numberof apples in the **P**-th bucket. He just remembers that it is a number withabsolute value not greater than **F**.
Now, he is asking you to help him to calculate his chances. The players at theFinals are so good that they only make optimal moves to maximize their chanceof winning. If neither player can win, the game is considered a draw. You areto find the number of possible apple counts for the bucket with an unknownnumber of apples where Popo will win. Popo is also sure that he is the one tomake the first turn.
## Input
The first line of the input file consists of a single number **T**, the numberof test cases. Each test case begins with a line containing two integers**N**, the number of buckets and **P**, the number of the bucket with theunknown amount of apples. It is followed by a line containing **N** integers,the numbers of apples in the corresponding buckets. The **P**th number on thisline is the positive integer **F** and corresponds to the constraint on thenumber of apples in the **P**-th bucket.
## Output
Output **T** lines, with the answer to each test case on a single line, thenumber of possible values for unknown bucket.
## Constraints
**T** = 50 1≤ **P** ≤ **N** ≤ 2,000. 1≤ **F** ≤ 1,000,000,000,000. The number of apples in each bucket at the start of the game has an absolutevalue not greater than 1,000,000,000,000.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950Case #1: 2Case #2: 1Case #3: 5Case #4: 2Case #5: 2Case #6: 986217165634Case #7: 1002456934349Case #8: 812053503419Case #9: 1002481940247Case #10: 988889644609Case #11: 1008867688282Case #12: 3Case #13: 896856530991Case #14: 984312027341Case #15: 1017606700635Case #16: 1284822124847Case #17: 992545327253Case #18: 1101002652523Case #19: 965823706896Case #20: 730429422093Case #21: 1134081025735Case #22: 1013550903092Case #23: 1038375278147Case #24: 1000783973454Case #25: 1012419891647Case #26: 999999999970Case #27: 1305771904105Case #28: 1019446723130Case #29: 728910530069Case #30: 1224473397557Case #31: 1289882017196Case #32: 1332162289297Case #33: 1050599582383Case #34: 1128130897062Case #35: 987014026338Case #36: 677015991558Case #37: 0Case #38: 990431235212Case #39: 985393646885Case #40: 610289560579Case #41: 0Case #42: 0Case #43: 1001343337069Case #44: 2000000000001Case #45: 970463442365Case #46: 1009232305622Case #47: 1005990274949Case #48: 973364302077Case #49: 934198191708Case #50: 976504890470123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384<p>
You're throwing a party for your friends, but since your friends may not allknow each other, you're afraid a few of them may not enjoy your party. So toavoid this situation, you decide that you'll also invite some friends of yourfriends. But who should you invite to throw a great party?
</p>
<p>
Luckily, you are in possession of data about all the friendships of your friendsand their friends. In graph theory terminology, you have a subset<strong>G</strong> of the social graph, whose vertices correspond to yourfriends and their friends (excluding yourself), and edges in this graph denotemutual friendships. Furthermore, you have managed to obtain exact estimatesof how much food each person in <strong>G</strong> will consume during theparty if he were to be invited.
</p>
<p>
You want to choose a set of guests from <strong>G</strong>. This set of guestsshould include all your friends, and the subgraph of <strong>G</strong> formedby the guests must be connected. You believe that this will ensure that all ofyour friends will enjoy your party since any two of them will have something totalk about...
</p>
<p>
In order to save money, you want to pick the set of guests so that the totalamount of food needed is as small as possible. If there are several ways ofdoing this, you prefer one with the fewest number of guests.
</p>
<p>
The people/vertices in your subset <strong>G</strong> of the social graph arenumbered from 0 to <strong>N</strong> - 1. Also, for convenience your friendsare numbered from 0 to <strong>F</strong> - 1, where <strong>F</strong> is thenumber of your friends that you want to invite. You may also assume that<strong>G</strong> is connected. Note again that you are notyourself represented in <strong>G</strong>.
</p>
<h2>Input</h2>
The first line of the input consists of a single number <strong>T</strong>, thenumber of test cases. Each test case starts with a line containing threeintegers <strong>N</strong>, the number of nodes in <strong>G</strong>,<strong>F</strong>, the number of friends, and <strong>M</strong>, the number ofedges in <strong>G</strong>. This is followed by <strong>M</strong> lines eachcontaining two integers. The <strong>i</strong><sup>th</sup> of these lines will containtwo distinct integers <strong>u</strong> and <strong>v</strong> which indicatesa mutual friendship between person <strong>u</strong> and person<strong>v</strong>. After this follows a single line containing<strong>N</strong> space-separated integers with the <strong>i</strong><sup>th</sup>representing the amount of food consumed by person <strong>i</strong>.<br/><br/>
<h2>Output</h2>Output <strong>T</strong> lines, with the answer to each test case on a singleline by itself. Each line should contain two numbers, the first being the minimum totalquantity of food consumed at a party satisfying the given criteria and thesecond the minimum number of people you can have at such a party.<br/><br/>
<h2>Constraints</h2><strong>T</strong> = 50<br/>1 ≤ <strong>F</strong> ≤ 11<br/><strong>F</strong> ≤ <strong>N</strong>-1 <br/>2 ≤ <strong>N</strong> ≤ 250<br/><strong>N</strong>-1 ≤ <strong>M</strong> ≤ <strong>N</strong> * (<strong>N</strong> - 1) / 2<br/><strong>G</strong> is connected, and contains no self-loops or duplicate edges.<br/>For each person, the amount of food consumed is an integer between 0 and 1000, both inclusive.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960You're throwing a party for your friends, but since your friends may not allknow each other, you're afraid a few of them may not enjoy your party. So toavoid this situation, you decide that you'll also invite some friends of yourfriends. But who should you invite to throw a great party?
Luckily, you are in possession of data about all the friendships of yourfriends and their friends. In graph theory terminology, you have a subset**G** of the social graph, whose vertices correspond to your friends and theirfriends (excluding yourself), and edges in this graph denote mutualfriendships. Furthermore, you have managed to obtain exact estimates of howmuch food each person in **G** will consume during the party if he were to beinvited.
You want to choose a set of guests from **G**. This set of guests shouldinclude all your friends, and the subgraph of **G** formed by the guests mustbe connected. You believe that this will ensure that all of your friends willenjoy your party since any two of them will have something to talk about...
In order to save money, you want to pick the set of guests so that the totalamount of food needed is as small as possible. If there are several ways ofdoing this, you prefer one with the fewest number of guests.
The people/vertices in your subset **G** of the social graph are numbered from0 to **N** \- 1. Also, for convenience your friends are numbered from 0 to**F** \- 1, where **F** is the number of your friends that you want to invite.You may also assume that **G** is connected. Note again that you are notyourself represented in **G**.
## Input
The first line of the input consists of a single number **T**, the number oftest cases. Each test case starts with a line containing three integers **N**,the number of nodes in **G**, **F**, the number of friends, and **M**, thenumber of edges in **G**. This is followed by **M** lines each containing twointegers. The **i**th of these lines will contain two distinct integers **u**and **v** which indicates a mutual friendship between person **u** and person**v**. After this follows a single line containing **N** space-separatedintegers with the **i**th representing the amount of food consumed by person**i**.
## Output
Output **T** lines, with the answer to each test case on a single line byitself. Each line should contain two numbers, the first being the minimumtotal quantity of food consumed at a party satisfying the given criteria andthe second the minimum number of people you can have at such a party.
## Constraints
**T** = 50 1 ≤ **F** ≤ 11 **F** ≤ **N**-1 2 ≤ **N** ≤ 250 **N**-1 ≤ **M** ≤ **N** * (**N** \- 1) / 2 **G** is connected, and contains no self-loops or duplicate edges. For each person, the amount of food consumed is an integer between 0 and 1000,both inclusive.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950Case #1: 6 3Case #2: 11 3Case #3: 177 5Case #4: 28 7Case #5: 45 10Case #6: 6 1Case #7: 9 1Case #8: 4 3Case #9: 9 1Case #10: 10 3Case #11: 34 4Case #12: 2384 5Case #13: 335 5Case #14: 6138 14Case #15: 7405 14Case #16: 6176 16Case #17: 7890 15Case #18: 3839 14Case #19: 54 16Case #20: 48 14Case #21: 30 13Case #22: 35 14Case #23: 61 13Case #24: 29 16Case #25: 27 16Case #26: 35 20Case #27: 32 14Case #28: 19 18Case #29: 96 18Case #30: 136 27Case #31: 116 23Case #32: 133 32Case #33: 82 19Case #34: 144 27Case #35: 129 31Case #36: 142 28Case #37: 93 27Case #38: 133 28Case #39: 37 32Case #40: 37 29Case #41: 37 26Case #42: 41 25Case #43: 46 22Case #44: 7163 20Case #45: 8494 21Case #46: 4309 18Case #47: 5730 17Case #48: 7193 22Case #49: 6391 17Case #50: 4288 1812345678910111213141516<p>While en route to the 295<sup>th</sup> annual Galactic Dance Party on Risa, you find yourself unceremoniously yanked out of hyperspace and, according to your sensors, surrounded by <strong>N</strong> space bombs. Apparently caught in a trap laid out by some dastardly and unknown enemy, and unable to return to hyperspace, you must find the safest place in the vicinity to weather the detonation of all the space bombs. Your unseen opponent has constructed a cube-shaped space anomaly that you are unable to leave, so your options are limited to points within that cube.</p>
<p>Before the bombs explode (all simultaneously), you have just enough time to travel to any integer point in the cube [0, 0, 0]-[1000, 1000, 1000], both inclusive. You must find the point with the maximum distance to the nearest bomb, which your captain's intuition tells you will be the safest point.</p>
<h2>Input</h2>
<p>The first line of the input file consists of a single number <strong>T</strong>, the number of test cases. Each test consists of single number <strong>N</strong>, the number of bombs, followed by <strong>3*N</strong> integers describing the positions of the bombs.
<h2>Output</h2>
<p>Output <strong>T</strong> integers, one per test case each on its own line, representing the square of distance to the nearest bomb from the safest point in the cube.</p>
<h2>Constraints</h2><strong>T</strong> = 50<br/>1 ≤ <strong>N</strong> ≤ 200<br/>All bombs coordinates will be in [0, 1000], both inclusive.12345678910111213141516171819202122232425262728293031While en route to the 295th annual Galactic Dance Party on Risa, you findyourself unceremoniously yanked out of hyperspace and, according to yoursensors, surrounded by **N** space bombs. Apparently caught in a trap laid outby some dastardly and unknown enemy, and unable to return to hyperspace, youmust find the safest place in the vicinity to weather the detonation of allthe space bombs. Your unseen opponent has constructed a cube-shaped spaceanomaly that you are unable to leave, so your options are limited to pointswithin that cube.
Before the bombs explode (all simultaneously), you have just enough time totravel to any integer point in the cube [0, 0, 0]-[1000, 1000, 1000], bothinclusive. You must find the point with the maximum distance to the nearestbomb, which your captain's intuition tells you will be the safest point.
## Input
The first line of the input file consists of a single number **T**, the numberof test cases. Each test consists of single number **N**, the number of bombs,followed by **3*N** integers describing the positions of the bombs.
## Output
Output **T** integers, one per test case each on its own line, representingthe square of distance to the nearest bomb from the safest point in the cube.
## Constraints
**T** = 50 1 ≤ **N** ≤ 200 All bombs coordinates will be in [0, 1000], both inclusive.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950Case #1: 520667Case #2: 390625Case #3: 265929Case #4: 207418Case #5: 164387Case #6: 1002304Case #7: 30452Case #8: 30342Case #9: 29642Case #10: 29636Case #11: 30462Case #12: 30340Case #13: 30614Case #14: 30259Case #15: 30443Case #16: 31485Case #17: 251306Case #18: 253929Case #19: 252650Case #20: 255098Case #21: 500000Case #22: 500025Case #23: 500000Case #24: 750000Case #25: 46875Case #26: 46152Case #27: 34611Case #28: 41257Case #29: 36670Case #30: 44768Case #31: 53459Case #32: 47912Case #33: 40165Case #34: 61361Case #35: 42029Case #36: 39705Case #37: 39338Case #38: 40017Case #39: 41798Case #40: 45961Case #41: 38850Case #42: 44414Case #43: 53594Case #44: 43382Case #45: 42110Case #46: 37586Case #47: 46685Case #48: 40793Case #49: 39049Case #50: 39141123456789101112131415161718A double-square number is an integer <b>X</b> which can be expressed as thesum of two perfect squares. For example, 10 is a double-square because 10 =3<sup>2</sup> + 1<sup>2</sup>. Your task in this problem is, given <b>X</b>, determine the number of ways in which it can be written as the sum of twosquares. For example, 10 can only be written as 3<sup>2</sup> + 1<sup>2</sup>(we don't count 1<sup>2</sup> + 3<sup>2</sup> as being different). On theother hand, 25 can be written as 5<sup>2</sup> + 0<sup>2</sup> or as4<sup>2</sup> + 3<sup>2</sup>.<br/><br/><h3>Input</h3>You should first read an integer <b>N</b>, the number of test cases. The next<b>N</b> lines will contain <b>N</b> values of <b>X</b>.<h3>Constraints</h3>0 ≤ <b>X</b> ≤ 2147483647<br>1 ≤ <b>N</b> ≤ 100<h3>Output</h3>For each value of <b>X</b>, you should output the number of ways to write<b>X</b> as the sum of two squares.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364631025301245665325110542255525276257182513812516022580112520829254005625592832529641625770682251482081252430613251215306625214748364221474836432147483644214748364521474836462147483647510644794625058908181637141932686481812574318734154852231740798996372654318104149351832612250747320007471330296910770039761538292481109635445342133082011482843221475149141100058258920279290491941554117132864909310480391206025191128745665968583200771369439656102290785619918912215429156651234567891011121314151617181920212223A double-square number is an integer **X** which can be expressed as the sumof two perfect squares. For example, 10 is a double-square because 10 = 32 \+12. Your task in this problem is, given **X**, determine the number of ways inwhich it can be written as the sum of two squares. For example, 10 can only bewritten as 32 \+ 12 (we don't count 12 \+ 32 as being different). On the otherhand, 25 can be written as 52 \+ 02 or as 42 \+ 32.
### Input
You should first read an integer **N**, the number of test cases. The next**N** lines will contain **N** values of **X**.
### Constraints
0 ≤ **X** ≤ 2147483647 1 ≤ **N** ≤ 100
### Output
For each value of **X**, you should output the number of ways to write **X**as the sum of two squares.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263Case #1: 1Case #2: 2Case #3: 0Case #4: 1Case #5: 1Case #6: 1Case #7: 1Case #8: 1Case #9: 0Case #10: 2Case #11: 3Case #12: 4Case #13: 5Case #14: 6Case #15: 8Case #16: 9Case #17: 10Case #18: 12Case #19: 16Case #20: 18Case #21: 20Case #22: 24Case #23: 32Case #24: 36Case #25: 40Case #26: 48Case #27: 64Case #28: 0Case #29: 0Case #30: 0Case #31: 0Case #32: 0Case #33: 0Case #34: 0Case #35: 0Case #36: 0Case #37: 0Case #38: 0Case #39: 0Case #40: 0Case #41: 0Case #42: 0Case #43: 0Case #44: 2Case #45: 1Case #46: 1Case #47: 2Case #48: 1Case #49: 4Case #50: 1Case #51: 1Case #52: 2Case #53: 2Case #54: 1Case #55: 4Case #56: 8Case #57: 4Case #58: 1Case #59: 1Case #60: 4Case #61: 2Case #62: 1Case #63: 2123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263At the arcade, you can play a simple game where a ball is dropped into the topof the game, from a position of your choosing. There are a number of pegsthat the ball will bounce off of as it drops through the game. Whenever theball hits a peg, it will bounce to the left with probability 0.5 and to theright with probability 0.5. The one exception to this is when it hits a peg onthe far left or right side, in which case it always bounces towards themiddle.<br/><br/>When the game was first made, the pegs where arranged in a regular grid.However, it's an old game, and now some of the pegs are missing. Your goal inthe game is to get the ball to fall out of the bottom of the game in aspecific location. Your task is, given the arrangement of the game, todetermine the optimal place to drop the ball, such that the probability ofgetting it to this specific location is maximized.<br/><br/>The image below shows an example of a game with five rows of five columns.Notice that the top row has five pegs, the next row has four pegs, the nextfive, and so on. With five columns, there are four choices to drop the ballinto (indexed from 0). Note that in this example, there are three pegsmissing. The top row is row 0, and the leftmost peg is column 0, so thecoordinates of the missing pegs are (1,1), (2,1) and (3,2). In this example,the best place to drop the ball is on the far left, in column 0, which gives a50% chance that it will end in the goal.
<pre>x.x.x.x.x x...x.xx...x.x.x x.x...xx.x.x.x.x G
'x' indicates a peg, '.' indicates empty space.</pre><h3>Input</h3>You should first read an integer <b>N</b>, the number of test cases. Each of thenext <b>N</b> lines will then contain a single test case. Each test case will startwith integers <b>R</b> and <b>C</b>, the number of rows and columns (<b>R</b>will be odd). Next, an integer <b>K</b> will specify the target column.Finally, an integer <b>M</b> will be followed by <b>M</b> pairs of integer<b>r<sub>i</sub></b> and <b>c<sub>i</sub></b>, giving the locations of themissing pegs.<h3>Constraints</h3><ul><li>1 ≤ <b>N</b> ≤ 100</li><li>3 ≤ <b>R</b>,<b>C</b> ≤ 100</li><li>The top and bottom rows will not have any missing pegs.</li><li>Other parameters will all be valid, given <b>R</b> and <b>C</b></li></ul><h3>Output</h3>For each test case, you should output an integer, the location to drop theball into, followed by the probability that the ball will end in columns<b>K</b>, formatted with exactly six digits after the decimal point (round thelast digit, don't truncate).<h3>Notes</h3>The input will be designed such that minor rounding errors will not impact theoutput (i.e. there will be no ties or near -- up to 1E-9 -- ties, and the direction of roundingfor the output will not be impacted by small errors).
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960At the arcade, you can play a simple game where a ball is dropped into the topof the game, from a position of your choosing. There are a number of pegs thatthe ball will bounce off of as it drops through the game. Whenever the ballhits a peg, it will bounce to the left with probability 0.5 and to the rightwith probability 0.5. The one exception to this is when it hits a peg on thefar left or right side, in which case it always bounces towards the middle. When the game was first made, the pegs where arranged in a regular grid.However, it's an old game, and now some of the pegs are missing. Your goal inthe game is to get the ball to fall out of the bottom of the game in aspecific location. Your task is, given the arrangement of the game, todetermine the optimal place to drop the ball, such that the probability ofgetting it to this specific location is maximized. The image below shows an example of a game with five rows of five columns.Notice that the top row has five pegs, the next row has four pegs, the nextfive, and so on. With five columns, there are four choices to drop the ballinto (indexed from 0). Note that in this example, there are three pegsmissing. The top row is row 0, and the leftmost peg is column 0, so thecoordinates of the missing pegs are (1,1), (2,1) and (3,2). In this example,the best place to drop the ball is on the far left, in column 0, which gives a50% chance that it will end in the goal.
x.x.x.x.x x...x.x x...x.x.x x.x...x x.x.x.x.x G 'x' indicates a peg, '.' indicates empty space.
### Input
You should first read an integer **N**, the number of test cases. Each of thenext **N** lines will then contain a single test case. Each test case willstart with integers **R** and **C**, the number of rows and columns (**R**will be odd). Next, an integer **K** will specify the target column. Finally,an integer **M** will be followed by **M** pairs of integer **ri** and **ci**,giving the locations of the missing pegs.
### Constraints
* 1 ≤ **N** ≤ 100 * 3 ≤ **R**,**C** ≤ 100 * The top and bottom rows will not have any missing pegs. * Other parameters will all be valid, given **R** and **C**
### Output
For each test case, you should output an integer, the location to drop theball into, followed by the probability that the ball will end in columns**K**, formatted with exactly six digits after the decimal point (round thelast digit, don't truncate).
### Notes
The input will be designed such that minor rounding errors will not impact theoutput (i.e. there will be no ties or near -- up to 1E-9 -- ties, and thedirection of rounding for the output will not be impacted by small errors).
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960Case #1: 0 0.375000Case #2: 1 1.000000Case #3: 1 1.000000Case #4: 0 1.000000Case #5: 0 0.500000Case #6: 0 1.000000Case #7: 3 0.500000Case #8: 0 0.375000Case #9: 0 0.625000Case #10: 0 0.500000Case #11: 1 1.000000Case #12: 0 0.500000Case #13: 2 0.250000Case #14: 0 1.000000Case #15: 2 1.000000Case #16: 1 0.500000Case #17: 0 0.375000Case #18: 0 0.273438Case #19: 25 0.139282Case #20: 26 0.094469Case #21: 5 0.343750Case #22: 52 0.229212Case #23: 8 0.144334Case #24: 11 1.000000Case #25: 4 0.273438Case #26: 5 0.312500Case #27: 9 0.118933Case #28: 7 0.382813Case #29: 17 0.130849Case #30: 11 0.090337Case #31: 63 0.235746Case #32: 16 0.194322Case #33: 6 0.103375Case #34: 76 0.124419Case #35: 44 0.234087Case #36: 35 0.298492Case #37: 52 0.158363Case #38: 23 0.060319Case #39: 28 0.078013Case #40: 60 0.112882Case #41: 15 0.283266Case #42: 88 0.140881Case #43: 44 0.250275Case #44: 3 0.126945Case #45: 51 0.101507Case #46: 25 0.077408Case #47: 60 0.108157Case #48: 8 0.105733Case #49: 43 0.343750Case #50: 61 0.216110Case #51: 25 0.102611Case #52: 63 0.126953Case #53: 74 0.375000Case #54: 27 0.245132Case #55: 52 0.186421Case #56: 95 0.093098Case #57: 30 0.078492Case #58: 85 0.459503Case #59: 83 0.147201Case #60: 48 0.096127123456789101112131415You've been given a list of words to study and memorize. Being a diligent student of language and the arts, you've decided to not study them at all and instead make up pointless games based on them. One game you've come up with is to see how you can concatenate the words to generate the lexicographically lowest possible string.<br/><br/>
<h3>Input</h3>As input for playing this game you will receive a text file containing an integer <strong>N</strong>, the number of word sets you need to play your game against. This will be followed by <strong>N</strong> word sets, each starting with an integer <strong>M</strong>, the number of words in the set, followed by <strong>M</strong> words. All tokens in the input will be separated by some whitespace and, aside from <strong>N</strong> and <strong>M</strong>, will consist entirely of lowercase letters.<br/><br/>
<h3>Output</h3>Your submission should contain the lexicographically shortest strings for each corresponding word set, one per line and in order.<br/><br/>
<h3>Constraints</h3>1 ≤ <strong>N</strong> ≤ 100<br/>1 ≤ <strong>M</strong> ≤ 9<br/>1 ≤ all word lengths ≤ 10<br/>12345678910111213141516171819202122232425262728293031323334353637383940396 facebook hacker cup for studious students5 k duz q rc lvraw5 mybea zdr yubx xe dyroiy5 jibw ji jp bw jibw5 uiuy hopji li j dcyi9 i hsmh hsmheh xgi eh xg xgeh xnfc ihsmh9 gm souyd fsrd bjnnuknqs rvncvkvssd gxfl wjmeagyob pahil nkfrcuhjh9 nnozzwtf ahkjj wtp t sj htawm ihw egzinwju vn9 rnnabb ldk ndhn rnnaldk zeabbbb zeabb zea rnna bb9 m xmnz mlk vlk lk iwkf lkiwkf vm v9 rgh woqg dmabatgbt qrvpcrx eluunoi sy w wnthqxgkg aimallazuc9 zvow qhx hx vth qhxhxdfgt q dfgt hxdfgt qhxq9 wjxwgm qdhmzkmpzv uhibo gcikegpzv ceqiwekdx rxegvkc ujjvbv kfit peiawyk9 jg j uj ujnzdng nzdng nzdn e g ujnzdngj9 qxwd bejf wfaua rvkorigcm psdflr utgcsj iaolpoazv hmzczeg hqktnql9 k itqsgpwze ma yhpncg xtf w m kahula zgbo9 nl jtdmdxu ux nlmnyzdxu mnyz jtdm nlmnyz dxu uxdxu9 a yncoklkc ek yyfqebh je edzhujjc gpmb ktqimdtw opka9 joicfs joi xul nzndjoi nzndjoijoi nznd nzndjoijoi ssre cfs9 vkzzfgtobz i tkczlqaf peqmnyoh eogzpbe bgorlllxor bkkupvnqr gsr xfqmteh9 hdfeax d s uxnnrzko nxpcu v njxqbnh aaqzeeb kxpkw9 ikjea pdizqbo cwvswrhe m fw yyxcoj ggwgyonra ep tbnoazzs9 eavcqvv wyuh mkfq not evhlpur eidqnartht pesgphnnlq t ztvu9 ld r d lo rlo rlol l rd ix9 o zt da wv brorejctww fu phnej ynrdkylwys ekggrmehcl9 z dvqgfh wqx vnajabkqvs sdwkc dlhcnc ezrcvsc teje gzwwj9 dcn csmzj krnc vkcoume wvpva yqoexwujwp v cxepgptf xb9 r wwwr ndtc ndtclp lpb b wwwb www lp9 fujv mzr kgukjmokvz schpxugnef p rjojpzbsro wpobp wl od9 wehfri kclm ri qgca gt qgcagt qgcagt wehf qgcagtqgca9 u ufmu ufmuqfy vmc ufm uqfy z vmcu qfy9 c evaxdeyrxb rhhfmdm xq vxedern diqs tpdofbc rbq kbxdy9 iccrmcrm mwp sil iccrmcrm ic odo iccrm crm odocrm9 ksdzsjz bbio ja mvvyxzkmq zgdvxolmt xgvwdbfqzn rhubnqtaad qa eeb9 myrzwdyhv pojiires fbjbkcbtq pzdfuxfh rq ukbom ypkffomyl tdko zbwqkbuu9 krqeokrq weo usau krqeo eo zltg krq w zltgkrq9 orth xlruwr afpjkzr qtrrmfpr lvqsidbp qcr dcg xcykyy trarmefmf9 s minpax ax zit cyax zitax minp zitaxminp cy9 izqht h qpbdayaifl pjsoie sujccnm umj dralemrspo euswuti m1234567891011121314151617181920212223242526272829You've been given a list of words to study and memorize. Being a diligentstudent of language and the arts, you've decided to not study them at all andinstead make up pointless games based on them. One game you've come up with isto see how you can concatenate the words to generate the lexicographicallylowest possible string.
### Input
As input for playing this game you will receive a text file containing aninteger **N**, the number of word sets you need to play your game against.This will be followed by **N** word sets, each starting with an integer **M**,the number of words in the set, followed by **M** words. All tokens in theinput will be separated by some whitespace and, aside from **N** and **M**,will consist entirely of lowercase letters.
### Output
Your submission should contain the lexicographically shortest strings for eachcorresponding word set, one per line and in order.
### Constraints
1 ≤ **N** ≤ 100 1 ≤ **M** ≤ 9 1 ≤ all word lengths ≤ 10
123456789101112131415161718192021222324252627282930313233343536373839Case #1: cupfacebookforhackerstudentsstudiousCase #2: duzklvrawqrcCase #3: dyroiymybeaxeyubxzdrCase #4: bwjibwjibwjijpCase #5: dcyihopjijliuiuyCase #6: ehhsmhehhsmhihsmhixgehxgixgxnfcCase #7: bjnnuknqsfsrdgmgxflnkfrcuhjhpahilrvncvkvssdsouydwjmeagyobCase #8: ahkjjegzinwjuhtawmihwnnozzwtfsjtvnwtpCase #9: bbldkndhnrnnabbrnnaldkrnnazeabbbbzeabbzeaCase #10: iwkflkiwkflkmlkmvlkvmvxmnzCase #11: aimallazucdmabatgbteluunoiqrvpcrxrghsywnthqxgkgwoqgwCase #12: dfgthxdfgthxqhxhxdfgtqhxqhxqqvthzvowCase #13: ceqiwekdxgcikegpzvkfitpeiawykqdhmzkmpzvrxegvkcuhiboujjvbvwjxwgmCase #14: egjgjnzdngnzdnujnzdngjujnzdngujCase #15: bejfhmzczeghqktnqliaolpoazvpsdflrqxwdrvkorigcmutgcsjwfauaCase #16: itqsgpwzekahulakmamwxtfyhpncgzgboCase #17: dxujtdmdxujtdmmnyznlmnyzdxunlmnyznluxdxuuxCase #18: aedzhujjcekgpmbjektqimdtwopkayncoklkcyyfqebhCase #19: cfsjoicfsjoinzndjoijoinzndjoijoinzndjoinzndssrexulCase #20: bgorlllxorbkkupvnqreogzpbegsripeqmnyohtkczlqafvkzzfgtobzxfqmtehCase #21: aaqzeebdhdfeaxkxpkwnjxqbnhnxpcusuxnnrzkovCase #22: cwvswrheepfwggwgyonraikjeampdizqbotbnoazzsyyxcojCase #23: eavcqvveidqnarthtevhlpurmkfqnotpesgphnnlqtwyuhztvuCase #24: dixldllordrlolrlorCase #25: brorejctwwdaekggrmehclfuophnejwvynrdkylwysztCase #26: dlhcncdvqgfhezrcvscgzwwjsdwkctejevnajabkqvswqxzCase #27: csmzjcxepgptfdcnkrncvkcoumevwvpvaxbyqoexwujwpCase #28: blpblpndtclpndtcrwwwbwwwrwwwCase #29: fujvkgukjmokvzmzrodprjojpzbsroschpxugnefwlwpobpCase #30: gtkclmqgcagtqgcagtqgcagtqgcaqgcariwehfriwehfCase #31: qfyufmufmuqfyufmuuqfyuvmcuvmczCase #32: cdiqsevaxdeyrxbkbxdyrbqrhhfmdmtpdofbcvxedernxqCase #33: crmiccrmcrmiccrmcrmiccrmicmwpodocrmodosilCase #34: bbioeebjaksdzsjzmvvyxzkmqqarhubnqtaadxgvwdbfqznzgdvxolmtCase #35: fbjbkcbtqmyrzwdyhvpojiirespzdfuxfhrqtdkoukbomypkffomylzbwqkbuuCase #36: eokrqeokrqeokrqkrqusauweowzltgkrqzltgCase #37: afpjkzrdcglvqsidbporthqcrqtrrmfprtrarmefmfxcykyyxlruwrCase #38: axcyaxcyminpaxminpszitaxminpzitaxzitCase #39: dralemrspoeuswutihizqhtmpjsoieqpbdayaiflsujccnmumj1234567891011121314151617<p>Let's call a sequence of integers a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>N</sub> <i>almost monotonic</i> if first K elements are non-decreasing sequence and last N-K+1 elements are non-increasing sequence: a<sub>1</sub>≤a<sub>2</sub>≤...≤a<sub>K</sub> and a<sub>K</sub>≥a<sub>K+1</sub>≥...≥a<sub>N</sub>.</p>
<p>The <i>diversity number</i> of a sequence a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>N</sub> is the number of possible sequences b<sub>1</sub>, b<sub>2</sub>,..., b<sub>N</sub> for which 0≤b<sub>i</sub><a<sub>i</sub> and all of the numbers b<sub>1</sub>, b<sub>2</sub>,..., b<sub>N</sub> are different. The diversity number of an empty sequence is 1.</p>
<p>You need to find the sum of the diversity numbers of all almost monotonic subsequences of a sequence. Since this number can be very large, find it modulo 1,000,000,007. A subsequence is a sequence that can be obtained from another sequence by deleting some elements without changing the order of the remaining elements. Two sequences are considered different if their lengths differ or there is at least one position at which they differ.</p>
<h2>Input</h2><p>The first line of the input file consists of a single number <strong>T</strong>, the number of test cases. Each test case consists of a number <strong>M</strong>, the number of elements in a sequence, followed by <strong>M</strong> numbers <strong>n</strong>, elements of some sequence (note that this sequence is not necessarily <i>almost monotonic</i>). All tokens are whitespace-separated</p>
<h2>Constraints</h2><p><strong>T</strong> = 20<br/>1 ≤ <strong>M</strong>, <strong>n</strong> ≤ 100</p>
<h2>Output</h2><p>Output T lines, with the answer to each test case on a single line.</p>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121601122 131 3 241 3 1 242 3 4 374 3 2 1 3 8 998 6 3 9 7 1 9 1 6103 1 1 2 1 1 1 3 3 1101 1 1 5 7 7 4 4 7 7101 1 1 1 3 4 3 3 4 41210 2 10 4 8 3 9 2 14 1 3 11125 4 6 8 6 8 8 5 12 7 14 14142 3 3 3 4 4 4 4 4 4 1 3 4 3144 4 1 1 3 3 3 2 2 1 1 1 2 4179 4 11 9 9 9 2 9 11 12 5 8 4 13 1 11 15294 85 91 90 90 9 74 59 16 18 18 57 53 19 22 85 22 42 41 57 38 25 36 36 78 36 36 27 28 30 25 24 21 31 20 43 17 44 16 44 48 58 14 5 1 86 66 77 42 78 83 84538 10 5 10 22 9 10 2 14 2 19 10 3 8 2 3 10 4 8 4 6 11 8 16 24 26 4 21 13 11 21 13 2 12 27 20 23 2 25 28 18 15 15 23 24 18 28 28 11 25 1 21 23554 45 12 12 6 42 37 12 45 26 27 12 18 18 22 36 27 18 17 28 20 3 20 39 20 31 31 20 36 20 20 30 15 35 29 24 30 11 19 25 4 33 35 38 16 20 31 3 38 38 39 15 40 13 345710 48 5 11 45 22 42 49 23 7 7 49 38 10 26 37 42 25 29 33 41 36 34 31 30 15 16 32 11 32 45 41 18 7 28 39 19 25 4 33 6 6 27 6 29 27 4 25 24 28 2 34 40 9 40 44 26341 2 3 3 37 3 3 3 3 8 9 9 13 14 37 18 14 33 14 14 14 22 24 7 26 28 29 10 22 7 34 4 2 33 20 39 33 33 33 40 35 36 36 33 37 38 38 40 9 38 40 38 40 22 40 43 6 43 13 5 43 18 216428 56 53 46 49 54 46 41 42 20 16 47 28 60 39 61 59 20 22 16 33 59 64 62 62 20 51 39 3 26 15 53 48 27 43 50 41 55 35 1 57 12 60 5 14 23 11 35 49 9 58 44 42 49 34 9 13 36 49 7 30 5 20 646986 82 84 90 56 86 64 81 72 71 67 72 58 66 56 10 47 35 43 55 27 48 52 90 73 45 68 36 66 90 15 30 42 48 30 15 41 24 36 65 57 56 23 7 88 29 31 53 35 20 12 93 52 50 16 71 12 44 73 24 27 38 26 21 21 21 18 11 17175 75 76 66 71 66 58 62 61 57 55 16 57 56 26 55 55 73 50 35 53 49 46 46 45 46 44 44 35 1 21 34 34 43 32 38 29 29 29 34 54 29 61 29 33 33 31 29 27 27 26 23 26 64 66 11 26 8 71 8 4 23 1 19 11 43 71 4 2 2 17531 11 2 35 1 2 28 9 35 3 3 3 7 7 31 28 26 8 5 9 7 31 11 16 30 30 2 12 30 2 29 19 26 32 21 24 25 13 21 13 32 13 16 23 22 32 16 15 35 22 25 25 19 16 15 12 12 13 12 27 15 10 12 12 6 5 30 34 30 5 30 30 32 33 37560 57 59 53 3 53 53 5 53 6 52 51 52 49 43 51 42 49 10 49 42 49 46 45 35 45 34 34 44 33 22 39 39 36 32 22 33 30 32 32 29 26 30 26 25 25 19 19 24 20 20 13 28 10 10 28 10 15 13 32 8 13 7 7 34 51 6 5 3 1 5 4 1 54 18080 72 11 10 80 28 73 7 29 61 65 74 45 68 37 34 6 30 31 16 48 75 49 23 34 52 71 40 19 24 50 29 57 42 63 30 47 43 46 47 42 55 30 29 62 73 7 56 2 42 45 57 51 28 45 52 53 51 34 57 25 27 12 34 62 59 31 26 69 41 21 24 15 58 14 48 20 10 32 668534 90 83 39 86 79 11 49 95 87 13 35 79 17 47 34 20 84 66 24 70 63 32 39 55 72 40 80 87 17 32 61 90 69 58 26 86 58 60 34 29 54 14 29 23 68 49 76 23 91 49 65 36 50 73 13 32 42 93 32 29 29 12 19 66 28 66 8 6 22 13 4 73 62 13 87 23 16 88 16 1 70 2 91 948414 14 20 20 20 5 19 8 5 18 11 7 18 18 18 17 9 16 16 16 14 13 11 18 12 12 4 12 12 12 7 20 9 20 11 10 10 20 9 9 9 9 8 8 17 4 8 8 20 7 8 8 8 3 6 12 6 6 15 1 5 11 5 3 6 5 1 5 5 18 14 18 4 4 4 2 20 4 13 2 4 1 1 18917 17 6 5 16 16 17 10 16 17 17 1 8 14 14 15 7 6 5 14 16 13 14 14 3 14 16 14 14 13 14 14 11 10 6 9 16 10 6 10 8 13 13 9 5 11 9 6 10 8 8 13 7 5 7 16 4 7 16 5 7 2 3 3 15 15 8 7 6 14 6 6 5 5 15 6 6 11 4 2 6 6 5 7 3 1 5 3 39198 98 4 15 3 98 34 47 30 87 7 98 71 98 96 13 42 97 76 77 66 95 29 75 71 32 50 61 60 49 73 60 69 66 35 65 18 36 62 64 49 42 50 60 51 44 15 53 31 77 57 73 23 79 45 85 44 14 42 79 42 42 41 87 80 88 13 93 78 41 31 14 92 15 27 89 23 48 43 4 22 13 2 94 15 52 3 12 8 94 9610037 1 26 4 32 37 39 18 2 39 2 3 15 6 16 2 34 3 28 4 19 3 13 47 4 23 21 39 21 8 23 26 45 12 19 25 27 40 39 23 32 2 26 23 29 46 23 31 33 19 32 36 29 34 38 7 36 25 8 5 36 17 37 43 37 39 23 22 43 16 18 10 44 25 37 45 20 39 2 38 45 14 38 42 12 45 46 41 47 1 45 46 4 46 5 43 26 27 46 431001 27 2 20 9 9 28 2 30 5 27 17 10 1 11 27 30 9 8 1 10 14 23 2 17 30 20 11 6 22 9 18 17 26 1 20 6 25 11 11 25 14 12 13 1 30 11 26 13 23 9 26 17 26 11 2 13 5 6 18 18 30 12 24 4 13 15 20 15 6 18 7 28 6 18 2 23 26 18 26 1 5 12 4 10 9 20 20 21 18 13 30 21 29 24 18 25 12 22 249260 4 73 24 67 12 5 20 10 11 39 12 13 14 73 14 68 43 42 66 11 74 29 8 70 71 25 28 62 28 16 55 26 43 53 35 19 62 58 15 38 57 40 47 40 40 69 57 73 19 46 57 30 40 37 33 35 59 40 17 52 48 46 26 71 22 42 60 4 75 47 48 55 12 27 60 40 73 40 34 67 6 55 60 44 72 15 44 73 26 69 70931 23 1 17 23 24 20 24 2 20 24 19 2 2 3 24 3 21 3 5 5 20 9 19 9 14 17 18 17 14 16 14 15 15 18 19 15 17 21 24 21 2 15 17 13 19 13 11 21 11 22 22 22 22 2 10 23 17 9 18 9 9 6 23 14 12 10 23 1 1 1 23 23 23 1 23 23 9 23 24 7 24 24 1 24 24 24 5 5 1 2 1 24906 60 63 61 6 37 59 53 59 51 3 9 59 59 27 28 58 51 36 54 51 59 54 41 50 25 50 25 45 32 57 2 43 16 22 38 54 44 36 5 14 38 23 38 32 44 43 40 42 38 41 39 34 29 7 35 33 32 1 33 23 26 23 32 45 21 27 16 16 19 19 27 36 52 10 4 39 1 30 18 16 16 1 46 8 8 59 57 1 6982 35 3 6 6 10 2 10 10 10 38 63 7 11 11 19 9 9 9 9 12 19 14 15 20 57 21 15 21 16 19 20 21 26 21 22 22 26 26 28 29 27 30 36 61 29 31 31 33 33 41 41 44 63 63 33 35 33 36 36 40 42 46 46 63 65 47 66 67 48 48 71 49 76 49 77 51 83 77 51 54 78 54 55 58 78 82 58 83 62 18 65 65 70 78 78 79 809639 35 39 39 39 1 35 2 37 37 31 30 25 7 29 29 28 9 36 27 26 20 16 39 34 26 31 39 26 26 26 21 1 11 25 23 23 21 3 14 2 26 3 28 14 28 14 20 7 28 13 12 12 25 12 14 25 26 11 26 9 26 25 24 7 4 23 23 23 23 20 20 20 16 15 4 9 17 38 9 8 8 1 8 1 36 5 17 1 1 2 17 2 1 1 12912 3 32 31 31 3 31 4 4 4 7 7 8 8 26 8 9 24 9 23 9 9 9 10 14 16 17 18 6 18 23 23 10 11 22 18 11 20 20 18 13 20 14 21 22 23 14 23 19 23 18 23 21 14 12 23 9 23 9 24 13 23 24 9 23 9 23 24 23 25 9 8 7 27 27 26 27 27 4 27 28 28 31 31 18 30 31 32 32 1 32959 19 47 46 11 47 43 41 9 47 39 48 9 39 37 35 37 11 35 41 15 35 9 10 33 31 31 11 11 13 13 47 29 32 20 14 28 42 35 18 27 31 27 27 20 27 4 21 31 37 21 32 31 13 13 31 42 31 22 22 27 27 26 10 31 25 22 46 26 25 21 3 39 2 30 37 33 24 43 39 21 21 15 23 23 17 23 42 26 30 3 2 10 46 3971 32 46 45 12 22 47 46 42 43 42 36 39 39 36 36 17 35 39 37 36 35 34 33 32 35 4 27 27 26 34 26 26 45 18 26 30 27 26 3 26 25 23 22 37 21 26 23 21 20 19 17 23 23 23 22 17 15 22 15 23 20 22 21 4 15 11 8 20 34 20 17 17 46 17 10 9 19 1 19 8 13 8 24 7 22 12 6 27 6 11 5 7 3 7 24 5902 11 29 12 19 30 13 81 75 2 74 13 2 39 24 6 20 75 60 72 8 12 76 7 66 14 63 14 61 32 72 52 11 14 29 73 48 23 13 56 32 34 50 14 20 6 42 55 22 21 35 64 51 36 44 31 53 42 64 9 7 26 34 15 10 23 21 65 67 30 28 6 16 3 66 30 67 47 63 64 67 3 69 46 78 77 20 44 1 76911 34 3 3 4 33 5 5 29 1 8 1 8 1 10 2 29 12 12 12 12 2 12 6 12 8 10 15 12 16 12 12 12 19 12 24 12 24 23 20 21 14 14 14 22 17 17 15 15 21 16 16 17 18 18 25 29 19 21 31 21 21 32 32 22 22 22 23 16 23 14 23 26 12 11 28 6 28 5 35 5 32 35 4 35 32 33 35 35 35 19968 55 1 65 65 17 1 62 61 41 10 61 1 17 61 5 41 5 7 61 14 47 30 17 20 52 8 8 23 17 20 61 68 19 60 57 3 20 9 26 3 38 54 20 18 22 23 49 9 49 29 31 35 22 35 49 47 45 36 33 12 44 45 50 43 41 52 2 41 39 31 30 30 47 29 53 36 42 42 26 26 33 24 54 23 25 68 15 54 66 56 57 27 7 45 66 5 67 679064 58 51 17 29 15 13 49 36 63 27 7 7 62 61 6 54 50 43 12 7 42 19 29 57 10 37 16 21 9 8 57 18 20 3 6 1 39 12 22 21 6 35 45 32 4 8 55 19 16 26 24 63 61 26 24 32 45 7 51 29 8 30 61 44 61 9 64 5 57 36 22 61 14 34 35 23 38 3 59 45 60 23 27 3 2 53 58 1 11006 98 64 95 95 86 84 13 100 70 89 7 100 40 89 54 65 16 65 60 78 60 88 48 23 24 78 81 24 35 45 47 47 76 63 75 74 56 83 41 47 66 74 39 14 38 66 38 22 61 35 65 19 63 63 62 58 56 51 51 49 42 100 75 4 16 42 39 39 37 17 36 8 7 74 34 1 91 7 36 36 31 28 78 27 95 24 4 3 21 17 99 81 10 43 32 15 66 11 81003 4 100 6 10 10 12 99 16 16 84 17 19 20 20 21 23 24 25 27 27 74 29 74 58 29 30 32 46 35 35 35 35 35 36 36 36 42 43 43 28 44 17 45 45 45 47 47 50 22 50 50 51 51 52 53 54 54 20 55 55 55 39 55 56 56 57 16 57 61 61 62 15 67 69 73 77 77 85 86 7 87 87 87 88 88 88 5 88 88 88 89 89 91 91 95 95 97 2 9710096 4 2 99 8 5 23 12 88 17 17 74 7 3 9 5 18 21 29 7 34 40 31 15 21 33 42 46 23 100 35 41 18 24 63 44 58 49 59 36 41 58 28 56 41 27 39 41 10 31 34 34 34 40 44 39 56 61 51 71 62 60 63 62 66 85 41 72 57 58 86 78 53 72 87 58 96 81 39 70 75 7 85 72 84 77 4 78 40 79 87 84 90 85 27 87 31 100 96 1210027 5 4 11 11 13 13 13 13 13 100 13 13 13 86 74 45 14 14 17 17 67 19 20 20 89 69 27 27 30 37 50 55 34 34 89 24 6 34 35 36 36 37 37 63 39 39 41 42 1 45 47 47 48 92 49 49 63 41 64 64 65 38 60 68 69 72 72 35 72 72 75 4 76 81 81 31 86 82 10 14 84 85 85 91 97 91 91 91 90 92 92 92 92 92 92 92 95 98 10010093 2 94 94 94 91 87 89 89 3 83 80 82 16 80 78 77 76 18 75 78 50 70 73 70 70 26 67 67 65 64 27 67 62 29 62 67 27 49 50 65 59 58 50 56 50 50 58 49 42 56 42 62 41 66 36 69 35 47 34 71 42 30 42 27 34 32 32 23 21 18 30 18 13 15 13 72 76 15 3 11 22 15 11 10 81 81 9 9 81 7 10 84 5 3 1 10 6 3 8510098 92 1 97 96 96 96 96 88 96 93 93 89 89 89 29 89 89 88 84 84 84 80 76 76 75 75 74 73 75 73 70 70 69 67 67 67 67 67 66 63 63 63 54 52 51 51 51 51 51 51 51 49 63 49 49 47 47 45 42 41 41 41 74 41 41 38 58 37 36 33 33 30 30 30 29 36 29 28 21 21 21 23 16 20 20 97 19 18 18 18 18 18 13 10 8 8 20 2 210074 6 42 100 1 57 28 100 6 83 97 6 60 60 33 98 69 77 15 29 70 98 94 94 94 37 98 28 29 67 48 53 41 74 41 61 92 85 33 94 62 20 82 96 87 84 80 74 44 33 52 74 27 30 37 65 62 62 33 28 59 36 57 95 26 19 55 43 51 48 16 11 46 25 32 45 39 25 22 15 73 37 36 84 19 41 15 27 32 24 35 14 6 88 38 91 60 4 29 31003 23 85 98 96 91 3 90 86 6 7 97 7 84 8 77 77 10 77 10 14 17 19 20 26 88 26 26 70 59 43 26 16 37 59 59 27 59 9 93 63 55 31 2 28 54 39 62 49 44 31 41 36 41 43 42 1 48 48 50 51 42 60 42 60 65 66 30 68 96 72 75 25 40 36 35 76 34 49 33 26 80 29 82 26 82 24 89 24 23 92 23 95 14 10 9 95 6 98 171002 2 2 6 11 11 13 9 7 89 14 15 14 18 16 18 22 22 24 24 27 26 1 27 30 29 16 31 31 31 33 33 19 33 38 92 53 34 84 39 40 42 49 49 44 48 54 53 80 55 55 60 55 56 56 55 60 1 61 67 33 59 62 66 66 68 68 72 68 71 82 70 48 76 78 79 84 78 84 12 92 86 84 88 92 47 93 89 43 93 90 93 93 96 93 99 95 97 97 97100100 22 76 77 65 18 70 37 97 28 20 4 57 94 19 60 89 81 93 42 57 27 81 9 57 38 30 45 73 95 32 23 97 81 30 66 19 35 69 96 54 92 82 61 28 52 58 67 57 61 54 26 61 48 64 74 55 17 53 36 11 48 64 89 42 48 32 68 80 33 87 9 95 60 18 89 16 47 18 16 23 20 3 16 16 41 93 11 79 16 96 26 21 6 8 37 77 75 34 161002 6 6 5 97 3 15 91 9 15 11 11 84 12 23 81 18 56 37 20 60 26 81 32 27 43 11 89 24 30 80 78 38 70 33 34 33 80 46 37 32 41 34 30 39 86 99 49 49 22 46 41 35 57 36 65 5 15 38 50 55 53 75 75 90 75 35 24 55 75 80 84 57 15 14 64 32 84 26 22 68 13 95 91 11 22 12 56 90 4 97 3 96 94 1 74 79 81 83 9910088 16 30 3 40 30 66 40 82 30 85 35 46 73 58 19 61 25 62 18 41 27 22 82 87 13 13 86 16 2 9 4 93 61 21 52 31 17 40 98 26 71 90 60 56 6 51 29 72 30 14 88 9 77 50 14 77 87 53 98 77 39 3 85 51 79 14 52 36 82 59 56 1 57 18 78 80 97 87 83 99 63 75 31 30 15 91 37 84 33 27 22 30 89 40 1 2 33 61 1410030 20 99 2 28 3 31 9 100 61 2 78 3 32 8 93 92 23 61 33 14 90 98 23 92 98 83 97 79 34 37 16 24 21 80 32 27 47 50 80 46 75 56 86 56 33 58 63 39 62 58 75 45 46 10 43 61 81 72 55 73 66 37 96 29 46 71 67 61 56 45 87 3 45 22 51 16 73 29 77 77 38 77 65 88 27 45 75 24 36 20 26 12 10 79 10 52 19 80 3710086 2 69 74 9 50 10 61 71 81 64 19 15 19 15 80 60 56 52 58 9 100 68 1 32 16 22 52 52 82 62 52 44 36 10 19 55 90 37 30 60 69 61 46 19 44 45 40 40 26 23 69 77 44 16 92 56 26 56 34 44 34 7 69 4 58 76 33 32 45 40 32 30 73 82 87 27 27 82 34 22 21 74 20 30 49 47 11 87 88 81 3 18 100 11 6 3 39 92 941002 7 21 21 22 22 42 58 24 54 23 5 36 13 97 77 52 39 14 77 46 48 28 48 15 61 1 16 16 18 48 74 62 20 55 6 63 84 61 95 24 24 28 64 39 67 60 67 28 76 95 31 31 76 33 76 77 89 52 79 37 54 54 8 55 72 55 74 81 16 87 57 58 75 58 99 81 62 50 56 60 1 74 81 81 85 79 47 80 26 81 87 86 91 100 2 46 22 97 1810059 5 2 5 6 2 6 90 88 58 19 34 6 6 38 20 24 81 22 16 33 35 86 28 74 71 8 44 33 22 44 52 69 50 27 29 23 71 8 41 27 91 71 66 71 48 52 48 61 45 18 48 46 60 93 35 73 48 14 48 72 59 65 48 59 98 64 74 80 51 55 11 6 73 73 3 98 48 16 9 46 69 86 86 88 86 88 19 70 39 51 34 31 5 61 91 83 98 86 111234567891011121314151617181920212223242526272829303132Let's call a sequence of integers a1, a2, ..., aN _almost monotonic_ if firstK elements are non-decreasing sequence and last N-K+1 elements are non-increasing sequence: a1≤a2≤...≤aK and aK≥aK+1≥...≥aN.
The _diversity number_ of a sequence a1, a2, ..., aN is the number of possiblesequences b1, b2,..., bN for which 0≤bi<ai and all of the numbers b1, b2,...,bN are different. The diversity number of an empty sequence is 1.
You need to find the sum of the diversity numbers of all almost monotonicsubsequences of a sequence. Since this number can be very large, find itmodulo 1,000,000,007. A subsequence is a sequence that can be obtained fromanother sequence by deleting some elements without changing the order of theremaining elements. Two sequences are considered different if their lengthsdiffer or there is at least one position at which they differ.
## Input
The first line of the input file consists of a single number **T**, the numberof test cases. Each test case consists of a number **M**, the number ofelements in a sequence, followed by **M** numbers **n**, elements of somesequence (note that this sequence is not necessarily _almost monotonic_). Alltokens are whitespace-separated
## Constraints
**T** = 20 1 ≤ **M**, **n** ≤ 100
## Output
Output T lines, with the answer to each test case on a single line.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960Case #1: 2Case #2: 5Case #3: 15Case #4: 17Case #5: 80Case #6: 1385Case #7: 14225Case #8: 44Case #9: 7582Case #10: 208Case #11: 139062Case #12: 12253464Case #13: 398Case #14: 260Case #15: 95347532Case #16: 526243268Case #17: 929337171Case #18: 147052968Case #19: 195636079Case #20: 389797360Case #21: 665170103Case #22: 16725417Case #23: 146751068Case #24: 7227736Case #25: 518425798Case #26: 266732463Case #27: 507417546Case #28: 503505194Case #29: 232316930Case #30: 988066713Case #31: 517806143Case #32: 300951705Case #33: 753423693Case #34: 566642014Case #35: 71582778Case #36: 674194511Case #37: 812773393Case #38: 29763795Case #39: 250743743Case #40: 836304681Case #41: 351922379Case #42: 797678285Case #43: 883590649Case #44: 978459083Case #45: 789180545Case #46: 843933280Case #47: 812285465Case #48: 339921829Case #49: 145561976Case #50: 396549044Case #51: 697309449Case #52: 83141363Case #53: 734139224Case #54: 933400677Case #55: 747024168Case #56: 405767349Case #57: 746363179Case #58: 196711014Case #59: 975178336Case #60: 81066591012345678910111213141516171819202122232425A simple game consists of a grid of <b>R</b>x<b>C</b> buttons. Each buttonwill be either lighted, or unlighted. Whenever you push a button, the stateof that button, and its (up to) four neighbors will toggle -- lighted buttonswill become unlighted and unlighted buttons will become lighted. Note thatthe neighbors do not 'wrap' and thus a corner button has only two neighbors,while an edge buttons has three.<br/><br/>In this problem you will be given an initial configuration of the buttons.Your task is to push the right buttons so that, when you are done, all of thelights are turned on. If there are multiple ways to do this, you shoulddetermine the minimum number of buttons pushes that it can be done in.<h3>Input</h3>You will first read an integer <b>N</b> the number of test cases. For eachtest case, you will read two integers <b>R</b> and <b>C</b>. This willbe followed by <b>R</b> whitespace-separated tokens, each containing <b>C</b> characters. A 'X'indicates a lighted button, while a '.' indicates an unlighted button.<h3>Constraints</h3><ul><li><strong>N</strong> = 20</li><li>1 ≤ <b>R</b>,<b>C</b> ≤ 18</li></ul><h3>Output</h3>For each test case you should output the minimum number of button pressesrequired to turn on all the lights. If there is no way to do this, you shouldoutput -1.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051605 6XXXXXXXXX.X.XXXXXXX.XXXXXXXXX.1 13..XXXXXXX.X..11 6XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.X.XXXXXXX.XXXXXXXXXX.XX10 13..XX...X.X.X.XX..X..X......X...........X........X........XX..X.X..X..XX........X.....X.X....X....X............XX...X...X....X.....9 3.................X.........7 4XXXXXXXXXXXXXXXXXXXX.XX.XXXX18 18XXXXXXXXX.X.XXXXXXX.XXXXXXXXX.XX..X.XXX.XXX.XXXXXXXXXXXXXXXXXXXXXXXX.XX..XXX.XX.X.XX.XXXX.XXXXXXXXXXXXXXX..XX.XXXXXX.XX...XXXXXXXX...XXXXXXX.XX.XXXXXX.XXXX.XXX.XXXXXXXXXXX..XX.XXX.XXXXXXXXXXXXXX..XXXXXXXX.XXX.XXXXXX.XXXXXXXXX.XXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXX.XXXXXXXX.XXXX.XXXXXXXXX.X.XXX.XXXXXXXXXXX.XXXXXXXXXXXXXXXXXX.X.18 18.X..XXXX...X..X..XXXXXXXXXX.X.XXXXXX.XXXX.XXXXXXX.X..XXX....XX.XX...XX..XXXXXXX.XX.X.X.X.XXXXX.X..X.XXXX.X.XX.XXXXXXXXXX...XXXX..XX.XX.X.XX.XXXX.X.X.XXX.X.X..X...X.X.XXXXXXXXX.X.X..XX..X.XX..XX..XXX..X.XX..X.XX.X.X..X.X.X.XXXXXXX..XXX..X.X..XXXXXXXXXX.XX.XX..XXXXXXXX.XXX.X.XXXXXXXXXX.XXXXXX.XXX.X...XXXXXX..XXXX.XXX...X.X.X18 18....X.X.X.XX.................................X..............X.....XX..............X.X....X......................X...X....X........X........X....XX.........X.......X.............X.X........X.......X......X..........X.X.................X.X.........X.....X........X.....X.X......XX......X.....X...X............X..........X.X...18 18X.........X......X.......................X..........X.............X....................X......X.............XX........XX.....................X...................X.............X....X..X.X............X........X.........X....X..X....X.....X...........X.....XX......X......X.......X.X.............X......X.......................18 18.X..X..XX..X......XXX.XX......XXX.X......X..X.X..X.X.XXX.XXX.X...XX.X..X.XX..XXX..X.X.X...X.X......X....XX.X.X.X.X.X..X.X.X.XX...XXXX.X..XX..XX..X.X.XX.....XX...X.XX...X.....X.X..XXXXXXXX...XXXX....XXXXXXXX.X.XXXXXX..X.XXXX....X.XXX...XXX..XXXX..XXXX..XXX...XX.XXX..XXX.X.XXXX....XXX.XX..XXX.XXXX...XXX.XX.X.XX..X...XX..X..X18 18XXXX..............X..X..X......X.......X....X.X........X...X.......X..X..X...X..............XXXX..X...........XX...X..X..XX.....X.X..X.....X.X.X..........X.................X..X.X..........................X.......X.........X..X....X................XX...............X......X..XXX..X....XX........X.X......................X..XX18 18.XXX.X...XXXX.XX.XXXXXXX.XX.XXX..XX.XXXXX.XX..XXXXXXXXXXXXXX.X.X..XXXXXXXX.XXXXXXXXXXXX.XXXXXXXXX.XXX.XXX.XXX.XXX.X..XXXXX.XXX..XX.X.XXXXXXX.XX.XXXXXXXX.XXXXXXX.XXXXXXXX.XXXXXXXXXXXX.X..X.XX.X.XXXXXX.X.XXXX.XXXXXXXXX.XXXXX..XXXXXXX..XXXX.XXX.XXX.XX.XXX..XXXXX.XXXXXXX.X.XXX..XXXX..X..XXXX.XXXX.XXX.XX.X.XXXXXXXXX.X.XX.XX.XXX18 18..XXXX.......XX..X......X.........XX.......X....X.X.XX...X....X..X...............X.X........X...XXXX............XX.....X...XX.......X........X......................X......................................X..X.X.................XX..X...........X......X....XXX.......X........X.X........X.............X..X.....X........X....X.X18 18.XXXXXXXXXXXX.XX..XXX.XXXXXXX.XXXXXXXX.XXXXX.X.XXX.XXX.XXXXXX.XX.X.XXXX.X.XXX.XXXX.XXXXX.XXXXXXX.XX.XXX.XX..XXXXXX.XXXXXXX.XXXXXXX.XXXXXX.XXXXX.XXXXXXXXXXXXXXX.XXXX.XXXXXXX.X.XXXXXXXXXXXXXX.XXXXXXXXXXXXXX.XXXXXXXX.XXXX.XXXXXXXXXXXX.X.XX.XX.XXXXXXX.XXXXXXXXXXXXX.XXX.XXXX.XXX.XXXX.XXXXX.X..XX.XXXXX.XXXXXX.XX.XXXXXXXXXXXXXXXX18 18XXX..XX.XXXXXXXXX..X..XXXXXXXXXXXX.XX.X..XXXX.XXX.XX.XXX.X.XXX.XXXXX.XXXXXXXXX.XXXXXX.XXXXXXXXXXXXX.XX..XXX..XXXXXX.XXXXXX.XXXXXXX..XX.XXXXXXXXXXXXXXXXXXX..XXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXX...X.XX.XXXXXXX.XXXXX..XXXXXXXX.X.XXXXXX..X.X.XXXXXX.XXX.X.XXXXXXX..XXXXXXXXXXXX..XXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXX..XXXXXXX.18 18.X...X.X..X.............X.X...X.....X......X..........X........XX...........X..............X.X...X...X.............X.X..XX.X........X.X.....X...........X...XX...XX.X...X..X...X...X.X......X....X.X.........X...XX.....XXXXX.X........X................XX...XX.XXX.....X.XX..........X........X...X.....X.......X..............X.X.18 18.XXX..X..X.XX..X.X.......X..X.XXXX.XX.X.XX.XX.XX.XXXXX...XX.X.XXX.X..X....XX..X.XX..XXX.XX.X.X..XXXXX.XX..XXXX.XX..XXX..XXX.X..XXXX.X.XX.XXXXXXXXXXXX.X......XXXX.XXXX.XXX.X.XX.........XX.XXX...XXXX.XXXXX..XX.XXX.X..XX..X.XX.XX..X.X.X.X..X..X....XXXXX..X.XXXX.......X...XXXX..XX.X..X...X.X.....XXXXX.X.X.XX..X..XXXX.X.XX.X..X18 18X...X...........X.X....XXX...X..X.......XX.X...........X.......X.X..X.XX....XX..XXX..........X.X...XX.......X..X.X.X.X..X........X......XX.XX...XX..X....X..X..........X..XX.......XX.....XX..X....X..........XX.X....X.........X...X.......X.X.X..X.X.XXX.X.X..X...X.X..X..X..XXX..XX...XX....X.XXX...X...X.........X...XXXX......X18 18XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXX.X.18 18..............X........X................X........................X.....X..................X..............................................X...............................X......X..........................................................X.....................................X....X......................X.X..XX..X.............18 18XX.X..XXXXXXX..XX...XX...XXXXXX....XXXXXXXXXX..X.XX..X..X..X.X.XXXXX.XX...X.XXXXX.XX.XX.XXXXXXXX....XX.XXX.XX.X.X.X.X...XX.X..X..X...X..X.X..X..X.X.X..XXXXXX..XX...X...X..XXX.X...X..X.X.XXXX..X..XXX.X.X..X.X.XXX.X..X...X.X.X..XX..X.XXXXXXX.....X.X..XXXXXXXX.X..X.X..X.XXXX.X.XXXX.XXXX...XXX..X.X.XX.XX.....X..X.XX.X..XX..X..18 18..X..........X...X...X.....X.X.X.....XX............XXX.......X...........XXXX....X...X.....XX..X..X.....X..X....X..........X.......................XX.X........X......X.X...........X...X.....X......X..X......X...X..X........X......XX....XX...........XX.XX...X..................XXX.X....X..X..X..X....XXX....X............X....18 18XXXXXXX.XXXXXXXXX.X.XXXXXXXXXXXX..XXX.XXXX.X.XX.XXXXX.X.XXXX.XXXXXX.XXX.XX.XXX.X.X.XXXXXXXXXXX..XX.XXXXXXXXX.X.X.XXXXXX..XXXXXX.X.XXX.XXXXXXXXXXXXX.XXXX.X..XXX.XX.XXX.XX.XXXXXXX.XX.XX.X.XX.XXXX..XX.XXXXX.XX.XX..XXXXXXXX.XXXXXXXX.X.X.XXXXXX.XX.X.XXXXXXX.XX.XXXXXXX..XXX..X..X.X.XXXXXX.XXXX.XXXXXXXXX.XXX.XXXXX..X.X.XXXX.XXXXX18 18X....X....X.........X.....XX..........X.X...........X.....X................X..X....X............XX...........X.X......X.........X.X.........XX...X..XX.X........X...X.....X...........X...X.......X...............X.......X...................X................................X...X..........XX.X..................XX..............18 18...........................X..............X...............XX............X....................X....X..X.....................................X.........X...............X......X..............X.........X......X..............X....X.........XX..........X.....................X.................XX.X....X.............X...X......X....18 18..X..X.XX..X.X..X..X.XX.XXXXX..XXXXX.XX.X.....X...X..XXXX.X.X.XXX.XX.X........XXX...X.XX.XXX...XX....XXXX.X..XXX.XXXXX..X.X.X.X.X..X.X..XX.X.XXXX...XX...XX....XX.XX..XXXXXXXX.X.XX.X.....X...X.XXXXXX.XX.X..X...XXX.X.....XX.XXX.X..X...XX.X.X.XXXXXXX....XX.XXX..XXX.......XX.XXXXXX....XXXXX.XXX..XXXX.XXXXXX..X...XXX.XXXX.....X18 18XX...XXX..XX....X.XX..X..XX..XXX.X.X..X...............XX.....X....X..XX.XX....XXX..XXXXXXXXX..X.X...X.X...X.XXXX..X.X....XX...X.X.X..X..X..X...X....XXXX..X.XX.....X.X...X.XXXXX.X.X....XXXX....X.XX.XXX.XX.X.X.XX.XXX.XXX.....X......X.X..XX...........XXX..X.X..X...X.XX...X.XXXX..XX..X...X.X...X...X...XX..X....X....X..........18 18....X.X..X....X.XXXX.X.....X.......XX.X.X.....X....X.XX...X..X.X.X.X...X....XX.XXX.XX..X.....XXX............XX.X.X.X..XX..XXXXX.X...X.X....X....X..X....X..XX.....X.....XX.X....X..........XXXXXXX.....X.X.X.X.X....XX.XX..X.X..XX.XXX.XXXX..XXXXX.X..X.XXXXX..XX........XX.X...X........XX.X....X.......XX.XX...XXX.X.XXX..XXXXXX.X18 18X......X....XX..XX....X.X.X.X.XX.X.XX.X.XXXXXX.XX.X.XXX.......X.XX...X.X..X.X...X.XX.........XXX.X....XXX.X....XXXXX.X...XX.......X.X.X..XXXX.X.X....XX..XX.XXX.X..X.XX..X.XXXXX..X....X...XX.XX.X.....X..XX.X.X...XX.XXX.X..XXX.......XX.XX..X...XX.X..XX...XXXXX...X.XXXX.X....XX.X..X.X...XXX..X.X.XX.X.XXXXX.X.X..XX.X...XXXXX.X18 18.......X.XXXXXXXX.XXXXX..XX.XXXXXXXXX.XXXX.XX..X.XX.XXX..XXXXXX.XXXX....XX.XX.XXX...XXXXXXXXXX..XXX.X...XX...X....X.XXXXXX.X..X.XX..XXXX.XX.X.XXX...X..X..X.XX.XX..X.XX..XX.XX..X...XX.XXXXXXXX.XX.XX..X.X.X.XX.XXXXX..XX..XXXX.XXX.X.XXX.X...X.XX.X.XX.X...X..XXXX.XX....XXX.X.XXXXXX.X.XX....XXXXX.XX..X..XXXX.XXXX.XXX..XX.XXX.X.18 18XXXXXXXXXX.X....X.XX.....XX...XX...X.XX.X.XX...XXXX....X.X....XX..X..X..XXXX..X..XXXX..X.X....X..X.X...XXX..XX.XX.XXX.X...X.X.X...XXX..XXX..XXX.XX.X..X.XX.XXX....X..X..X..XX..XXX....XX.X.XXXX.X..XXXXX.X..XXXX....XXXXXXX...XX...X.XXXX..XX.XX.XX..XXXXXX....X...XXX.XXXXX.X.XX...X.XX.X...XXXXXXX..........X.XXX..XX..X...XXX..XX18 18XXXXXXX..XX.X..XXXX...X.XX..X..XX.XXXXXX.XXXXX.X.X.XXX........XX.XXX..XX......XXX.XX.XXXX....X.X.X...XX..XXX.XXXXXXX.XXX.XX..XXX.X...XXX..XX..XXX...XXX.XXX.XXX.X.XXX....X.XX.XXX.XX.XX.XXX..X.X.XX..X.XXX.XXX...XXXX.X....XXXXXX.XXXX.X.XX...XXX.X.....XXX.X.XXXXXX.X..X.XX...X..X.X...XXX.XX.X..X..X...XX...XXXXX..XXXX.X..XXX.XX.18 18...XX.X.X.....X.X.X..X......X..XX.X..XX.X..X.XX...X.......XXX.X..XXXXX....XX...X...XXXX.XX.XX.XXXXX..X.X.XXXX.XX..........XXX..XX...XXX.....XXX..X..XX.X.X..XX...X.....XX..X.XX..XX...X...XXX....XX....X..X......XXX...XX.X...XX.X...X...X.XX..X...X..X...XXX..X...X........XX.X..X.X.XXX.XX.X.XXX...X.X.XX.X..X.XX.X..XXX..XXXX.X..18 18XXXX.XXXXXXXXXXXX.XXXX.XXXXXX.XXX.X.XXXXXXXXX.XXX.XXXXXXXXX.XX.X.XXXXXXXXX.XX..XXXXXXXXX.X.XXXXXXXXXXXXXXXXXXXXXXXXXX.XXX.X.X.XXXXXXXXXXXXXXXXX.XXXXX.XX.XXXXXXXX.XXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXXXXX.XXXXXXXXXX.XXXXXXX.XX..XXXX.XXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXX.XXXXXXXXX.XXXX..XXXXX.XXXXXXXXX.X.XXXXXXXXXXXXXXX.XXX.XX18 18XXXXXXXXXXXXXXXX...XXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXX.XXXX.XXX.X.XXXXXXXX.XXXXXXXXXX.XXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XX..XXXXXXXXX..XXXXXXX.XXXX.XXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXX.XXXXXXXXXXXXXXX..XXX.XXXXXXXXXXX.XX.XX.XXXXXXXXXXXXXXXXXXXXX18 18..XXX.X..X.XX.X..X..XX....X...XX.X...XX.....X...X.....XXX.X.X.XX...XXX...X..X...X.....XXXX....X......X.X..XXXX.X...X.........XX.......X.X.XX..XXX...XX........X...X.X.X....XXXXXX...XXX..X.....X.X...........X..X.X...XX..X.............XXXXX......X......X..X.XX.X..X.X....X.X...XX....X..X..X.......XX...X...X....X..X.XXXX......X18 18X.....X.X.XX.X.....X...XXXX..XX......X.X....XX...X....XX..XX......X..................X.......X.X.X.XXX.........X...X......X.......X....X......XX..X.X..X......X......X.X.X.....XX..X..X......X...X.X.X.....X.X.X........X...XX.......X.XX..............XX...X.XXX....X...X.........X....XX....XX..X......X.......X.X...X......X.X..X18 18X.XX...X..X..XX.XXXX.X..X...X.XXX.XXX...XXXXXXXXX.XXXXX...XXX.XX..XXXXXXX..XXXXXX...X..X..XXXXXX.X.XX.X.XXX.XX..XXX.X...XXX..XXXXX...X.X..XX...X..XXXXXXXXXX.X.......XXXX.XX.XX...X..XXXX.XX.X.XXXXXXXXXXX.XXXXXXXX.X.X..XXX..XXX...XXX.XXXXX.XXX..X.X..XX.X...X..X.X.XX..XXX.XX.....X...X..XXXXXXXXXXX..XXX.XX..XX.X.XXXXXXXXXXXX.X18 18XXX.XXXXXX.XXXXXXXXX.XX.X..XX..XXXXX.X..XXXXX.XXXXXXX.XX.X..X.XX.XXXX.XXXX.XX.XX.XXXXX.XXXXX.XXXXXXXXXX..XXXXXXXX.XXX.XXXXX.XXXXX.X.X.XXXXXXXXXX.X.XXX.XXXXX.X.XX.X.XXXXXX..XXXXXXX..X.XXXXXXXXX.X.XXXXX.XXXXX..XXXX.XX.X.XXXXXXX..XXX.XXXXX.XXXXXXXXXX.X.XXX....X..XXXX..XXXX.XXXXX.XX..XXX.X.XXX..XX.XXXXX.XX.XX.XXXXXXX.XXXX.XXXX18 18XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXX.XXX.XXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXX..XXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXX.XXXXX.XXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX..XXXXXXXXXX.XXXXXXXXX.XXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX18 18.........X...........XX..X.........XX.........X....................X..X...........X............X.XXX....................X..............X..........X......X.....XX...X.........X.........................XXX........X..X...X...XX..........X..........X..X..X..XX......X.....X...X.....X.......X.X..X.X........X..X........X......X..18 18XXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXX.XXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXX18 18X.XX.X.X....XXXXXX...XX..XX.XX.....X.........X.....X..........X.X..X.XX......X.......X..........X...X.X.X.XXX.......X....X...X..X..XX...X....X.X.X..........X.XX..XXX.XXX.......X.X.X.X......XXXX.X..XXXXX.............X........XX....XX.X.X..X.X.............XXXX....X..X..X.XX..X...XX.XX................X.......X....XX..........18 18.XX.XX...X.X.X..XXX.X..XX.XX...X.XX.XX.XX.XXX.XXX..XX.X.X.X.XX...X..XXXX.X.X.X..XXX..XX.X...X.X..XX.X.XX.XX..XX..XX.X.X..XXX.XXXXXX..XX.X..X.XXXXXX.X.XXX.......XXXXXXX.X.XXX..X..X..XX.XXX.X...XX.......X..X.XXX.XXXX...XXXX...XXXX....X.XXX.X..XX.XX.XX..X.XXX.XX...XX.XXX.XXXX.XXXXX.X.XXX....XXX..X...XXX.XXX......X.XXX..XX....18 18XXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXX.XXXXXXXXXXXXXXXXX..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXX.XX.XXXXXXXXXXXXXXXX.XXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX18 18................................................................................................................................................X....................................X..............................................................................................................................................18 18.............X......X....X.XX.X...........X..........XX..X.....X...XX.......X...X....XX..........X.........X...XX.X.............X...X...................................X....XXX......X..X...X..X..XX.......X...X..XX.X..........................X.XX...X..X.X.X....XX...X.X...X..XX...XX.....X......................XXX............18 18XXXXXXXXXXXXXX....X.X..XXX...X...X.XXXX...XX.XXX.X.XX....XX.X.XX..XX.X....XXX...XXXX..X.....XX....XX...XXX........XXX..X...X..X..X....XXXX.XX.X...XXXX....XXXX.XXX.XX.XX.X.X...X..XXX.X.....X.XXX..X.XX.....X.XXXX..XX..XX.XX.X...XXX.X.X.XX.....X....XX.X.X.X...X...X..X.X.XX..X.....X.X.XXXX....XXXX....XX..XX.X.XX..X..XXX.....XX18 18X.XXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXX.XXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX14 13.XXXXX.XXX.XXXXXXXXXXXXXXXXXXXXXXXX.XX.XXXXXXXXX.XX.XXXXXXXXXXXXXXXXXXXX..XX.XXXXXX.XXX..XXXXXXXX.X.XXXXXXXXXXXXXXXXX.XXXX.XXXXXXXXXXXXXXX.XXX.XXX.XXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXX17 6XX.XX.X.X.XXX.XXXX.XXX...X.XX.XXXXXXXXXXXX...XX.XXX.XXXX.X.XXXX..X.X.XXX.XXXXX.XXXX...XXXX..X.XXX.XXX.15 16...............X......X...........X...X....X.............X.X.....X................X...................X........X..X......X.X.....X..............X.X...............X........X.X...........XX............X..........X.........X.......X...........6 17XXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXX.X.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.X18 18XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX17 17XXXXXXXXX.X.XXXXXXX.XXXXXXXXX.XX..X.XXX.XXX.XXXXXXXXXXXXXXXXXXXXXXXX.XX..XXX.XX.X.XX.XXXX.XXXXXXXXXXXXXXX..XX.XXXXXX.XX...XXXXXXXX...XXXXXXX.XX.XXXXXX.XXXX.XXX.XXXXXXXXXXX..XX.XXX.XXXXXXXXXXXXXX..XXXXXXXX.XXX.XXXXXX.XXXXXXXXX.XXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXX.XXXXXXXX.XXXX.XXXXXXXXX.X.XX17 17........................XX....X...............X......X...........X...X....X.....X.......X.X.....X................X...................X....X...X..X......XXX.....X..............X.X...............X.......XX.XX.XX.......XX....X.......X....X.....X.........X.......X...........X......X...X......17 17..............................................................X...........X...X...................................................X.....................X...............................................X.............XX.........................................................................17 17...........XX.X..X......X.X...X........X.X...X.X....XXXX......X.....X.XXX............X....X.....X.X.....XX.........XX.....X.............X........XX.......XXXX........X....X...X.....X.........XX......X..X...X.X....XX.X.....XXX.X.X........X..X..X.XX.X.X............X..X.X...........X....XXXX17 17..XX.....X.X..X.....X..X....X.X....X..XX...X.X...X...........X..X..XX..X...X.X..X.XX.X.X.XX.XX..X...XX....X......X.XX...........X...X...X..........XX...........X..........XX................X.X..X.............X..X.X....XX.........................X.X.X.....X..X...X.......X.X.X..XX..XX..X.X.123456789101112131415161718192021222324252627282930A simple game consists of a grid of **R**x**C** buttons. Each button will beeither lighted, or unlighted. Whenever you push a button, the state of thatbutton, and its (up to) four neighbors will toggle -- lighted buttons willbecome unlighted and unlighted buttons will become lighted. Note that theneighbors do not 'wrap' and thus a corner button has only two neighbors, whilean edge buttons has three. In this problem you will be given an initial configuration of the buttons.Your task is to push the right buttons so that, when you are done, all of thelights are turned on. If there are multiple ways to do this, you shoulddetermine the minimum number of buttons pushes that it can be done in.
### Input
You will first read an integer **N** the number of test cases. For each testcase, you will read two integers **R** and **C**. This will be followed by**R** whitespace-separated tokens, each containing **C** characters. A 'X'indicates a lighted button, while a '.' indicates an unlighted button.
### Constraints
* **N** = 20 * 1 ≤ **R**,**C** ≤ 18
### Output
For each test case you should output the minimum number of button pressesrequired to turn on all the lights. If there is no way to do this, you shouldoutput -1.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960Case #1: 14Case #2: 7Case #3: 27Case #4: 65Case #5: 11Case #6: 16Case #7: 167Case #8: 152Case #9: 171Case #10: 174Case #11: 170Case #12: 158Case #13: 170Case #14: 166Case #15: 181Case #16: 157Case #17: 150Case #18: 159Case #19: 171Case #20: 169Case #21: 165Case #22: 157Case #23: 161Case #24: 166Case #25: 156Case #26: 170Case #27: 169Case #28: 153Case #29: 164Case #30: 161Case #31: 176Case #32: 156Case #33: 166Case #34: 160Case #35: 166Case #36: 178Case #37: 184Case #38: 169Case #39: 156Case #40: 160Case #41: 137Case #42: 160Case #43: 170Case #44: 135Case #45: 158Case #46: 175Case #47: 169Case #48: 164Case #49: 182Case #50: 163Case #51: -1Case #52: -1Case #53: 136Case #54: -1Case #55: 0Case #56: -1Case #57: -1Case #58: -1Case #59: 136Case #60: -11234567891011121314151617181920212223242526272829A group of Facebook employees just had a very successful product launch. Tocelebrate, they have decided to go wine tasting. At the vineyard, they decideto play a game. One person is given some glasses of wine, each containing adifferent wine. Every glass of wine is labelled to indicate the kind of winethe glass contains. After tasting each of the wines, the labelled glasses areremoved and the same person is given glasses containing the same wines, butunlabelled. The person then needs to determine which of the unlabelled glassescontains which wine. Sadly, nobody in the group can tell wines apart, so theyjust guess randomly. They will always guess a different type of wine for eachglass. If they get enough right, they win the game. You must find the numberof ways that the person can win, modulo 1051962371.<br/><br/>
<h3>Input</h3>The first line of the input is the number of test cases, <strong>N</strong>. The next <strong>N</strong> lineseach contain a test case, which consists of two integers, <b>G</b> and<b>C</b>, separated by a single space. <b>G</b> is the total number of glassesof wine and <b>C</b> is the minimum number that the person must correctlyidentify to win.<br/><br/>
<h3>Constraints</h3><ul> <li><strong>N</strong> = 20</li> <li>1 ≤ <strong>G</strong> ≤ 100</li> <li>1 ≤ <strong>C</strong> ≤ <strong>G</strong></li></ul><br/>
<h3>Output</h3>For each test case, output a line containing a single integer, thenumber of ways that the person can win the game modulo 1051962371.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051501 14 25 513 1014 123 1183 452 315 416 935 262 3969 3098 1632 717 1397 8636 1513 984 7515 833 3189 1282 5930 867 319 675 3566 1914 493 8586 266 4649 3319 470 4960 2375 173 988 5734 2719 1124 356 4471 1796 7874 4730 751 4397 5712345678910111213141516171819202122232425262728293031323334A group of Facebook employees just had a very successful product launch. Tocelebrate, they have decided to go wine tasting. At the vineyard, they decideto play a game. One person is given some glasses of wine, each containing adifferent wine. Every glass of wine is labelled to indicate the kind of winethe glass contains. After tasting each of the wines, the labelled glasses areremoved and the same person is given glasses containing the same wines, butunlabelled. The person then needs to determine which of the unlabelled glassescontains which wine. Sadly, nobody in the group can tell wines apart, so theyjust guess randomly. They will always guess a different type of wine for eachglass. If they get enough right, they win the game. You must find the numberof ways that the person can win, modulo 1051962371.
### Input
The first line of the input is the number of test cases, **N**. The next **N**lines each contain a test case, which consists of two integers, **G** and**C**, separated by a single space. **G** is the total number of glasses ofwine and **C** is the minimum number that the person must correctly identifyto win.
### Constraints
* **N** = 20 * 1 ≤ **G** ≤ 100 * 1 ≤ **C** ≤ **G**
### Output
For each test case, output a line containing a single integer, the number ofways that the person can win the game modulo 1051962371.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950Case #1: 1Case #2: 7Case #3: 1Case #4: 651Case #5: 405146859Case #6: 268080562Case #7: 552088028Case #8: 498632674Case #9: 635191483Case #10: 23541693Case #11: 81808008Case #12: 80187174Case #13: 74001353Case #14: 996152376Case #15: 402231981Case #16: 22917Case #17: 229148997Case #18: 319742759Case #19: 7086Case #20: 863143030Case #21: 13402248Case #22: 529Case #23: 871634493Case #24: 390562784Case #25: 141615833Case #26: 195200775Case #27: 389246543Case #28: 173520569Case #29: 488623143Case #30: 603392721Case #31: 49429646Case #32: 299325777Case #33: 596669446Case #34: 20744057Case #35: 380563847Case #36: 79967853Case #37: 902077391Case #38: 862630060Case #39: 141282623Case #40: 391774960Case #41: 875219463Case #42: 170303393Case #43: 654845005Case #44: 505880537Case #45: 902409729Case #46: 525015203Case #47: 893971096Case #48: 948425733Case #49: 253211239Case #50: 203764253123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566After decades of shadowy demonstrations and delays from the game’s maker, Chess 2 has finally been released. You waited in line all night to be one of the first to purchase an example of the hot sequel to the classic original, and now you are finally getting a chance to open up your new investment and take a look inside. What you find is slightly puzzling; in addition to the traditional pieces, the game has been expanded to contain a number of pieces that are not actually original.<br/><br/>
The best-known piece that has been added to the game is the nightrider. The nightrider can make any number of knight moves in a single direction, i.e., its offset from its initial position will be 2*<strong>m</strong> in one dimension and <strong>m</strong> in the other for some nonzero integer <strong>m</strong>. Like other "sliding" pieces, if one of the knight moves would cause it to take another piece it is not able to traverse beyond that point<br/><br/>
The archbishop is also part of Chess 2. The archbishop can simply make any move that a knight or bishop could legally make.<br/><br/>
The strangest new piece is the kraken. The kraken can move to any square on the board, regardless of the position of any other pieces, including its own current position.<br/><br/>
You don't feel like reading the manual to learn about how the new pieces fit into the standard chess opening positions, so instead you place some of the pieces randomly on the board. The game you’ve decided to play is simply to count how many pieces on the board are currently being threatened. A piece is threatened if another piece is able to move into its cell and take it (note that if the kraken moves into its own cell it does not take itself).<br/><br/>
<h2>Input</h2>Your input file will consist of a single integer <strong>N</strong> followed by <strong>N</strong> test cases. Each case will consist of, all separated by whitespace, an integer <strong>P</strong> followed by the identities and positions of <strong>P</strong> Chess 2 pieces. Pieces are described by a single character <strong>C</strong> to denote their type (see specification below) followed by two integers <strong>R</strong> and <strong>F</strong>, the 1-based rank and file, respectively, of the piece.<br/><br/>
You've decided to ignore the colors of the pieces in this game. The color of the pieces will not be reflected in the input and so cannot affect your output.<br/><br/>
To make room for the new pieces, the Chess 2 board is a 16 by 16 grid. No specified pieces will fall outside the board, and no two pieces will occupy the same position.</br><br/>The types of pieces will be specified as follows, and no entries not present in this table will appear on the board:<table border="1"> <tr> <td>Piece</td> <td>Abbreviation</td> </tr> <tr> <td>King</td> <td>K</td> </tr> <tr> <td>Queen</td> <td>Q</td> </tr> <tr> <td>Rook</td> <td>R</td> </tr> <tr> <td>Bishop</td> <td>B</td> </tr> <tr> <td>Knight</td> <td>N</td> </tr> <tr> <td>Nightrider</td> <td>S</td> </tr> <tr> <td>Archbishop</td> <td>A</td> </tr> <tr> <td>Kraken</td> <td>E</td> </tr></table><br/><br/>
<h2>Output</h2>Output a single integer, the number of threatened pieces on the board, for each test case separated by whitespace.<br/><br/>
<h2>Constraints</h2><strong>N</strong> = 20<br/>3 ≤ <strong>P</strong> ≤ 64<br/>1 ≤ <strong>R, F</strong> ≤ 16<br/><strong>C</strong> will be one of {K, Q, R, B, N, S, A, E}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462504Q 1 1B 3 1B 5 1B 1 4
3S 1 1K 2 3S 3 5
4N 1 1B 3 3Q 5 5N 4 1
5R 2 2N 1 2N 2 1N 16 2N 2 16
6Q 1 1Q 2 3Q 3 5Q 4 2Q 5 4E 1 5
16B 2 7R 4 1S 11 16E 1 3N 3 16E 16 15E 8 7R 6 3A 6 9A 2 9K 10 11B 3 13E 10 3A 12 8A 1 1S 9 1
16B 3 5N 2 9Q 10 16Q 5 10K 3 1B 11 3N 3 8Q 3 16B 4 4B 14 4Q 7 16B 9 15N 1 5Q 2 11S 2 16R 16 4
13E 6 8B 6 5Q 1 9S 16 11R 5 15B 9 5Q 2 7S 5 9K 8 16Q 4 6A 4 9N 9 2N 9 13
41B 6 4A 5 12S 3 4A 16 15K 12 14S 3 7S 6 1Q 11 6R 15 15S 12 13K 7 9Q 16 3E 10 12K 14 9S 11 10K 8 5N 2 10N 1 5R 9 2S 2 5R 11 5A 10 3N 6 6R 10 4A 1 15B 12 9E 11 7S 5 14A 13 15B 1 7R 6 14K 15 2R 9 13E 7 10S 16 1N 10 9Q 9 11Q 15 16E 12 4N 6 13E 4 6
7R 14 8B 6 10K 3 3S 11 14E 10 12N 15 12K 11 11
23A 9 13E 5 12N 6 11Q 15 15Q 5 13K 3 7K 10 7S 13 15A 5 2K 13 9A 7 6B 11 16K 8 7R 12 9S 2 13N 6 14K 13 8K 3 1R 8 8S 12 16K 6 13E 16 16R 13 4
44S 12 3S 4 11E 3 10R 9 1B 7 15A 12 7S 1 4A 8 8B 8 10R 11 8A 8 2R 16 6N 10 4R 5 7Q 6 14B 13 1S 2 5S 1 7B 3 2Q 10 16Q 16 1R 12 15K 14 12Q 6 4R 7 3A 10 14S 7 9K 6 8E 2 10N 11 11Q 15 6S 16 9R 11 4S 8 1E 2 1R 11 10Q 9 14B 3 8E 4 6N 9 3N 12 6K 12 12R 15 16K 3 11
42K 2 5Q 7 8E 14 16A 6 6K 5 1N 12 13A 2 1K 6 12K 7 4E 8 13E 4 4B 11 1S 12 15K 9 16E 2 3N 9 14A 4 12A 11 5A 12 3B 6 8N 2 15N 1 12N 1 6N 15 6E 15 15Q 12 1Q 2 13R 11 4R 11 12K 1 9Q 12 16E 16 6A 4 14B 5 12A 8 12B 15 2E 8 16E 15 4K 8 9S 8 2A 15 12Q 11 6
60N 6 15Q 7 3E 10 11N 9 4Q 9 7Q 3 6A 2 8B 15 13N 10 9Q 11 7R 5 4K 14 5Q 1 15N 1 12S 7 2R 13 4N 4 10S 6 5R 8 15S 11 1R 2 2N 10 1R 1 9E 15 6A 10 3E 3 2K 16 16A 12 7B 14 10B 8 1N 6 8R 11 14B 16 15S 12 13Q 15 12A 12 1B 6 9S 5 12E 9 2A 9 12K 9 9N 12 15A 11 11R 12 6R 13 15B 5 11R 9 16B 6 14E 10 16K 13 5E 9 15N 13 11R 4 6Q 1 14Q 6 6R 3 7K 5 10B 4 3R 4 2A 13 9
24N 2 15E 14 16R 5 10E 16 8N 14 15B 10 12R 1 6K 7 13N 4 3B 12 3B 10 11B 3 8A 13 8B 5 9B 3 11E 7 1K 16 13S 2 2N 15 15E 10 8B 4 12A 7 10K 5 15A 8 2
12B 2 4K 14 13S 6 12E 11 9E 3 1S 3 7R 5 3A 6 6S 8 4K 5 5A 10 6Q 13 16
34B 8 5B 9 9K 12 3B 5 11B 7 9Q 12 1K 15 1K 7 15A 10 2R 12 14A 13 12K 13 15A 10 6N 11 8S 1 5Q 12 16E 2 16A 4 13S 13 14E 14 3Q 16 13K 3 2Q 11 15S 10 12N 3 5R 8 8R 13 10E 15 16S 14 4A 1 15K 16 9R 15 10N 15 9B 3 9
14K 1 5E 7 5B 16 5B 6 1Q 14 1A 6 2B 1 7Q 3 11S 1 12R 6 5K 10 12E 15 16E 7 6Q 2 7
33E 7 15A 10 10Q 12 7K 7 7R 1 14B 10 4Q 12 3E 5 9K 6 4B 2 6K 6 1E 11 11A 5 16N 14 1Q 6 9R 7 5S 15 2N 7 14R 5 10E 8 14E 1 3S 9 8N 13 1S 6 3K 11 16E 10 16K 9 7E 2 8B 16 16R 8 4N 9 6A 12 12A 2 9
39E 1 1N 13 7S 2 1A 13 14S 14 9Q 16 11B 3 6R 9 2N 5 9E 5 2Q 11 4K 8 1A 15 14R 4 6Q 10 2B 6 7Q 11 8N 6 3K 14 5B 3 4E 15 5E 1 16A 4 2S 14 3B 13 8Q 2 11A 14 10S 13 16R 4 7K 8 6E 3 15Q 9 14B 10 6E 11 5R 5 15S 16 13S 13 13A 15 3A 1 10
22B 11 9R 1 14E 7 11K 1 7S 16 4N 5 6E 9 5Q 6 10S 1 9B 3 13A 3 4B 12 15R 4 9R 15 8B 8 15K 13 12A 11 12Q 13 4A 11 6A 11 13K 12 14E 1 11
25N 2 13B 12 14S 1 15A 15 11K 15 7B 9 6B 3 1E 9 13Q 3 14A 12 13S 15 12A 1 16S 6 3B 14 8R 14 5K 11 4N 3 15K 6 13K 9 1A 8 1R 3 3S 4 5A 14 15E 7 15N 12 6
38S 12 2Q 1 11Q 10 10A 14 2K 13 5B 2 2B 13 9E 3 9R 8 6S 14 3R 11 13N 10 7R 12 14S 3 10S 1 6Q 7 13E 8 16R 11 8R 12 9K 11 9Q 6 1S 12 7S 13 12S 11 5B 7 15E 2 7R 16 11A 3 5N 3 8S 8 3S 13 2A 15 5K 6 7R 12 10E 10 5B 10 11E 4 7B 15 15
7Q 11 3K 12 3Q 16 3S 10 16Q 16 15R 8 15R 11 14
30E 10 16A 4 5E 7 12K 4 9N 8 7A 12 14E 12 10N 13 5K 1 12Q 10 3R 2 13K 1 4N 14 11R 1 2E 4 4A 16 4R 6 12Q 2 2S 6 11R 5 2K 9 9A 12 7S 14 12R 12 11R 2 15Q 15 3S 13 14A 9 8R 9 5K 15 14
64Q 6 2E 15 12N 15 4A 7 15Q 9 7Q 7 1B 5 7K 4 10K 14 15Q 5 1E 15 16E 2 4Q 10 3Q 2 5Q 15 13Q 10 4R 11 14B 3 5N 4 16E 5 3E 3 11A 6 12K 4 7A 13 15B 2 8N 13 3R 3 10B 14 13A 3 15R 8 15Q 14 1E 4 12A 10 5B 8 16B 16 13B 16 7S 6 13Q 9 16K 14 9K 2 3A 11 2B 1 5E 13 9Q 14 5S 7 13B 3 6N 7 16S 2 11N 4 9B 3 4S 9 11A 1 1K 4 1A 4 15K 6 1N 8 13S 7 2S 2 15Q 7 4R 8 2E 11 7A 12 11A 8 12A 16 15
15N 6 16B 5 1Q 14 14E 2 15S 9 7K 4 6N 12 16A 10 2R 16 14B 8 15K 9 2B 11 11R 9 5K 13 13R 11 13
25K 9 15S 13 14S 11 13E 3 12K 9 3A 12 7K 16 11Q 1 16K 2 13B 15 7Q 12 1S 8 12E 9 16S 12 12B 9 6N 5 12N 15 12N 7 16E 16 1Q 14 5E 8 16N 11 3R 4 13K 8 14N 6 12
7E 2 13R 7 3Q 5 4E 9 4E 16 16E 4 13K 1 14
10A 3 9K 2 8B 15 16K 12 9A 11 7A 11 5N 13 13E 10 8R 1 16R 6 12
47E 4 5B 3 7E 6 14B 13 12N 9 14R 1 11B 16 4R 3 2E 1 13R 15 12B 1 5S 15 13R 11 11E 7 12N 6 2K 8 16A 7 14Q 11 3A 4 7E 3 10S 12 11B 1 4Q 9 15N 4 3N 11 4S 12 3S 3 11N 3 4K 11 13S 2 12N 5 11Q 5 3Q 13 2Q 7 13Q 7 7A 9 2B 11 12E 8 13K 3 15E 6 4S 7 15Q 14 3E 9 7A 5 7S 13 8A 14 6S 5 5
17B 11 1K 12 3S 11 16K 14 7R 13 15K 8 10R 6 7E 15 13Q 11 3B 9 2K 5 9A 14 4Q 12 15B 10 13N 10 11Q 8 4Q 12 6
3B 8 8Q 4 8A 14 4
43N 15 9A 11 15K 16 2Q 3 7S 1 5S 7 2E 7 13E 5 6A 1 12E 10 3B 3 6K 6 8K 4 5Q 7 12E 13 2B 14 13E 2 11R 7 4K 8 12A 4 9A 15 3A 13 11S 2 6K 13 15B 4 11E 6 14N 11 12S 12 16S 2 5N 6 10K 3 5N 10 9Q 11 10K 2 1N 2 10Q 4 16E 14 3R 10 15K 4 2A 2 14R 1 11A 3 16Q 8 10
44R 3 15N 14 14K 10 5A 11 11Q 13 7E 11 4K 10 1E 9 2S 5 13B 14 7S 11 2A 5 4S 1 3E 10 6K 15 4A 1 10B 9 4B 13 16A 6 8B 2 1K 3 2E 6 3R 11 5S 8 2K 7 14A 10 7Q 12 13K 14 2B 2 14A 12 15R 11 6R 9 16N 8 10S 2 3R 7 15N 13 4R 4 16R 11 16N 14 5K 8 9A 15 1E 12 3A 4 13N 2 15
4Q 15 3E 14 6A 14 15N 2 3
27N 14 13S 16 14B 12 3N 12 2B 12 13A 12 1A 2 2S 16 10S 8 8S 10 5E 11 6R 6 7B 11 4Q 13 14R 11 16S 7 2E 8 16N 12 4S 1 8A 1 4Q 9 1N 5 12B 12 9A 2 16K 4 14S 9 11E 7 11
38S 14 12A 5 3A 7 6Q 6 11N 4 7Q 4 1K 6 1S 9 12S 6 4Q 12 14B 11 7K 10 8B 5 15S 11 5E 14 5Q 9 16A 11 10A 7 10Q 1 2Q 3 7K 5 14A 6 6S 8 14S 10 3A 7 2Q 3 12S 15 7E 6 15E 12 5S 6 8S 16 13B 14 1K 15 5S 2 11S 4 3R 8 15A 5 4Q 3 16
51E 16 10Q 3 11N 3 13R 12 11B 14 4Q 8 14A 9 9E 5 1E 6 15B 7 4A 15 5B 6 6N 8 3N 1 11B 9 13E 12 14Q 15 4A 1 16B 16 6E 2 12K 3 10A 10 8K 9 15R 7 15Q 6 4A 15 14N 12 15S 3 6E 15 10Q 1 9R 3 8S 12 13E 7 2N 4 4A 4 15K 6 3Q 9 2Q 9 12Q 7 6B 2 1Q 6 16S 12 5Q 14 13E 7 1N 11 14B 6 8B 11 12Q 15 8Q 3 7B 8 13Q 13 12
13Q 14 2B 6 14N 12 3B 9 3A 13 13E 7 14S 5 6B 8 11K 11 5R 9 11R 10 10Q 9 15Q 6 4
34K 15 8A 12 7R 2 13R 16 12E 15 9A 16 5A 2 16K 1 1A 10 6A 8 8N 7 11B 13 5K 9 10S 2 8S 13 1S 6 13R 2 10E 15 14K 3 9S 7 16N 16 7S 8 16Q 13 16N 5 8E 9 14R 10 4B 8 10R 12 15N 4 9K 1 15N 16 3A 11 16B 9 2A 3 15
27Q 16 3S 2 6N 11 15N 13 3R 16 4B 6 9E 10 9Q 13 4N 15 14E 4 5N 16 16K 8 2E 11 13R 14 13N 8 9B 6 11K 12 5B 6 3S 15 1K 7 9E 14 5S 10 8A 11 2B 10 13N 4 9R 8 10S 16 12
62R 4 6B 14 16Q 13 11E 5 11E 13 3S 14 1R 5 15K 9 16S 5 12N 1 2N 6 15N 7 15E 4 13S 15 4N 9 6R 5 14B 7 10E 9 3S 4 12B 13 15E 2 10B 7 11B 7 16Q 2 8B 3 14R 6 10N 11 9Q 1 13A 11 5A 15 9A 14 8S 8 14Q 9 13S 4 9A 6 11S 3 5N 7 5Q 1 4N 5 5N 15 10S 6 1A 10 3A 8 10S 12 1Q 15 13R 12 15S 10 2B 4 5S 3 16K 6 5S 15 1K 14 13Q 10 15S 9 7Q 9 11B 7 3A 14 12K 1 5A 16 14K 4 14E 7 4E 12 2
56E 9 10S 8 13N 16 7A 13 10E 8 7S 14 2K 12 14R 13 4S 16 16E 3 12E 10 11K 9 4N 15 16S 1 15K 3 15E 3 2K 16 14K 2 3N 4 14S 14 9B 11 14S 15 9N 3 3K 4 13A 6 9S 1 8R 3 14E 11 9R 5 5A 9 11B 14 13R 14 11B 5 3R 5 7Q 7 4B 14 4S 4 6R 9 9R 15 15R 8 12A 3 6N 10 12E 2 16K 5 1E 13 12K 9 16K 13 5A 11 7R 5 12R 6 15K 2 14Q 15 14B 9 15K 2 10B 11 4N 12 8
23N 7 4A 3 8A 6 13B 2 2S 6 9S 3 16R 2 10R 6 10K 6 16R 12 15R 9 15Q 15 6K 4 10S 4 12Q 16 3B 1 14Q 3 7B 5 8N 4 14A 7 9K 16 6B 4 5R 11 1
42N 6 8A 15 15Q 7 7K 8 1Q 8 12R 4 7S 1 6K 11 6B 5 5Q 6 11A 3 9B 8 4S 4 13N 2 13S 1 4E 13 13N 16 9E 6 13N 7 10A 13 11A 16 6B 14 1Q 10 14N 2 14S 2 15B 10 11R 12 7B 14 9S 16 3R 8 8E 1 3S 6 2A 4 12Q 5 3A 9 14A 8 14N 11 8A 15 10Q 11 9K 4 3N 12 4B 7 14
41Q 12 13B 14 10S 11 13R 4 4S 11 4E 10 15E 7 9A 9 8B 6 4B 8 6E 14 16R 12 11R 4 13N 8 7E 10 4Q 8 14E 11 10K 2 15Q 11 7A 10 12B 5 3B 4 10R 2 5K 16 10Q 11 1Q 10 14E 2 4R 12 4R 7 7R 15 15N 14 5S 1 14S 15 14S 7 14R 14 2S 1 7K 4 8N 14 1E 10 9B 8 4E 11 5
25A 2 11B 8 9A 11 8S 13 4K 7 8K 6 1S 4 8K 6 16K 16 3N 7 11S 4 5S 6 14E 5 3Q 9 14N 11 6N 16 11E 7 15K 13 1A 11 2R 6 5A 7 5N 8 14B 11 1Q 12 11N 8 4
27E 11 12N 4 2K 2 9N 6 13K 10 6R 2 5E 12 16S 12 3K 12 6K 6 6Q 14 12N 4 9A 11 16A 15 13K 12 14R 6 7Q 1 7S 15 5S 11 11K 16 9K 10 4A 16 6E 1 2K 13 11E 6 10Q 3 12A 5 15
54R 2 12K 9 14K 13 2S 3 5B 13 14R 14 16N 1 5A 2 10Q 2 11R 7 1E 7 15A 7 6N 7 11E 1 10K 2 8E 8 9Q 3 7S 14 9B 6 1S 8 6Q 14 3N 3 10E 7 16S 8 10K 6 7A 5 2N 13 4E 16 7R 10 7B 11 1B 13 11S 5 14B 6 11S 12 1B 8 11B 3 6Q 11 15N 2 16N 10 4Q 2 6A 11 10N 3 12N 1 16Q 11 7Q 6 9K 12 9B 3 1B 4 13A 9 16K 12 8K 10 2B 3 9S 9 10R 8 4
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101After decades of shadowy demonstrations and delays from the game’s maker,Chess 2 has finally been released. You waited in line all night to be one ofthe first to purchase an example of the hot sequel to the classic original,and now you are finally getting a chance to open up your new investment andtake a look inside. What you find is slightly puzzling; in addition to thetraditional pieces, the game has been expanded to contain a number of piecesthat are not actually original. The best-known piece that has been added to the game is the nightrider. Thenightrider can make any number of knight moves in a single direction, i.e.,its offset from its initial position will be 2***m** in one dimension and**m** in the other for some nonzero integer **m**. Like other "sliding"pieces, if one of the knight moves would cause it to take another piece it isnot able to traverse beyond that point The archbishop is also part of Chess 2. The archbishop can simply make anymove that a knight or bishop could legally make. The strangest new piece is the kraken. The kraken can move to any square onthe board, regardless of the position of any other pieces, including its owncurrent position. You don't feel like reading the manual to learn about how the new pieces fitinto the standard chess opening positions, so instead you place some of thepieces randomly on the board. The game you’ve decided to play is simply tocount how many pieces on the board are currently being threatened. A piece isthreatened if another piece is able to move into its cell and take it (notethat if the kraken moves into its own cell it does not take itself).
## Input
Your input file will consist of a single integer **N** followed by **N** testcases. Each case will consist of, all separated by whitespace, an integer**P** followed by the identities and positions of **P** Chess 2 pieces. Piecesare described by a single character **C** to denote their type (seespecification below) followed by two integers **R** and **F**, the 1-basedrank and file, respectively, of the piece. You've decided to ignore the colors of the pieces in this game. The color ofthe pieces will not be reflected in the input and so cannot affect youroutput. To make room for the new pieces, the Chess 2 board is a 16 by 16 grid. Nospecified pieces will fall outside the board, and no two pieces will occupythe same position. The types of pieces will be specified as follows, and no entries not presentin this table will appear on the board:
Piece
Abbreviation
King
K
Queen
Q
Rook
R
Bishop
B
Knight
N
Nightrider
S
Archbishop
A
Kraken
E
## Output
Output a single integer, the number of threatened pieces on the board, foreach test case separated by whitespace.
## Constraints
**N** = 20 3 ≤ **P** ≤ 64 1 ≤ **R, F** ≤ 16 **C** will be one of {K, Q, R, B, N, S, A, E}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950Case #1: 2Case #2: 1Case #3: 3Case #4: 4Case #5: 6Case #6: 16Case #7: 12Case #8: 13Case #9: 41Case #10: 7Case #11: 23Case #12: 44Case #13: 42Case #14: 60Case #15: 24Case #16: 12Case #17: 34Case #18: 14Case #19: 33Case #20: 39Case #21: 22Case #22: 25Case #23: 38Case #24: 6Case #25: 30Case #26: 64Case #27: 14Case #28: 25Case #29: 7Case #30: 10Case #31: 47Case #32: 16Case #33: 1Case #34: 43Case #35: 44Case #36: 3Case #37: 27Case #38: 38Case #39: 51Case #40: 12Case #41: 34Case #42: 27Case #43: 62Case #44: 56Case #45: 19Case #46: 42Case #47: 41Case #48: 25Case #49: 27Case #50: 5412
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061609 34 13 25 46 914 29 158 1415 318 911 315 2220 2615 2417 3315569 554111583 980116692 259229 622822236 50285788 5470157298 7500185465 3340712096 1618116111 85311004844898 599870982398 51912844176 4274280090413 13271524325969 45432684539840 1071730523654378 2562369544242544 20823836837752 5257470121962 2371508310088 2081155104102185 4617840455709600 3010516253853029 2524999018856195 4502890630293137 9910966621871186 497326279643 11800194613241 4986424051667526 9993312576262614 8689208459759810 6745799896021803 9345752744976641 12319948975564 15999999999994 6774999999999954 1073999999999929 9869999999999997 2287999999999902 1385999999999976 1657999999999995 29611000000000000 7885999999999965 470999999999979 926612
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960Case #1: 1Case #2: 1Case #3: 2Case #4: 2Case #5: 2Case #6: 2Case #7: 1Case #8: 4Case #9: 13Case #10: 3Case #11: 9Case #12: 10Case #13: 5Case #14: 1Case #15: 7Case #16: 2120Case #17: 9307Case #18: 13767Case #19: 8380Case #20: 12870Case #21: 108319Case #22: 73245Case #23: 141748Case #24: 662176Case #25: 88331Case #26: 85722025Case #27: 39037023Case #28: 515376569Case #29: 35505654Case #30: 296987310Case #31: 275734586354Case #32: 378886990758Case #33: 250719764684Case #34: 718335168421Case #35: 92977784171Case #36: 127438603762Case #37: 13032499082Case #38: 344868691150Case #39: 347331336612Case #40: 184304921625Case #41: 614107045428Case #42: 468287005627Case #43: 58859175635Case #44: 598309863104Case #45: 270992714172Case #46: 138523456879Case #47: 146266615756Case #48: 318728205092Case #49: 558519823146Case #50: 255077042619Case #51: 605474245496Case #52: 806603136066Case #53: 379199925050Case #54: 520133628360Case #55: 635459719362Case #56: 33420462051Case #57: 621390814757Case #58: 138243410238Case #59: 748830943000Case #60: 51714854203412345678910111213141516171819202122232425262728293031323334<p>You recently befriended a guy who writes software for slot machines. After hanging out with him a bit, you notice that he has a penchant for showing off his knowledge of how the slot machines work. Eventually you get him to describe for you in precise detail the algorithm used on a particular brand of machine. The algorithm is as follows:</p>
<pre>int getRandomNumber() { secret = (secret * 5402147 + 54321) % 10000001; return secret % 1000;}</pre>
<p>This function returns an integer number in [0, 999]; each digit represents one of ten symbols that appear on a wheel during a particular machine state. <strong>secret</strong> is initially set to some nonnegative value unknown to you.</p>
<p>By observing the operation of a machine long enough, you can determine value of <b>secret</b> and thus predict future outcomes. Knowing future outcomes you would be able to bet in a smart way and win lots of money.</p>
<h2>Input</h2>
<p>The first line of the input contains positive number <strong>T</strong>, the number of test cases. This is followed by <strong>T</strong> test cases. Each test case consists of a positive integer <strong>N</strong>, the number of observations you make. Next <strong>N</strong> tokens are integers from 0 to 999 describing your observations.</p>
<h2>Output</h2><p>For each test case, output the next 10 values that would be displayed by the machine separated by whitespace.<br/>If the sequence you observed cannot be produced by the machine your friend described to you, print "Wrong machine" instead.<br/>If you cannot uniquely determine the next 10 values, print "Not enough observations" instead.</p>
<h2>Constraints</h2><strong>T</strong> = 20<br/>1 ≤ <strong>N</strong> ≤ 100<br/>Tokens in the input are no more than 3 characters long and contain only digits 0-9.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556551 968 3 767 308 284 5 78 880 53 698 235 7 23 786 292 615 259 635 540 9 862 452 303 558 767 105 911 846 462 11 255 353 267 500 766 937 792 682 28 339 575 13 611 876 666 178 641 403 377 804 590 641 708 268 512 15 511 831 275 539 597 170 42 467 286 37 560 817 474 917 250 17 945 782 497 380 959 578 65 837 870 618 444 12 656 345 168 43 484 19 743 398 250 424 103 472 294 112 512 942 604 955 793 162 243 182 873 587 787 21 201 260 506 418 790 810 314 622 128 316 429 966 217 930 503 128 316 696 81 862 930 23 999 876 259 462 934 705 543 897 770 641 589 909 354 747 579 267 705 83 572 270 807 791 41 25 433 827 480 303 296 112 567 266 353 221 473 105 536 176 497 873 819 208 726 156 71 134 672 663 617 27 378 733 719 221 320 986 89 206 453 199 328 208 839 774 86 650 597 325 450 512 575 14 695 426 230 63 103 29 689 305 489 341 127 345 816 52 612 920 459 58 96 761 832 958 651 704 511 391 691 902 868 131 133 92 617 457 664 31 241 172 738 267 885 360 159 170 984 680 77 77 865 506 228 726 27 292 149 934 57 886 879 917 244 891 3 35 132 846 92 33 870 223 112 965 54 390 762 594 509 344 574 298 213 582 681 426 84 424 484 502 119 362 172 227 99 381 160 192 300 976 429 539 30 35 668 839 865 10 199 285 991 869 152 668 734 241 350 399 756 564 473 811 975 910 996 714 954 995 970 564 971 566 671 189 580 421 990 923 161 37 100 4 238 270 27 492 928 28 578 480 340 61 415 72 48 640 582 291 197 569 248 20 959 616 202 792 35 365 90 290 888 275 780 657 56 22 970 39 924 316 873 48 30 517 241 654 410 366 719 195 910 984 92 649 306 307 760 145 615 482 150 463 486 487 823 708 235 798 9 217 469 143 9 978 232 626 775 41 853 436 501 761 405 895 233 155 193 488 586 482 885 370 848 276 984 368 977 486 645 93 30 825 686 281 857 753 506 817 291 931 415 666 571 635 355 833 105 943 908 43 156 884 848 933 536 819 493 299 636 272 763 334 229 229 85 394 808 819 405 439 757 178 562 57 938 718 268 282 543 969 722 829 32 483 464 683 598 312 574 229 72 85 17 45 614 745 103 927 223 158 513 809 251 646 588 344 653 997 345 341 252 928 699 266 499 594 976 758 583 458 308 50 736 366 0 743 551 451 889 853 683 272 121 24 290 491 521 705 550 47 227 148 683 247 18 43 290 310 581 595 94 687 689 370 381 886 124 630 622 617 412 297 244 25 664 934 711 130 113 739 832 322 300 47 809 542 791 666 319 744 453 716 158 861 80 677 231 49 846 312 78 812 729 460 766 453 477 551 632 483 972 243 339 85 754 439 344 560 641 289 389 352 35 689 754 624 44 536 714 355 114 791 344 558 49 957 921 754 52 870 526 224 298 235 879 258 494 51 791 219 317 730 753 333 288 393 577 528 487 586 275 841 928 862 533 556 68 917 144 168 412 116 648 583 91 109 110 714 134 677 675 320 72 864 711 708 334 368 779 195 366 557 437 810 139 685 10 818 427 53 104 364 139 493 532 597 767 197 713 274 217 73 924 19 781 704 1 845 688 576 463 334 603 129 729 679 798 0 645 326 858 150 293 903 743 173 483 519 28 991 466 573 276 826 215 381 317 924 582 643 461 671 825 55 47 696 325 768 584 566 537 178 835 226 472 540 835 426 263 947 365 53 853 152 764 936 608 585 164 506 943 251 674 324 563 473 154 540 920 296 922 812 401 458 525 736 697 717 521 437 530 626 663 47 688 810 320 409 902 57 334 357 62 736 67 995 267 883 961 154 662 575 852 73 668 915 89 447 774 90 401 753 997 415 3 843 51 340 916 316 856 762 156 351 647 694 626 748 787 573 560 789 862 903 130 980 97 375 188 320 259 512 719 90 32 345 477 59 279 264 300 653 91 868 789 823 60 132 516 678 155 671 257 692 868 564 498 446 905 632 20 179 616 737 388 825 982 494 276 84 716 880 375 0 288 498 200 188 287 114 702 237 268 555 357 802 704 362 906 763 321 956 57 822 898 243 642 61 590 835 70 774 898 227 516 668 219 853 647 529 412 658 3 0 922 943 559 325 21 521 193 884 519 766 903 482 480 926 285 559 635 571 495 126 837 853 854 663 306 329 194 64 214 608 488 316 841 548 519 194 386 907 980 569 198 788 142 19 263 63 535 741 309 691 922 100 38 608 318 830 502 632 715 256 592 777 700 60 283 682 524 400 216 647 132 660 240 967 546 104 705 881 195 100 223 432 499 603 267 278 33 655 34 397 353 182 748 743 357 590 167 445 987 774 6 46 619 177 780 375 61 399 22 65 377 331 985 41 239 122 200 791 256 734 937 80 806 346 676 748 406 92 611 644 3 790 155 352 760 752 207 70 618 367 327 100 443 724 701 114 827 683 296 967 353 54 585 454 56 126 635 28 829 262 808 57 356 355 886 89 513 52 744 182 324 994 321 460 719 67 3 619 803 907 978 973 143 636 516 627 428 524 2 994 142 786 915 830 966 513 236 586 942 504 134 450 1 693 363 797 786 709 558 343 463 207 391 202 81 166 808 988 507 109 984 27 429 229 217 557 588 161 615 765 215 467 263 895 457 319 537 357 350 533 556 346 515 69 126 403 347 309 113 772 666 749 385 947 305 489 767 697 743 320 38 615 900 554 185 550 230 400 716 706 266 823 479 858 760 881 565 486 530 576 699 997 373 919 795 483 741 792 848 675 343 275 52 967 895 145 837 241 578 630 663 716 22 556 251 268 910 962 692 207 146 1 418 71 752 43 166 175 852 271 257 594 996 840 797 285 963 345 209 358 546 354 256 423 770 994 17 200 738 405 412 447 224 288 868 490 680 105 291 21 263 164 511 767 898 768 663 799 776 225 489 476 440 614 28 601 97 298 556 359 412 560 383 693 112 631 291 35 530 37 602 796 926 928 132 73 508 387 866 718 201 300 870 509 714 496 344 819 980 939 983 491 218 983 538 281 263 443 563 36 168 803 75 723 27 48 818 720 777 505 288 147 469 863 236 410 39 362 253 352 170 989 97 138 495 379 158 232 130 837 63 225 188 606 85 970 734 985 567 461 126 358 686 766 700 982 105 643 226 75 453 293 104 635 225 173 391 449 813 473 198 922 283 538 572 268 997 100 262 637 767 323 586 799 781 697 412 207 93 225 238 42 338 34 16 453 131 613 650 25 766 688 93 685 309 564 356 565 10 421 805 483 732 703 88 701 609 995 723 326 532 200 928 0 431 799 465 833 1 223 375 974 842 877 699 77 764 864 874 756 32 532 119 294 972 194 329 772 540 524 319 576 50 480 323 516 883 211 759 504 684 727 926 865 591 658 247 516 256 725 136 578 680 967 303 500 785 903 584 512 254 616 488 79 148 608 419 914 797 655 11 449 909 539 223 627 614 304 490 240 404 320 49 655 720 835 676 347 696 14 661 897 669 79 709 770 113 673 56 406 641 234 71 171 184 876 843 122 908 353 829 597 47 872 386 91 782 268 297 620 263 349 657 835 667 838 817 254 864 885 342 718 717 115 512 228 424 845 393 191 747 507 664 650 66 165 398 521 37 925 330 928 860 983 412 519 851 779 710 761 828 722 21 76 946 678 313 796 838 149 143 603 805 81 142 722 335 514 418 814 664 604 654 752 67 71 25 551 826 959 943 721 201 758 651 434 413 94 878 668 897 550 594 793 230 568 419 342 895 328 582 258 996 549 746 473 601 858 364 511 225 51 873 235 192 51 667 752 165 954 309 450 223 26 450 96 365 761 458 279 882 10 282 611 74 600 988 740 737 31 437 655 381 507 296 83 941 338 88 559 562 708 893 879 297 77 227 14 162 368 901 98 331 108 692 166 528 786 195 862 749 851 709 923 965 5 381 450 380 594 319 589 708 403 516 844 274 607 429 364 141 309 574 682 704 965 284 118 399 68 192 254 167 127 449 13 772 562 82 443 875 876 739 55 961 517 234 565 901 40 422 595 372 754 634 465 830 279 118 85 252 909 857 679 369 67 620 724 456 797 358 865 420 354 648 406 385 487 753 45 644 675 368 567 652 880 223 581 463 438 389 924 298 286 439 715 257 758 169 320 293 822 921 192 86 362 706 197 842 151 897 550 464 19 115 1 467 672 948 314 854 666 644 682 848 396 323 878 680 129 534 938 755 177 384 528 488 752 667 460 160 401 772 223 754 87 197 815 96 597 393 940 142 664 555 775 213 968 722 953 237 183 164 604 477 402 147 554 390 331 265 774 560 65 529 615 809 246 859 814 167 21 920 508 583 934 20 147 761 525 225 936 965 624 357 193 545 800 66 886 140 478 888 61 586 670 652 881 5 221 153 837 102 944 981 370 804 269 372 959 560 780 962 704 24 484 228 38 413 546 694 289 970 89 884 843 512 375 348 280 458 45 782 100 428 923 394 238 276 668 506 599 875 126 149 585 297 474 726 730 853 847 803 773 133 413 65 93 84 341 245 151 129 10 406 427 60 667 246 590 331 193 134 624 579 824 113 805 434 83 265 713 777 176 470 997 784 741 821 73 537 494 117 309 174 957 164 416 998 364 352 580 418 497 666 684 94 23 637 802 299 461 245 91 429 383 71 482 900 242 395 308 781 680 257 106 42 198 230 928 666 115 121 696 289 250 803 925 717 5 6 640 837 785 523 857 421 154 622 726 285 194 382 664 782 526 766 44 973 55 792 800 398 508 763 753 66 433 295 806 726 260 174 700 12 924 236 885 318 952 13 278 921 811 92 156 960 203 144 226 191 855 853 428 33 760 528 283 37 144 223 469 750 269 263 93 886 244 326 476 586 581 415 819 396 54 82 117 465 966 490 874 110 225 416 523 31 666 217 626 362 745 46 408 30 183 801 772 940 122 47 896 370 153 930 459 0 932 269 698 280 884 834 110 220 7 932 369 1 934 217 731 589 516 86 369 570 778 442 982 180 317 519 121 262 758 504 896 518 822 599 847 846 706 991 489 897 915 758 114 748 134 156 841 407 35 188 935 259 95 258 555 693 861 961 429 868 200 522 207 288 128 551 589 809 278 998 861 520 258 916 140 511 322 704 383 706 575 410 342 674 804 950 826 322 896 33 984 344 810 303 141 138 12 966 689 185 992 746 976 447 368 854 395 105 354 516 222 416 687 257 634 402 317 984 242 80 698 961 899 52 665 654 909 202 209 458 158 903 273 246 894 970 984 57 533 61 8 388 328 367 779 455 882 90 97 921 872 464 227 634 647 68 696 837 825 503 197 416 6 826 703 154 215 156 685 832 598 280 726 585 323 63 32 972 182 837 241 966 428 467 420 47 305 11 992 300 576 558 128 650 485 97 756 341 350 208 872 925 463 548 285 833 230 45 166 59 425 153 393 21 131 394 633 279 176 702 321 227 800 418 871 444 343 859 598 9 722 443 121 729 427 491 870 880 163 203 824 349 78 968 37 782 99 866 778 702 144 658 520 590 636 937 802 357 300 719 604 414 480 932 332 880 42 336 477 303 489 198 217 400 516 37 360 257 563 527 957 195 727 709 55 425 606 26 901 398 461 789 59 356 184 857 392 856 123 526 330 573 762 254 619 683 522 856 640 513 933 326 572 173 699 580 417 972 652 843 582 594 123 918 295 216 621 77 359 84 443 669 653 259 188 736 119 632 531 70 142 749 35 114 733 304 2 511 831 2 945 782 2 743 398 2 201 260 2 999 876 123456789101112131415161718192021222324252627282930313233343536373839404142You recently befriended a guy who writes software for slot machines. Afterhanging out with him a bit, you notice that he has a penchant for showing offhis knowledge of how the slot machines work. Eventually you get him todescribe for you in precise detail the algorithm used on a particular brand ofmachine. The algorithm is as follows:
int getRandomNumber() { secret = (secret * 5402147 + 54321) % 10000001; return secret % 1000; }
This function returns an integer number in [0, 999]; each digit represents oneof ten symbols that appear on a wheel during a particular machine state.**secret** is initially set to some nonnegative value unknown to you.
By observing the operation of a machine long enough, you can determine valueof **secret** and thus predict future outcomes. Knowing future outcomes youwould be able to bet in a smart way and win lots of money.
## Input
The first line of the input contains positive number **T**, the number of testcases. This is followed by **T** test cases. Each test case consists of apositive integer **N**, the number of observations you make. Next **N** tokensare integers from 0 to 999 describing your observations.
## Output
For each test case, output the next 10 values that would be displayed by themachine separated by whitespace. If the sequence you observed cannot be produced by the machine your frienddescribed to you, print "Wrong machine" instead. If you cannot uniquely determine the next 10 values, print "Not enoughobservations" instead.
## Constraints
**T** = 20 1 ≤ **N** ≤ 100 Tokens in the input are no more than 3 characters long and contain only digits0-9.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455Case #1: Not enough observationsCase #2: 577 428 402 291 252 544 735 545 771 34Case #3: 762 18 98 703 456 676 621 291 488 332Case #4: 38 802 434 531 725 594 86 921 607 35Case #5: Wrong machineCase #6: 863 914 332 914 352 538 579 357 505 427Case #7: Wrong machineCase #8: 437 370 75 142 741 46 328 433 773 68Case #9: 200 296 626 311 671 64 600 649 15 469Case #10: 35 188 23 845 368 520 198 280 973 598Case #11: 439 260 68 165 938 320 741 792 232 981Case #12: 836 36 121 132 115 162 444 132 104 321Case #13: 169 766 316 100 402 695 833 924 868 164Case #14: 800 165 579 115 155 485 397 892 591 132Case #15: 12 123 630 403 88 13 716 682 620 212Case #16: Wrong machineCase #17: 671 737 285 894 377 188 114 36 31 852Case #18: 547 21 522 708 409 563 166 681 372 411Case #19: Wrong machineCase #20: 499 309 706 12 532 496 169 184 596 591Case #21: Wrong machineCase #22: 51 243 287 11 772 631 963 393 308 117Case #23: 117 52 82 453 461 561 924 51 178 774Case #24: Wrong machineCase #25: 776 780 877 52 725 929 793 919 721 279Case #26: 127 654 591 954 270 340 110 917 31 941Case #27: Wrong machineCase #28: 493 61 44 54 688 821 37 868 201 56Case #29: 854 5 362 383 865 738 326 916 904 102Case #30: 719 181 80 99 865 221 345 881 565 158Case #31: 184 661 105 194 865 465 388 877 222 869Case #32: 644 499 307 244 454 178 463 139 35 315Case #33: Wrong machineCase #34: Wrong machineCase #35: Wrong machineCase #36: Wrong machineCase #37: 96 522 713 79 701 58 479 559 161 68Case #38: 964 553 653 415 502 627 798 708 300 579Case #39: 651 449 497 957 920 363 732 525 826 367Case #40: 521 25 557 3 54 464 52 135 605 250Case #41: 675 54 868 633 515 738 869 307 940 437Case #42: 792 808 907 388 524 550 79 759 228 538Case #43: 63 202 233 593 27 579 587 451 423 344Case #44: 551 450 984 8 293 172 487 124 517 833Case #45: Wrong machineCase #46: 98 270 352 869 563 250 36 505 232 178Case #47: 172 486 864 971 603 697 927 850 774 910Case #48: Wrong machineCase #49: 29 663 215 269 304 846 114 206 387 418Case #50: 271 614 979 74 762 740 272 167 572 45Case #51: Not enough observationsCase #52: Not enough observationsCase #53: Not enough observationsCase #54: Not enough observationsCase #55: Not enough observations123456789101112A number is called <strong>n</strong>-factorful if it has exactly <strong>n</strong> distinct prime factors. Given positive integers <strong>a</strong>, <strong>b</strong>, and <strong>n</strong>, your task is to find the number of integers between <strong>a</strong> and <strong>b</strong>, inclusive, that are <strong>n</strong>-factorful. We consider 1 to be 0-factorful.<br/><br/>
<h2>Input</h2>Your input will consist of a single integer <strong>T</strong> followed by a newline and <strong>T</strong> test cases. Each test cases consists of a single line containing integers <strong>a</strong>, <strong>b</strong>, and <strong>n</strong> as described above.<br/><br/>
<h2>Output</h2>Output for each test case one line containing the number of <strong>n</strong>-factorful integers in [<strong>a</strong>, <strong>b</strong>].<br/><br/>
<h2>Constraints</h2><strong>T</strong> = 20<br/>1 ≤ <strong>a</strong> ≤ <strong>b</strong> ≤ 10<sup>7</sup><br/>0 ≤ <strong>n</strong> ≤ 10123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051501 3 11 10 21 10 31 100 31 1000 02836886 9741361 105686897 9548986 8106918 126109 15781726 9933735 12097182 8971863 41732109 8779488 57551469 9356612 75777852 9164237 64469152 8202365 16066267 8009990 93822727 8587114 46892171 8394739 22120074 7432867 73893280 7240493 62558797 7817616 85416449 7625242 91003781 2819352 61771171 2626977 52448143 3204101 92675787 3011726 71591563 2049854 2452893 1857479 1792490 2434603 32036417 2242228 4209457 1280356 7662907 1087982 81255 1665105 1099515 1472731 846295 510858 347709 318484 2820229 895607 6680385 703233 52951918 3585378 6189824 3393004 4483428 3970127 81722003 3777753 72750996 2815880 2219766 2623506 11778284 3200629 52196668 3008255 327114 2046383 8319644 1854008 7698476 2431131 91120382 2238757 81144104 1276885 32011/finals/alien_game.htmlAdded+19
2011/finals/alien_game.inAdded
2011/finals/alien_game.mdAdded+54
2011/finals/alien_game.outAdded+50
2011/finals/party_time.htmlAdded+84
2011/finals/party_time.inAdded
2011/finals/party_time.mdAdded+60
2011/finals/party_time.outAdded+50
2011/finals/safest_place.htmlAdded+16
2011/finals/safest_place.inAdded
2011/finals/safest_place.mdAdded+31
2011/finals/safest_place.outAdded+50
2011/quals/double_squares.htmlAdded+18
2011/quals/double_squares.inAdded+64
2011/quals/double_squares.mdAdded+23
2011/quals/double_squares.outAdded+63
2011/quals/peg_game.htmlAdded+63
2011/quals/peg_game.inAdded
2011/quals/peg_game.mdAdded+60
2011/quals/peg_game.outAdded+60
2011/quals/studious_student.htmlAdded+15
2011/quals/studious_student.inAdded+40
2011/quals/studious_student.mdAdded+29
2011/quals/studious_student.outAdded+39
2011/round1a/diversity_number.htmlAdded+17
2011/round1a/diversity_number.inAdded+121
2011/round1a/diversity_number.mdAdded+32
2011/round1a/diversity_number.outAdded+60
2011/round1a/turn_on_the_lights.htmlAdded+25
2011/round1a/turn_on_the_lights.inAdded+1051
2011/round1a/turn_on_the_lights.mdAdded+30
2011/round1a/turn_on_the_lights.outAdded+60
2011/round1a/wine_tasting.htmlAdded+29
2011/round1a/wine_tasting.inAdded+51
2011/round1a/wine_tasting.mdAdded+34
2011/round1a/wine_tasting.outAdded+50
2011/round1b/chess_2.htmlAdded+66
2011/round1b/chess_2.inAdded+1462
2011/round1b/chess_2.mdAdded+101
2011/round1b/chess_2.outAdded+50
2011/round1b/diminishing_circle.htmlAdded+2
2011/round1b/diminishing_circle.inAdded+61
2011/round1b/diminishing_circle.mdAdded+2
2011/round1b/diminishing_circle.outAdded+60
2011/round1b/slot_machine_hacker.htmlAdded+34
2011/round1b/slot_machine_hacker.inAdded+56
2011/round1b/slot_machine_hacker.mdAdded+42
2011/round1b/slot_machine_hacker.outAdded+55
2011/round1c/n_factorful.htmlAdded+12
2011/round1c/n_factorful.inAdded+51