Rational Billiard#780

Rational Billiard

2 seconds
64 megabytes
Very easy

The International Billiard Manufactory (IBM) builds the best billiard tables in the world. Its latest product is the Rational Billiard, a frictionless table with volume-less balls. This means that the balls only occupy a point in space, and once they are struck with the cue, they move on the table with constant velocity until they hit another ball.

IBM wants you to build a program to analyze the behavior of balls in the Rational Billiard. The program must decide whether a ball, struck at a given angle, will hit another ball at a certain position. The following figures show the configuration of the table and the balls:

and are integer values indicating the size of the table. (x_1, y_1) and (x_2, y_2) are the coordinates of the first and second ball, respectively, where 0 < x_1, x_2 < m and 0 < y_1, y_2 < n. The direction in which the first ball is struck is determined by the integer values and (not both zero). A value p = 0 means the ball moves parallel to the vertical axis, according to the sign of . When the ball hits an edge, it rebounds as if the edge were a mirror (angle of incidence equals angle of reflection). In the special case when the ball hits a corner, it is reflected on the same line but in the opposite direction. Spin effects are ignored.

Input

Each line in the input corresponds to a test case specified by eight integers: , , x_1, y_1, x_2, y_2, , and , where 0 < m, n \leq 1000, 0 < x_1, x_2 < m, 0 < y_1, y_2 < n, -1000 \leq p, q \leq 1000, and |p| + |q| > 0.

The end of input is specified by the line "0 0 0 0 0 0 0 0".

Output

For each test case, output a line containing "HIT" if the first ball hits the second ball, or "MISS" if it does not.

Examples

Example 1

Loading
Loading