Under construction

Still being built. Things may change

Space Bowling

Time limit2sMemory limit1024 MB

Summary
Given a triangular array of n rows of circular pins and a ball moving in a straight line, count how many pins the ball touches.
Level

Hard8 of 10

Topics
Geometry, Math, Implementation, Binary search
Solved
No attempts yet

Problem

A new space bowling alley has opened on the planet Plyuk. The field of the bowling alley is an infinite plane on which pins are placed.

Each pin is a tall cylinder whose base is a circle of radius rr meters. All pins are identical. The pins are placed according to the following rules. The pins form nn rows: the first row holds one pin, the second holds two, and so on. The last, nn-th row holds nn pins. Introduce a coordinate system on the plane so that the unit of length equals one kilometer. The center of the only pin in the first row is at (0,0)(0, 0). The centers of the pins in the second row are at (−1,1)(-1, 1) and (1,1)(1, 1). Thus the centers of the pins in the ii-th row are at the points with coordinates (−(i−1),i−1)(-(i - 1), i - 1), (−(i−3),i−1)(-(i - 3), i - 1), …\ldots, (i−1,i−1)(i - 1, i - 1).

The game proceeds as follows. A ball of radius qq meters is used. The player chooses the initial position of the ball's center (xc,yc)(x_c, y_c) and the ball's direction vector (vx,vy)(v_x, v_y). The ball is then placed at the initial position and moves without stopping in the direction of the vector (vx,vy)(v_x, v_y). The ball is considered to have knocked down a pin if at some moment during the ball's motion the ball and the pin share a point. Knocked-down pins do not change the ball's direction and do not knock down neighboring pins as they fall.

The figure shows an example of a pin arrangement for r=500r = 500, n=4n = 4 and a ball for q=1000q = 1000, xc=−2x_c = -2, yc=−2y_c = -2, vx=1v_x = 1, vy=1v_y = 1.

Write a program that, given the pin radius rr, the number of pin rows nn, the ball radius qq, its initial position (xc,yc)(x_c, y_c), and its direction vector (vx,vy)(v_x, v_y), determines the number of pins knocked down by the ball.

Input

The first line of the input file contains two integers rr and nn, separated by exactly one space (1≤r≤7001 \le r \le 700, 1≤n≤200 0001 \le n \le 200\,000).

The second line of the input file contains an integer qq (1≤q≤1091 \le q \le 10^9).

The third line of the input file contains two integers xcx_c and ycy_c, separated by exactly one space (−106≤xc≤106-10^6 \le x_c \le 10^6, −106≤yc-10^6 \le y_c, 1000×yc<−(r+q)1000 \times y_c < -(r + q)).

The fourth line of the input file contains two integers vxv_x and vyv_y, separated by exactly one space (−106≤vx≤106-10^6 \le v_x \le 10^6, 0<vy≤1060 < v_y \le 10^6).

Output

The output file must contain a single integer: the number of pins knocked down.

Notes

The figure below shows which pins are knocked down (such pins are marked with «х»).

Examples1

  1. Example 1

    Input
    500 4
    1000
    -2 -2
    1 1
    
    Expected output
    7