#HK4013. 「eJOI2023」Opening Offices
「eJOI2023」Opening Offices
Description
Your company is planning to open its offices in a city with horizontal and vertical streets with a building at each intersection. Each building is connected to all of its neighbors by up to two vertical and two horizontal roads, each with a length of .
At night, only of the roads are illuminated and others are not available for use. It so happens that these roads form a tree, i.e., they are exactly enough to connect any building to another.

The first figure in the image shows the roads at nighttime, while the second one depicts them during the daytime. The third figure is a simpler example that will be used in explanations below.
Each building can be bought and made to be an office. Each month, you will tour the offices, starting from one building, visiting all the other converted office buildings, and finally returning to the initial building. You will use the available roads for this purpose and minimize the total length of the tour, although you aren't certain about the specific time of day.
In the example on the right, in case of opening the offices in the buildings , and the tour length would be during the day and during the night.
To avoid planning complications, the decision was made to select office buildings in a manner that ensures the minimum length for the tour remains the same both during the day and at night.
Input Format
The first line contains three integers: , and . indicates the exact number of offices you plan to open, except when , in which case you can open any number of offices, but at least two.
Each of the following lines consists of characters (without spaces). The -th character on the -th line is either 0, 1, 2 or 3, describing roads illuminated during the nighttime from the building on the -th street from the top and -th street from the left:
0indicates no roads leading from this building to its upper or left directions.1indicates a road from this building to the one directly above it.2indicates a road from this building to the one directly to its left.3indicates roads from this building to the buildings directly above it and to its left.
There are exactly roads and they form a tree.
Output Format
Print one integer: the number of ways modulo .
2 3 2
022
031
12
Corresponds to the image above.
The offices can be opened in the following pairs of buildings: {A, B}, {A, C}, {A, E}, {A, F}, {B, C}, {B, D}, {B, E}, {B, F}, {C, D}, {C, E}, {C, F}, {D, E}.
2 3 3
022
031
10
Same city with . The offices can be opened in the following triplets of buildings: {A, B, C}, {A, B, E}, {A, B, F}, {A, C, E}, {A, C, F}, {B, C, D}, {B, C, E}, {B, C, F}, {B, D, E}, {C, D, E}.
2 3 1
022
031
25
In addition to the possibilities for and shown above, offices can also be opened in the following ways: {A, B, C, E}, {A, B, C, F}, {B, C, D, E}.
Constraints
Subtasks
- (4 points)
- (5 points)
- (9 points) ;
- (11 points)
- (9 points) ;
- (13 points)
- (14 points) ;
- (10 points) ;
- (9 points) ; Road descriptions do not contain character
3. - (16 points)