#P5427. The Misbehaving Cow

    ID: 18659 Type: Default 1000ms 256MiB

The Misbehaving Cow

The Misbehaving Cow

Farmer John is trying to take an aerial photograph of his herd with a drone. He wants all his cows to face the same direction for the perfect shot. The cows are arranged in an N × N grid (with 2 ≤ N ≤ 1000) where each cow faces either right (denoted by R) or left (denoted by L). Unfortunately, due to the cows being very close together, Farmer John cannot individually command a cow to turn around. His only option is to shout at an entire row or column, which makes every cow in that row or column reverse direction (i.e. change R to L and vice‐versa). He may issue as many commands as he likes (even on the same row or column more than once).

Surprisingly, Farmer John has discovered that it is not possible to get all the cows to face the same direction by these operations. However, he found that he can get all of them except one to be uniform. Your task is to identify that one misbehaving cow. (If more than one such cow exists, output the one with the smallest row index, and if there is still a tie, the one with the smallest column index.)

Explanation: It can be shown that a necessary and sufficient condition for a configuration to be made uniform by row and column flips is that, when we encode R as 1 and L as 0, the following relation holds for every cell:

\( B[i][j] = B[i][1] \oplus B[1][j] \oplus B[1][1] \)

for all 1 ≤ i, j ≤ N. In the above equation, \(\oplus\) denotes the XOR operation. The given configuration does not satisfy this property, but by flipping one cow’s direction (i.e. toggling its bit) the condition can be met. Find that cow.

inputFormat

The first line contains a single integer N (2 ≤ N ≤ 1000). Each of the next N lines contains a string of length N, consisting solely of the characters R and L, representing the current orientation of the cows.

outputFormat

If there is a cow that if flipped makes the configuration transformable to a uniform orientation by some sequence of row and column flips, output its 1-indexed row and column numbers separated by a space. If no such cow exists, output -1.

sample

3
RLR
RRL
LLR
2 1

</p>