Under construction

Still being built. Things may change

Dart

Time limit2sMemory limit1024 MB

Summary
Given a convex polygon dartboard and two lists of dart throws, compute each player's total score modulo 1e9+7 and report the winner.
Level

Hard8 of 10

Topics
Geometry, Binary search, Prefix sum
Solved
No attempts yet

Problem

Yeongmin and Hyeonbin always have dinner together, and they always disagree about the menu. So they agreed to settle it fairly with darts: the winner picks the menu. Neither of them knows darts well, but both like programming, so they defined the following scoring rules.

  • The dartboard is a convex NN-gon. No three of its vertices are collinear.
  • If a dart lands strictly inside the dartboard, the score is twice the area of the dartboard.
  • If a dart lands on the boundary of the dartboard, the score is 0.
  • If a dart does not land inside the dartboard, the score is computed as follows.
    • From the point where the dart landed, draw two tangent lines to the dartboard. If a tangent line touches the dartboard at a vertex, the tangent point closer to the dart is used.
    • Draw the segment connecting the two tangent points.
    • The segment divides the dartboard into two regions. The score is twice the area of the smaller of the two regions (the one that is not larger).

Yeongmin and Hyeonbin each throw the dart MM times. The total score of each person is taken modulo 1 000 000 007(=109+7)1\,000\,000\,007(=10^9+7), and the person with the larger remainder wins.

Input

The first line contains the number of vertices NN and the number of throws MM. (3≤N≤50 0003 \leq N \leq 50\,000, 1≤M≤50 0001 \leq M \leq 50\,000)

From the second line through line N+1N+1, each line contains the x and y coordinates of a vertex of the dartboard, separated by a space. The vertices are given in counterclockwise order.

From line N+2N+2 through line N+1+MN+1+M, each line contains the x and y coordinates of the point where one of Yeongmin's darts landed, separated by a space.

The next MM lines contain the x and y coordinates of the points where Hyeonbin's darts landed, separated by a space.

All coordinates are integers with absolute value at most 4×1084\times 10^8.

Output

On the first line, print "ym" if Yeongmin wins, "hb" if Hyeonbin wins, or "same" if the two scores are equal.

On the second line, print Yeongmin's score and Hyeonbin's score, each taken modulo 1 000 000 007(=109+7)1\,000\,000\,007(=10^9+7), separated by a space.

Examples5

  1. Example 1

    Input
    4 1
    1 1
    -1 1
    -1 -1
    1 -1
    0 0
    2 2
    
    Expected output
    ym
    8 4
    
  2. Example 2

    Input
    4 1
    1 1
    -1 1
    -1 -1
    1 -1
    2 2
    0 0
    
    Expected output
    hb
    4 8
    
  3. Example 3

    Input
    4 1
    1 1
    -1 1
    -1 -1
    1 -1
    0 0
    0 0
    
    Expected output
    same
    8 8
    
  4. Example 4

    Input
    10 7
    -10 -6
    -5 -7
    2 -6
    4 -4
    6 4
    6 6
    0 6
    -6 5
    -8 3
    -10 -1
    -4 2
    -3 -5
    5 -5
    4 -1
    3 0
    -3 4
    -4 3
    -3 0
    1 -5
    4 -4
    4 -3
    1 3
    0 4
    -3 5
    
    Expected output
    ym
    2016 2004
    
  5. Example 5

    Input
    5 3
    -9 -6
    -8 -8
    2 -9
    6 9
    -7 -2
    -5 3
    4 -3
    4 0
    -2 2
    3 -2
    -2 3
    
    Expected output
    hb
    30 518