A mountain map is a NxM rectangular grid where each cell has a height. The heights are positive integers between 1 and N*M, inclusive, and no two distinct cells have equal heights. Two cells are called neighboring if they share a side or a corner. A cell is called locally minimal if its height is less than the heights of all its neighboring cells.
You are given a String data. The j-th character of the i-th element of data is 'X' if the j-th cell in the i-th row of the mountain map is locally minimal, and '.' otherwise. Calculate the number of distinct mountain maps that match the data. Return the result modulo 12345678.