|
<p> |
|
As the Jeremy Lin sensation goes on, Roger, who is a geek and a super fan of Jeremy Lin, decides his new cell phone number must be |
|
"Linsane". More specifically, he wants his new phone number to satisfy: </p> |
|
|
|
<p> |
|
1) Adjacent sum: <br/> |
|
There is at least one occurrence in the phone number of three adjacent digits summing to <b>x</b>, where <b>x</b> is Lin's |
|
jersey number at New York Knicks. </p> |
|
|
|
<p> |
|
2) Diversity: <br/> |
|
There are at least <b>y</b> different values of the digits used in the phone number, where <b>y</b> is Lin's jersey number at Golden |
|
State Warriors. </p> |
|
|
|
<p> |
|
3) Neighboring difference: <br/> |
|
There is at least one pair of neighboring digits whose difference is equal to <b>z</b>, where <b>z</b> is Lin's jersey number at Harvard. </p> |
|
|
|
<p> |
|
A phone number with length <b>n</b> contains <b>n</b> digits. Each digit is in the range from 0 to 9, except that the first |
|
digit must be non-zero.<br/> |
|
|
|
A phone number is called "linsane" if it satisfies the three constraints listed above.<br/><br/> |
|
For phone numbers with a given length <b>n</b>, Roger wonders how many "linsane" phone |
|
numbers exist.<br/> |
|
He also wants to find out the "most linsane" phone number among them.<br/> |
|
For a given length, the "most linsane" phone number is a "linsane" phone number that has the biggest "linsanity measurement" among them.<br/> |
|
"Linsanity measurement" is defined as |
|
<img src="http://rogeryu.com/Facebook_Hacker_Cup_2012_Final_Round_Problem_Linsanity.gif"></img>, where <b>n</b> is the number of digits and <b>d<sub>i</sub></b> is the <b>i</b>-th digit in the phone number.<br/> |
|
If there is a tie on such measurement, choose the one whose median of the digits is largest; and if there is still a tie, choose the largest phone number.<br/> |
|
Median is the <b>(n+1)/2</b>-th smallest digit if <b>n</b> is odd, or the average of the <b>(n/2)</b>-th and <b>(n/2+1)</b>-th digit if <b>n</b> is even. |
|
For example, the linsanity measurement of number 78969251 is equal to (15*9)%8 + (17*6)%8 + (15*9)%8 + (15*2)%8 +(11*5)%8 + (7*1)%8 = 40 with its median equal to 6.5.<br/> |
|
</p> |
|
|
|
<h3>Input</h3> |
|
<p>The first line contains a positive integer <b>T</b>, the number of test cases. <b>T</b> test cases follow.</p> |
|
<p>Each test case is a single line and contains exactly four integers separated by single white space: <b>n x y z</b>, where <b>n</b> is the length of the phone number, <b>x</b> is Lin's jersey number at New York Knicks, <b>y</b> is Lin's jersey number at Golden State Warriors and <b>z</b> is Lin's jersey number at Harvard.<br/> |
|
(<b>x</b>,<b>y</b> and <b>z</b> are not necessarily 17, 7 and 4 in another parallel universe.) |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
|
|
3 ≤ <b>n</b> ≤ 20<br/> |
|
0 ≤ <b>x</b> ≤ 27<br/> |
|
0 ≤ <b>y</b> ≤ 10<br/> |
|
0 ≤ <b>z</b> ≤ 9<br/> |
|
1 ≤ <b>T</b> ≤ 15<br/> |
|
Among the <b>T</b> test cases, there will be no more than 5 test cases with <b>n</b> >12. |
|
|
|
|
|
</p> |
|
|
|
<h3>Output</h3> |
|
<p> |
|
For each of the test cases numbered in order from <b>1</b> to <b>T</b>, output "Case #", followed by the case number, |
|
followed by ": ", followed by the number of possible "linsane" phone numbers <i>mod</i> 10<sup>18</sup> for the given length for that case, |
|
and then a single space " " followed by the "most linsane" phone number for the given length or -1 if no "linsane" phone number exists |
|
for the given length. |
|
</p> |
|
|
|
|
|
|