VPEX P3 - Coding Club

Submit solution

Points: 12 (partial)
Time limit: 0.5s
Memory limit: 64M

Problem types


At coding club, Darcy is watching the bouncing screensaver meme. The screensaver consists of rectangular DVD logo of width A and height B bouncing around a rectangular screen of width W and height H at a speed of 1 unit/second. When the logo touches a side of the screen, it bounces off such that the angle of incidence equals the angle of reflection. When the logo reaches a corner, its direction is simply reversed.

The logo begins at position (x_0,y_0) (measured from the bottom left corner of the screen and logo) and travels in the direction (x,y). After a while, Darcy noticed that the logo returned to it's starting position and velocity. What is the minimum time Darcy had to wait?

Input specification

The first line contains integers W and H, the width and height of the screen.
The second line contains integers A and B, the width and height of the logo.
The third line contains integers x_0 and y_0, representing the starting position of the logo (measured from the bottom left corner of the screen to the bottom left corner of the logo).
The last line contains integers x and y, meaning the logo has the same initial direction as an vector pointing x units right and y units up.

Output specification

Let T be the minimum amount of seconds after beginning such that the logo is at position (x_0,y_0) travelling in direction (x,y). Print the 6 digits beginning from the first non-zero digit of T.

If this will never happen, print -1.


1\le A< W\le1000
1\le B< H\le1000
1\le A+x_0\le W
1\le B+y_0\le H
-10^5\le x,y\le10^5
x\neq 0 or y\neq 0

Subtask 1 [20%]

1\le W,H,x,y\le 15

Sample input

11 11
1 1
5 5
1 1

Sample Output





There are no comments at the moment.