Create a class CraneWork that contains a method moves that is given int[]s stack1, stack2, and warehouse containing the initial three stacks, and returns the minimum number of moves required to move all the crates into the warehouse stack. The elements of stack1, stack2, and warehouse represent the weights of the crates and are given from top to bottom (and thus in nondecreasing order of weight).
Class:  CraneWork 
Method:  moves 
Parameters:  int[], int[], int[] 
Returns:  int 
Method signature:  int moves(int[] stack1, int[] stack2, int[] warehouse) 
(be sure your method is public) 


Returns: 12 




Returns: 17 




Returns: 0 




Returns: 7 


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
A palindrome is a string that reads the same forward and backward. A palindrome substring is a contiguous sequence of characters taken from a string that form a palindrome. A palindrome substring of a string is maximal if we can't extend it to get a bigger palindrome substring. For example, string "acdadc" has 2 maximal palindrome substrings  "a" (the first one) and "cdadc". All other palindrome substrings (like "dad" or "c") can be extended to "cdadc", so they are not maximal.
You will be given a String[] str. Concatenate the elements of str to form one long string, and return the number of maximal palindrome substrings contained in that string.
Class:  MaximalPalindromeSubstrings 
Method:  countMaximalPalindromeSubstrings 
Parameters:  String[] 
Returns:  int 
Method signature:  int countMaximalPalindromeSubstrings(String[] str) 
(be sure your method is public) 


Returns: 2 




Returns: 2 




Returns: 3 




Returns: 14 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Class:  SalesRouting 
Method:  howMany 
Parameters:  String[] 
Returns:  int 
Method signature:  int howMany(String[] adj) 
(be sure your method is public) 


Returns: 1 




Returns: 1 




Returns: 1 




Returns: 4 



Returns: 0 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
We can substitute each digit of a number with a unique letter from 'A' to 'Z'. This way we can write groups of numbers in a single representation. For example "ABA" can represent any of the following: 101, 151, 343, 767, 929. However, "ABA" cannot mean 555 because each letter must stand for a distinct digit. Furthermore, numbers cannot begin with 0 and thus 'A' cannot be replaced by 0.
Given two such representations num1 and num2 and the result of their summation return the total number of possible combinations of numbers for which the equation holds. If no combinations are possible then return 0.
Class:  SecretSum 
Method:  countPossible 
Parameters:  String, String, String 
Returns:  int 
Method signature:  int countPossible(String num1, String num2, String result) 
(be sure your method is public) 
 
Returns: 32  
 
Returns: 112  
 
Returns: 0  

 
Returns: 32  
 
Returns: 12  
 
Returns: 5  

 
Returns: 4  

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
In the factorial number system the value of the first digit (from the right) is 1!, the value of the second digit is 2!, ..., and the value of the nth digit is n!. This means that any decimal number d can be written in this system as: a_{n}a_{n1}...a_{2}a_{1}, where
d = a_{n} * n! + a_{n1} * (n1)! + ... + a_{2} * 2! + a_{1} * 1! and 0 <= a_{i} <= i for all i.
Given an int num in decimal, return its representation in the factorial number system.
Class:  FactorialSystem 
Method:  convert 
Parameters:  int 
Returns:  int 
Method signature:  int convert(int num) 
(be sure your method is public) 
 
Returns: 1  
 
Returns: 1000  

 
Returns: 11111  

 
Returns: 10201  
 
Returns: 987654321  

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
A rational number is defined as a/b, where a and b are integers, and b is greater than 0. Furthermore, a rational number can be written as a decimal that has a group of digits that repeat indefinitely. A common method of writing groups of repeating digits is to place them inside parentheses like 2.85(23) = 2.852323 ... 23...
Given a decimal representation of a rational number in decimalNumber, convert it to a fraction formatted as "numerator/denominator", where both numerator and denominator are integers. The fraction must be reduced. In other words, the denominator must be as small as possible, but greater than zero.
Class:  RecurringNumbers 
Method:  convertToFraction 
Parameters:  String 
Returns:  String 
Method signature:  String convertToFraction(String decimalNumber) 
(be sure your method is public) 
 
Returns: "1/3"  

 
Returns: "21/16"  

 
Returns: "14119/4950"  

 
Returns: "3038111/333000"  
 
Returns: "1/9"  
 
Returns: "3/1"  
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

sequence will have between 1 and 50 elements, inclusive.

Each element of sequence will be between 1 and 1000, inclusive.
Examples
0)
????
{5, 6, 5, 1, 6, 5}
Returns: {1, 6, 5 }
There are six different ways to remove duplicates (remaining numbers are marked by '*'):
{ *5, *6, 5, *1, 6, 5},
{ *5, 6, 5, *1, *6, 5},
{ 5, *6, *5, *1, 6, 5},
{ 5, 6, *5, *1, *6, 5},
{ 5, *6, 5, *1, 6, *5},
{ 5, 6, 5, *1, *6, *5}.
The last variant is the lexicographically first.
1)
????
{3, 2, 4, 2, 4, 4}
Returns: {3, 2, 4 }
2)
????
{6, 6, 6, 6, 6, 6}
Returns: {6 }
3)
????
{1, 3, 2, 4, 2, 3}
Returns: {1, 2, 4, 3 }
4)
????
{5, 4, 1, 5}
Returns: {4, 1, 5 }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

heights will have between 1 and 50 elements, inclusive.

Each element of heights will be between 1 and 1000, inclusive.
Examples
0)
????
{1,5,5,1,6,1}
Returns: 3
We can use rectangles with sizes 6x1, 2x4 and 1x5.
×
×× ×
×× ×
×× ×
×× ×
××××××
1)
????
{2,2,2,4,4}
Returns: 2
We can use a 3x2 rectangle and a 2x4 rectangle.
××
××
×××××
×××××
2)
????
{6,6,6,6,6,6}
Returns: 1
The structure is a rectangle.
3)
××××××
××××××
××××××
××××××
××××××
××××××
????
{71,44,95,16,10,80,12,17,98,61}
Returns: 10
It's impossible to use less than 10 rectangles.
4)
????
{100,100,97,100,100,100,97,98,99,99}
Returns: 5
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

row will contain between 1 and 50 characters, inclusive.

Each character in row will be either '.' or 'X'.
Examples
0)
????
"....."
Returns: 2
You can buy either tickets with indexes 1 and 2 or tickets with indexes 2 and 3.
1)
????
"......"
Returns: 2
2)
????
"..X..."
Returns: 3
You should buy tickets with indexes 3 and 4.
3)
????
".X.X..."
Returns: 4
4)
????
"X.XX.X"
Returns: 1
5)
????
".."
Returns: 0
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
When a stone is thrown across water, sometimes it will land on the water and bounce rather than falling in right away. Suppose that a stone is thrown a distance of n. On each successive bounce it will travel half the distance as the previous bounce (rounded down to the nearest integer). When it can not travel any further, it falls into the water. If, at any point, the stone lands on an obstruction rather than water, it will not bounce, but will simply deflect and fall into the water. Please look at the figure for further clarification (with black, red and green cells representing banks, obstructions and free water respectively). So, if the stone is thrown a distance 7, it will bounce and travel a distance of 3, then finally a distance of 1, having travelled a total distance of 11 (the green path in the figure). If a stone is thrown a distance of 8, it will reach the opposite bank, and if thrown at distances of 2 or 6 it will hit an obstruction during its travel. These are the three red paths in the figure.
You are given a String water. An ‘X’ represents an obstruction, while a ‘.’
represents water free from obstruction. You are to return an int representing
the maximum distance a stone can travel and finally fall in the water, without
hitting any obstructions, and without reaching the opposite bank (going beyond
the end of the string). You may choose any initial distance for the throw,
which starts from the left side of the string. A distance of 1 is the first
character of the string, etc. If no initial throw will result in the stone
landing in the water without hitting an obstruction, return 0.
给予一个 String 输入：water. 其内’X'字符代表礁石，’.’ 代表无礁石水面。你的程序
返回一个整数int，表示该石头在最终落入水中的情况下运行的总最大距离，触礁、撞岸的
情形都必须排除。其中撞岸表征为 (字符串访问越上界). 你可以选择任何初始的投掷距离
，出发点为字符串最左侧。距离为1则抵达字符串的第一个字符，依此类推。如果没有投掷
距离，石头被当作直接入水，返回量为0。
定义：
Class:
SkipStones
Method:
maxDistance
Parameters:
String
Returns:
int
Method signature:
int maxDistance(String water)
(确保你的函数为公共类型 public)
注：
礁石处在水面，所以不存在石头入水后撞礁的情形。
限制条件：
water 字符串包含1到50个元素[即礁石或水面]，1、50包含在内。
water的每个元素包含1到50个字符, 1、50包含在内。
water的每个元素的每个字符要么是’X'，要么是 ‘.’.
测试例子
0)
“..X…..X…”
返回: 11
该例正如题目中（绿色轨迹）所图示。
1)
“…X…”
返回: 3
假如没有该礁石,可以扔一距离4,从而总距离为7。但在有礁石情形下，最佳则是扔出距离2
，再跳1而停止。
2)
“….X….X…XXXX.X…..”
返回: 22
12 + 6 + 3 + 1 = 22, 为最佳结果.
3)
“XXXXXXX.XXX.X..”
返回: 15
Constraints

baskets will be between 1 and 5, inclusive.

capacity will be between 1 and 20, inclusive.

balls will be between 1 and 100, inclusive.
Examples
0)
????
2
20
2
Returns: 3
The example from the problem statement.
1)
????
3
20
1
Returns: 3
We have only 1 ball, so we must choose which of the three baskets to place it in.
2)
????
3
20
2
Returns: 6
We can place both balls in the same basket (3 ways to do this), or one ball in each of two baskets (3 ways to do this).
3)
????
1
5
10
Returns: 0
We have more balls than our basket can hold.
4)
????
4
5
10
Returns: 146
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

cityMap will contain between 1 and 50 elements, inclusive.

Each element of cityMap will contain between 1 and 50 characters, inclusive.

Each element of cityMap will contain the same number of characters.

Each character of each element of cityMap will be 'B', 'X', or '.'.

There will be exactly one 'X' character in cityMap.

walkingDistance will be between 1 and 100, inclusive.
Examples
0)
????
{"...B.",
".....",
"..X.B",
".....",
"B...."}
3
Returns: 2
You can reach the bus stop at the top (3 units away), or on the right (2 units away). The one in the lower left is 4 units away, which is too far.
1)
????
{"B.B..",
".....",
"B....",
".....",
"....X"}
8
Returns: 3
A distance of 8 can get us anywhere on the map, so we can reach all 3 bus stops.
2)
????
{"BBBBB",
"BB.BB",
"B.X.B",
"BB.BB",
"BBBBB"}
1
Returns: 0
Plenty of bus stops, but unfortunately we cannot reach any of them.
3)
????
{"B..B..",
".B...B",
"..B...",
"..B.X.",
"B.B.B.",
".B.B.B"}
3
Returns: 7
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

grid will contain between 1 and 50 elements, inclusive.

Each element of grid will contain between 1 and 50 uppercase ('A''Z') letters, inclusive.

Each element of grid will contain the same number of characters.

find will contain between 1 and 50 uppercase ('A''Z') letters, inclusive.
Examples
0)
????
{"ABC",
"FED",
"GHI"}
"ABCDEFGHI"
Returns: 1
There is only one way to trace this path. Each letter is used exactly once.
1)
????
{"ABC",
"FED",
"GAI"}
"ABCDEA"
Returns: 2
Once we get to the 'E', we can choose one of two directions for the final 'A'.
2)
????
{"ABC",
"DEF",
"GHI"}
"ABCD"
Returns: 0
We can trace a path for "ABC", but there's no way to complete a path to the letter 'D'.
3)
????
{"AA",
"AA"}
"AAAA"
Returns: 108
We can start from any of the four locations. From each location, we can then move in any of the three possible directions for our second letter, and again for the third and fourth letter. 4 * 3 * 3 * 3 = 108.
4)
????
{"ABABA",
"BABAB",
"ABABA",
"BABAB",
"ABABA"}
"ABABABBA"
Returns: 56448
There are a lot of ways to trace this path.
5)
????
{"AAAAA",
"AAAAA",
"AAAAA",
"AAAAA",
"AAAAA"}
"AAAAAAAAAAA"
Returns: 1
There are well over 1,000,000,000 paths that can be traced.
6)
????
{"AB",
"CD"}
"AA"
Returns: 0
Since we can't stay on the same cell, we can't trace the path at all.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

keystrokes will be contain between 1 and 50 'L', 'R', 'H', and 'E' characters, inclusive.

N will be between 1 and 100, inclusive.
Examples
0)
????
"ERLLL"
10
Returns: 7
First, we go to the end of the line at position 10. Then, the rightarrow does nothing because we are already at the end of the line. Finally, three leftarrows brings us to position 7.
1)
????
"EHHEEHLLLLRRRRRR"
2
Returns: 2
All the rightarrows at the end ensure that we end up at the end of the line.
2)
????
"ELLLELLRRRRLRLRLLLRLLLRLLLLRLLRRRL"
10
Returns: 3
3)
????
"RRLEERLLLLRLLRLRRRLRLRLRLRLLLLL"
19
Returns: 12
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
没有难度
Constraints

s will contain between 1 and 50 digits, inclusive.
Examples
0)
????
"435245019"
Returns: {"435", "245", "019" }
The example above.
1)
????
"9"
Returns: {"9" }
2)
????
"0123456789"
Returns: { }
This input has 10 digits, and 10 is not a perfect square.
3)
????
"3357002966366183191503444273807479559869883303524"
Returns: {"3357002", "9663661", "8319150", "3444273", "8074795", "5986988", "3303524" }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
局搞笑的题目。这次中国锦标赛的模拟题比起上次东亚的差的太远了。解一个吧：
Notes

The cursor only paints the canvas if it moves (see example 1).
Constraints

commands will contain between 1 and 50 elements, inclusive.

Each element of commands will be formatted as either "LEFT" or "FORWARD x" (quotes for clarity only), where x is an integer between 1 and 19, inclusive, with no extra leading zeros.

When executing the commands in order, the cursor will never leave the 20 x 20 pixel canvas.
Examples
0)
{"FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19"}
Returns:
{"XXXXXXXXXXXXXXXXXXXX",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"XXXXXXXXXXXXXXXXXXXX" }
This sequence of commands draws a 20 x 20 outline of a square. The cursor is initially at (0, 0) pointing straight down. It then travels to (0, 19) after the first FORWARD command, painting each pixel along its path with a '*'. It then rotates 90 degrees left, travels to (19, 19), rotates 90 degrees left, travels to (19, 0), rotates 90 degrees left, and finally travels back to (0, 0).
1)
{"LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT"}
Returns:
{"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"...................." }
The cursor spins round and round, but never actually paints any pixels. The result is an empty canvas.
2)
{"FORWARD 1"}
Returns:
{"X...................",
"X...................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"...................." }
Going forward by one pixel creates a line that is 2 pixels long because both the start and end points are painted.
3)
{"LEFT", "FORWARD 19", "LEFT", "LEFT", "LEFT",
"FORWARD 18", "LEFT", "LEFT", "LEFT", "FORWARD 17",
"LEFT", "LEFT", "LEFT", "FORWARD 16", "LEFT",
"LEFT", "LEFT", "FORWARD 15", "LEFT", "LEFT", "LEFT",
"FORWARD 14", "LEFT", "LEFT", "LEFT", "FORWARD 13",
"LEFT", "LEFT", "LEFT", "FORWARD 12", "LEFT", "LEFT",
"LEFT", "FORWARD 11", "LEFT", "LEFT", "LEFT", "FORWARD 10",
"LEFT", "LEFT", "LEFT", "FORWARD 9", "LEFT", "LEFT",
"LEFT", "FORWARD 8", "LEFT", "LEFT", "LEFT", "FORWARD 7"}
Returns:
{"XXXXXXXXXXXXXXXXXXXX",
"...................X",
"..XXXXXXXXXXXXXXXX.X",
"..X..............X.X",
"..X.XXXXXXXXXXXX.X.X",
"..X.X..........X.X.X",
"..X.X.XXXXXXXX.X.X.X",
"..X.X.X........X.X.X",
"..X.X.X........X.X.X",
"..X.X.X........X.X.X",
"..X.X.X........X.X.X",
"..X.X.X........X.X.X",
"..X.X.X........X.X.X",
"..X.X.X........X.X.X",
"..X.X.XXXXXXXXXX.X.X",
"..X.X............X.X",
"..X.XXXXXXXXXXXXXX.X",
"..X................X",
"..XXXXXXXXXXXXXXXXXX",
"...................." }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
emu解答：
Class:  SongRenamer 
Method:  rename 
Parameters:  String[], String[], String[], String[], String 
Returns:  String[] 
Method signature:  String[] rename(String[] artists, String[] albums, String[] tracks, String[] titles, String format) 
(be sure your method is public) 
 
Returns: {"Marvin Gaye  Here My Dear09Annas Song", "Marvin Gaye  Whats Going On7Right On" }  
 
Returns: {"Number Two. Something_McLemore Avenue_(Something)" }  

 
Returns: {"You Cant Do That (You Cant Do That) You Cant Do That", "You Cant Do That (You Cant Do That) You Cant Do That", "You Cant Do That (You Cant Do That) You Cant Do That" }  
 
Returns: {" s p a c e s ._ The Leading Spaces_ (Trailing Space )" }  

 
Returns: {"()(). " }  

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Class:  Crop 
Method:  crop 
Parameters:  String[], String[] 
Returns:  String[] 
Method signature:  String[] crop(String[] image, String[] crops) 
(be sure your method is public) 
 
Returns: {"X.", ".." }  

 
Returns: {"X.X.X.X.X.X.X.X", ".X.X.X.X.X.X.X." }  

 
Returns: {"." }  
 
Returns: {".X..X.", "......", "X....X", ".XXXX." }  
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

url will contain between 1 and 50 characters, inclusive.

Each '%' in the input will be followed by a hexadecimal value between 20 (hex) and 7E (letters will be uppercase).

Each character in the input will have ASCII value between 32 and 126, inclusive.
Examples
0)
????
"http://www.%20%40%20%40%20.com/%25"
Returns: "http://www. @ @ .com/%"
"%20" is the escape sequence for ' ', while "%40" stands for '@' and "%25" stands for '%'.
1)
????
"%20%21%22%23%24%25%26%27%28"
Returns: " !\"#$%&'("
2)
????
"%48%65%6C%6C%6F%20%57%6F%72%6C%64%21"
Returns: "Hello World!"
3)
????
"%2525"
Returns: "%25"
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
The city has received enough funds to build one additional fire station, and the mayor has decided that it is most important to minimize the average distance between a person and the closest fire station to that person. The metric used to determine the distance between two locations in the city is the Manhattan distance between the two blocks on which the locations are situated. The Manhattan distance between two blocks (r1, c1) and (r2, c2) is r1r2+c1c2 (the vertical bars represent absolute value). Determine the block on which the new station should be built and return its row and column formatted as "r c" (quotes for clarity only). The return String should contain no extra leading zeros. If multiple blocks are equally optimal, return the one with the lowest row, and if multiple optimal blocks have the same lowest row, return the one among them with the lowest column. If adding an additional fire station would not reduce the average distance between a person and the closest fire station to that person, return the empty String ("").
Definition
????
Class:
NewStation
Method:
location
Parameters:
String[], String[]
Returns:
String
Method signature:
String location(String[] grid, String[] stations)
(be sure your method is public)
????
Constraints

grid will contain between 1 and 20 elements, inclusive.

Each element of grid will contain between 1 and 20 characters, inclusive.

Each element of grid will contain exactly the same number of characters.

Each element of grid will contain only digits ('0''9').

At least one character in grid will be nonzero.

stations will contain between 1 and 10 elements, inclusive.

Each element of stations will be formatted as "r c" (quotes for clarity only), where r and c are each integers between 0 and 19, inclusive, with no leading zeros.

Each element of stations will represent a location within the boundaries of grid.
Examples
0)
????
{"111",
"111",
"111"}
{"1 1"}
Returns: "0 1"
There's an existing station at (1, 1) and each block contains exactly the same number of people. Placing a new station at either (0, 1), (1, 0), (1, 2), or (2, 1) would minimize the average distance. (0, 1) is chosen since it has the lowest row. Adding the new station reduces the average distance from approximately 1.33 to 1.0. The distance from each block to the nearest station becomes:
101
101
212
1)
????
{"111",
"111",
"111"}
{"0 0", "0 1", "0 2",
"1 0", "1 1", "1 2",
"2 0", "2 1", "2 2"}
Returns: ""
There's a fire station on every block, so adding a new station would not reduce the average distance.
2)
????
{"2312",
"0233"}
{"1 3"}
Returns: "0 1"
Placing a fire station at (0, 1) would make the average distance 0.625.
3)
????
{"2312",
"0233"}
{"1 1", "1 1"}
Returns: "0 3"
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

sales will contain between 1 and 50 elements, inclusive.

Each element of sales will be formatted as described in the problem statement, with at least 1 product and at most 50 characters.

CLIENT_ID and each PRODUCT_* will contain between 1 and 10 uppercase letters ('A''Z'), inclusive.

Each CNT_* will represent an integer between 1 and 999, inclusive, with no leading zeros.

client will contain between 1 and 10 uppercase letters ('A''Z'), inclusive.

product will contain between 1 and 10 uppercase letters ('A''Z'), inclusive.
Examples
0)
????
{"BOB 1 SHOE",
"JOHN 2 SHOE",
"BOB 3 SHOE 1 HORSE"}
"BOB"
"SHOE"
Returns: 4
1)
????
{"MEG 1 TV 1 VCR 10 DVD 3 DVD",
"HARRY 2 TV 6 DVD",
"MEG 11 DVD",
"MEG 2 TV",
"HARRY 101 DVD"}
"MEG"
"DVD"
Returns: 24
Note that "DVD" occurs twice in the first element.
2)
????
{"GEORGE 999 PETS"}
"BOB"
"SHOE"
Returns: 0
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

collection will contain between 1 and 50 elements, inclusive.

Each element of collection will be formatted as described in the problem statement.

Each element of collection will contain between 7 and 50 characters, inclusive.

Each genre, artist, album, and song in collection will contain between 1 and 20 characters, inclusive.

collection will contain no duplicate elements.

filterInfo will contain between 1 and 4 elements, inclusive.

Each element of filterInfo will be formatted as described in the problem statement.

Each value in filterInfo will contain between 1 and 20 characters, inclusive.
Examples
0)
????
{"jazzjoe passvirtuosocherokee",
"rockled zeppeliniilemon song",
"countrydwight yoakamlong way homethings change",
"metaliron maidenpowerslaveaces high",
"popsupremesmore hitsask any girl",
"rockfaith no moreangel dustrv",
"jazzchuck mangionefeels so goodfeels so good",
"rockvan haleniispanish fly"}
{"genre=rock", "album=ii"}
Returns: {"rockled zeppeliniilemon song", "rockvan haleniispanish fly" }
This filter returns all the rock songs from albums with the title "ii".
1)
????
{"rockjimi hendrixaxis bold as lovelittle wing",
"rockcarscarsmoving in stereo",
"rockjimi hendrixelectric ladylandgypsy eyes",
"bluesalbert collinsice pickinice pick",
"rockjimi hendrixaxis bold as lovebold as love",
"rockjimi hendrixaxis bold as loveexp"}
{"artist=jimi hendrix", "album=axis bold as love"}
Returns:
{"rockjimi hendrixaxis bold as lovelittle wing",
"rockjimi hendrixaxis bold as lovebold as love" }
This filter returns all the songs that are from the album "axis bold as love" by the artist "jimi hendrix". The last element in the collection is not returned because there are two spaces between "jimi" and "hendrix".
2)
????
{"rockozzy osbourneblizzard of ozzdee",
"rockmarvelous threehey albumlet me go",
"rockcheap trickin colordowned"}
{"genre=soul"}
Returns: { }
There is no soul music in this collection, so an empty String[] is returned.
3)
????
{"countrytopcoderthe country albumtwangy",
"rocktopcoderthe rock albumrockin",
"jazztopcoderthe jazz albumjazzy",
"soultopcoderthe soul albumsoulful",
"metaltopcoderthe metal albumthrash"}
{"artist=topcoder", "genre=jazz", "album=the jazz album", "song=jazzy"}
Returns: {"jazztopcoderthe jazz albumjazzy" }
4)
????
{"popjackson fiveabcthe love you save",
"rockac dcpowerageriff raff"}
{"genre=pop", "genre=rock"}
Returns: { }
No single element of collection can represent more than one genre, so this filter returns an empty String[].
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Given the String[] macro, perform all the operations in the macro in order and return the final state of the image layers as a String[]. The String[] should contain exactly the same number of elements as there are layers in the final image, and each element i should correspond to the ith layer. Each element of the String[] should be a single space delimited list of the filenames contained in that layer. The filenames should be sorted in alphabetical order within each layer.
Definition
????
Class:
ImageLayers
Method:
contents
Parameters:
String[]
Returns:
String[]
Method signature:
String[] contents(String[] macro)
(be sure your method is public)
????
Constraints

macro will contain between 1 and 50 elements, inclusive.

Each element of macro will be formatted as either "OPEN filename" or "MERGE layer1layer2".

Each filename in macro will contain between 1 and 15 lowercase letters ('a''z'), inclusive.

Each layer1 and layer2 in macro will be integers between 0 and n1, inclusive, with no leading zeros, where n is the number of layers that exist in the image immediately before the command is executed.

Within each element of macro that represents a merge command, layer1 will be less than layer2.

The first element of macro will be an OPEN command.
Examples
0)
????
{"OPEN background",
"OPEN aone",
"OPEN atwo",
"OPEN foreground",
"MERGE 02",
"OPEN border"}
Returns: {"aone atwo background", "foreground", "border" }
After the first four commands in macro are executed, the layers are (from bottom to top):
0. background 1. aone 2. atwo 3. foreground
The merge command combines the bottom three layers into a single layer. There are now only two layers (from bottom to top):
0. background aone atwo 1. foreground
Finally, one last file is opened and placed in a new layer on top. The final return value contains the filenames within each layer sorted alphabetically:
0. aone atwo background 1. foreground 2. border
1)
????
{"OPEN sky",
"OPEN clouds",
"OPEN ground",
"MERGE 01",
"OPEN grass",
"MERGE 02",
"OPEN trees",
"OPEN leaves",
"OPEN birds",
"MERGE 12",
"MERGE 01"}
Returns: {"clouds grass ground leaves sky trees", "birds" }
2)
????
{"OPEN a", "OPEN b", "OPEN a", "OPEN a", "MERGE 03"}
Returns: {"a a a b" }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Constraints

size will be between 10 and 100, inclusive.

disk will contain between 1 and 12 elements, inclusive.

Each element of disk will contain between 1 and 50 characters, inclusive.

Each element of disk will be a singlespace delimited list of integers, without extraneous leading zeros.

Each integer in disk will be between 0 and size1, inclusive.

No integer will be appear more than once in disk.
Examples
0)
????
{"3 4 5 6 8 9 10","17 16 15"}
20
Returns: 5
We can defrag the first file by moving the contents of sector 8 to sector 7, then 9 to 8, and finally 10 to 9. The second file can be defragged in a number of ways by moving the contents of two sectors, for a total of 5.
1)
????
{"1 2 3 5 4 6 7 8"}
10
Returns: 2
Here we can take advantage of the fact that we have enough memory to hold two sectors worth of data. First, load the contents of sectors 4 and 5 into memory. Now, simply write the data back in the reverse order.
2)
????
{"1 3 5 7","0 2 4 8","6 9"}
100
Returns: 7
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Notes

While the input may have extraneous leading zeros, your return should not.
Constraints

rules will contain between 1 and 50 elements, inclusive.

Each element of rules will be formatted as described in the problem statement.

packets will contain between 1 and 50 elements, inclusive.

Each element of packets will be formatted as described in the problem statement.

Each of the four numbers in an IP address, or a number range in an IP address will be between 0 and 255, inclusive.

Each port or number in a port range will be between 1 and 65535 inclusive.

In any <NUMBER_RANGE> with two numbers, <LOWER_LIMIT> will be less than or equal to <UPPER_LIMIT>.
Examples
0)
????
{"FORWARD 192.168.000.* 001100 192.168.0.10",
"FORWARD 192.168.0.1 80 10.10.95.184 8080",
"ACCEPT 192.168.*.* 25",
"REJECT 192.168.5.38 *"}
{"192.168.0.43 80",
"00192.00168.000.001 00080",
"192.168.0.1 110",
"192.168.1.73 80",
"192.168.1.73 25",
"206.26.210.5 53",
"192.168.5.38 25"
}
Returns:
{ "192.168.0.10:80",
"10.10.95.184:8080",
"REJECT",
"REJECT",
"ACCEPT",
"REJECT",
"REJECT" }
Packet 0 matches rule 0, and gets forwarded according to that rule. Packet 1 matches both rules 0 and 1, so rule 1 is applied. Packets 2, 3, and 5 don't match any rules, so they are rejected. Packet 4 matches rule 2, and is therefore accepted. Packet 6 matches rules 2 and 3, so it gets rejected (rule 3 is applied).
1)
????
{"FORWARD *.*.*.* * 192.168.0.1"}
{"213.148.161.82 9484",
"172.230.108.145 16627",
"122.141.122.130 46874",
"241.145.145.77 26390",
"139.97.106.125 35305",
"244.131.151.77 26390"}
Returns:
{ "192.168.0.1:9484",
"192.168.0.1:16627",
"192.168.0.1:46874",
"192.168.0.1:26390",
"192.168.0.1:35305",
"192.168.0.1:26390" }
2)
????
{"REJECT *.20252.114157.3691 1317154085",
"ACCEPT *.*.73180.* *",
"FORWARD 55.63.173.239 * 168.154.33.25",
"REJECT *.7273.*.48191 *",
"REJECT 20.51.*.* 4579",
"ACCEPT 70166.*.*.86182 *",
"REJECT 88190.*.119157.* 331627844",
"FORWARD *.52221.134250.66207 * 116.94.120.82"}
{"203.11.104.45 44072",
"154.92.128.87 30085",
"20.51.68.55 4579",
"177.73.138.69 14319",
"112.65.145.82 26287",
"55.63.173.239 45899"}
Returns:
{ "ACCEPT",
"ACCEPT",
"REJECT",
"116.94.120.82:14319",
"116.94.120.82:26287",
"168.154.33.25:45899" }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.