NAQ 2018 Problem D Froggie
The code in the post does not solve the problem. Consider the following input:

1 6
0 3 3
1 UU


The code in the post prints "safe", but in fact the frog is squished, since the cars have speed 3 and separation 3, meaning that a car crosses every square in the lane on every time step, and so the lane is impassable.