P28670 [洛谷] [HAOI2014] Crossing the Blockade
提高
题目描述

Problem Description

A hostile area is represented by a closed polygon, defined by a set of adjacent 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 of the hostile area. For safety reasons, ZDM-007's path is perpendicular to the X-axis, moving from south to north.

Given the initial position of scout ZDM-007, can you calculate the total length of his path within the hostile area when crossing the blockade?

Input Format

The first line: $n$, the number of vertices of the polygon.

The next $n$ lines: $x_i, y_i$, the coordinates of the polygon's vertices (given in counterclockwise order).

The last line: $X, Y$, the initial position of the scout.

Output Format

The total length of the scout's path within the hostile area when crossing the blockade. (Output should be truncated to the integer part.)

Sample Input and Output

Input Sample #1

7 
0 1 
2 0
4 1
2 2 
4 3 
2 4 
0 3 
3 -1

Output Sample #1

2

Input Sample #2

4
10 100
10 0
100 0
100 100
100 -80

Output Sample #2

0

Notes

[Constraints]

$3 \le n \le 50, 0 \le x_i, y_i \le 1000, 0 \le X \le 1000, -100 \le Y < 0$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
7 0 1 2 0 4 1 2 2 4 3 2 4 0 3 3 -1
样例输出
2