Grasshopper
An infinite chessboard extends the standard chessboard infinitely to the right and upwards. Each cell alternates in color between white and black, with the bottom-left cell being black. Each cell has a side length of S millimeters, where 0 < S ≤ 1000. A knight is positioned at coordinates (x, y), where both coordinates are non-negative integers not exceeding 10^5 and are measured in millimeters. The knight jumps by moving dx millimeters to the right and dy millimeters upwards in a single jump, effectively moving from (x, y) to (x+dx, y+dy). Here, dx and dy are non-negative integers not exceeding 2000. Your task is to determine the number of jumps required for the knight to land on a white cell, noting that landing on the boundary of cells does not count as landing on a white cell. It is possible that the knight may never land on a white cell.
Input
The input consists of several (up to 100) sets of five numbers: S, x, y, dx, dy. The input concludes with a set of five zeros.
Output
For each set of numbers in the input, output a single number on a separate line, indicating the number of jumps needed, or –1 if it is impossible for the knight to land on a white cell.