Wesley's Anger Contest Reject 6 - Geology
View as PDFKesley is studying geology! He is given two maps of different  by 
 regions. The first map is divided into an 
 grid of equal-sized squares, while the second map is divided into an 
 grid of equal-sized squares. The grids can be represented as a string of characters with 
# indicating the square is mostly rocks and . indicating the square is mostly empty.
When Kesley overlays the two maps on top of each other, he wants to know how similar the two  by 
 regions are. A point on the map is considered similar if it is rocky in both regions or empty in both regions. It can be shown that the percentage of points that are similar can be represented as a fraction 
. The similarity of the two maps is equal to 
 where 
 is the multiplicative inverse modulo 
. It may be helpful to know that 
 is prime and 
.
Can you help Kesley determine the similarity of the two maps?
Constraints
For this problem, you will be required to pass all the samples in order to receive any points. In addition, you must pass all previous subtasks to earn points for a specific subtask.
For all subtasks:
Subtask 1 [36%]
Subtask 2 [64%]
No additional constraints.
Input Specification
The input consists of  lines.
The first line contains a single integer , the size of the grid for the first map.
The next  lines contain 
 characters of either 
# or ., describing the first map. # indicates a rocky square, while . indicates an empty square.
The next line contains a single integer , the size of the grid for the second map.
The next  lines contain 
 characters of either 
# or ., describing the second map.
Output Specification
This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.
Output a single integer representing the similarity of the two maps.
Sample Input
2
#.
.#
3
#.#
.#.
#.#
Sample Output
499122177
Sample Explanation
 of the points in the region are similar.
Comments