P3738 [HAOI2014] Crossing the Blockade Line

Description

An enemy-occupied area is a closed polygon represented by consecutive vertices $P_1(x_1,y_1)$, $P_2(x_2,y_2)$, $\cdots$, $P_n(x_n,y_n)$. Our scout ZDM-007 needs to cross the blockade line of the enemy-occupied area. For safety, ZDM-007 travels along a path perpendicular to the $X$-axis, moving from south to north. Given the current position of ZDM-007, can you compute the total length of his route that lies inside the enemy-occupied area while he crosses the blockade line? ![](https://cdn.luogu.com.cn/upload/pic/5207.png)

Input Format

The first line: $n$, the number of polygon vertices. The next $n$ lines: $x_i, y_i$, the coordinates of the polygon vertices (given in counterclockwise order). The last line: $X, Y$, the scout’s initial position.

Output Format

Output the total length of the scout’s path that lies inside the enemy-occupied area while crossing the blockade line. Print only the integer part.

Explanation/Hint

Constraints $3\le n\le 50, 0\le x_i, y_i \le 1000, 0\le X \le 1000, -100\le Y < 0$. Translated by ChatGPT 5