A Susquehanna International Group path simulator moves from the origin to a target grid point. Each move is exactly one unit up or one unit right. The simulator rejects any path containing three consecutive moves in the same direction.
Given nonnegative integers rows and cols, count the valid paths from (0, 0) to (rows, cols). Return the result modulo 1_000_000_007.
A path may end with a run of one or two identical moves, but never three or more. The first move has no previous direction or run length.
Implement count_valid_paths(rows, cols), where both inputs are integers. Return an integer representing the number of valid paths modulo 1_000_000_007.
def count_valid_paths(rows, cols):