#P8008. Bamboo Cutting in the Mystic Bamboo Grove

    ID: 21192 Type: Default 1000ms 256MiB

Bamboo Cutting in the Mystic Bamboo Grove

Bamboo Cutting in the Mystic Bamboo Grove

Yumeko (妖梦) has chosen a set of bamboo in a mystical bamboo grove. In this grove, infinitely many bamboo stalks lie in a plane; they are arranged as an infinite set of parallel lines with equal spacing and identical inclination. In fact, the bamboo lines can be represented by the equations

[ \cos\theta, x + \sin\theta, y = k,a, \quad \text{for all integers } k, ]

where (a > 0) is the spacing and (\theta) (in radians) is the inclination angle.

Yumeko selects a simple polygonal region (with (n) edges) in which to harvest the bamboo. Only the parts of the bamboo that lie strictly inside the polygon (i.e. the parts marked in orange in the figure) are collected. To avoid ambiguity, it is guaranteed that no edge of the polygon is parallel to the bamboo lines.

Your task is to compute the total length of the bamboo segments (i.e. all portions of the bamboo lines that lie inside the polygon).

Note: The bamboo lines are defined by

[ \cos\theta, x + \sin\theta, y = k,a,\quad k\in\mathbb{Z}, ]

and you are given the polygon by its (n) vertices in order (clockwise or counterclockwise). All real numbers in the input are given with sufficient precision such that an answer with an absolute or relative error at most (10^{-6}) is accepted.

inputFormat

The first line contains two real numbers (\theta) and (a) (with (0 \le \theta < \pi) and (a > 0)), where (\theta) is given in radians. The second line contains an integer (n) ((3 \le n \le 10^5)), the number of vertices of the polygon. Each of the next (n) lines contains two real numbers (x) and (y), the coordinates of the polygon's vertices given in order (either clockwise or counterclockwise).

outputFormat

Output a single real number representing the total length of the bamboo segments inside the polygon. The answer is accepted if its absolute or relative error does not exceed (10^{-6}).

sample

0 1
4
0 0
1 0
1 1
0 1
2.000000