Company: Algo university_2june
Difficulty: medium
Frog Freddy Problem Description Apaar is relaxing beside a large pond while his pet frog Freddy plays in it. The pond has N floating leaves, each described by an x-coordinate and a y-coordinate as viewed from the sky. From the leaf located at (a, b), Freddy can jump: to (a + Z, b + Z), where Z is a natural number. Call this direction A . to (a + Z, b - Z), where Z is a natural number. Call this direction B . to (a - Z, b + Z), where Z is a natural number. Call this direction C . to (a - Z, b - Z), where Z is a natural number. Call this direction D . Apaar shouts one of the directions and Freddy jumps to the first leaf in the chosen direction, that is, the floating leaf reached with the smallest natural number Z. If there is no floating leaf in that direction, Freddy does not move. After Freddy jumps, the leaf he jumped from collapses and sinks forever, so it can never be landed on again. Freddy starts on the first leaf of the input, and all M commands that Apaar shouts are known in ord