One useful modification of the Lee algorithm is to propagate from start and target points alternately. In this case, the algorithm is finished when two points from different origins are intersected. Sometimes this modification allows the algorithm to find the shortest path faster while also using less additional memory. Your task here is to apply the Lee algorithm with this modification for the following grid:
Apply the first iteration of the Lee algorithm for , then move to , after that return to again and so on. Print the coordinates of the first intersection of two points from different origins ( and ) as an answer to this problem. For example, it may look like this:
4 2
The first number is the row and the second number is the column.