Under construction

Still being built. Things may change

Billiards

Time limit1sMemory limit128 MB

Summary
Decide which of six table pockets a frictionless bouncing ball reaches, or report that it never falls in.
Level

Medium7 of 10

Topics
Math, Number theory, Simulation, Implementation
Solved
No attempts yet

Problem

On a Friday evening, Bajtazar and his friends head to a club for a game of billiards. As usual at such gatherings, an argument breaks out between Bajtazar and Bitol. Bajtazar claims that Bitol's strategy is pointless, because the ball he strikes has no chance of dropping into a pocket. Bitol insists that if he hit the ball hard enough, it would eventually fall into some pocket. Help settle their argument: write a program that decides whether the ball really would fall into a pocket, and if so, which one.

Your program should:

  • read the dimensions of the billiard table, the starting position of the struck ball, and the vector describing how the ball moves after the strike,
  • determine which pocket the ball falls into, or determine that it never falls into any pocket,
  • print the result.

Input

The one and only line contains six integers sxs_x, sys_y, pxp_x, pyp_y, wxw_x, wyw_y separated by single spaces:

  • sxs_x, sys_y: the dimensions of the table, with 1≤sx,sy≤1061 \le s_x, s_y \le 10^6 and sxs_x even,
  • pxp_x, pyp_y: the ball's starting position, with 0≤px≤sx0 \le p_x \le s_x and 0≤py≤sy0 \le p_y \le s_y,
  • wxw_x, wyw_y: the motion vector, with −1000≤wx,wy≤1000-1000 \le w_x, w_y \le 1000.

The table is sxs_x long and sys_y wide. Pockets sit at the four corners and at the midpoints of the two sides of length sxs_x. For example, a table of size (8,3)(8, 3) has pockets at (0,0)(0, 0), (4,0)(4, 0), (8,0)(8, 0), (0,3)(0, 3), (4,3)(4, 3), and (8,3)(8, 3). The ball never leaves the table and moves without friction; every bounce off a cushion follows the rule that the angle of incidence equals the angle of reflection. The ball drops into a pocket exactly when it reaches the point where that pocket is located.

Output

Print a single line: the name of the pocket the ball drops into, or the word NIE if that never happens. The pocket names are:

  • GL: the pocket at (0,sy)(0, s_y)
  • GP: the pocket at (sx,sy)(s_x, s_y)
  • GS: the pocket at (sx/2,sy)(s_x/2, s_y)
  • DL: the pocket at (0,0)(0, 0)
  • DP: the pocket at (sx,0)(s_x, 0)
  • DS: the pocket at (sx/2,0)(s_x/2, 0)

Hint

Examples1

  1. Example 1

    Input
    10 5 7 4 1 2
    
    Expected output
    DP