eolymp
bolt
Try our new interface for solving problems

Pinball

\includegraphics{https://static.e-olymp.com/content/64/64bbf4df2ac26dead5981b3d51d2e6c990ad18d0.jpg} Maria is quite addicted to pinball. She can shoot the ball to any position at the top of the board, but she cannot predict where the ball will end when it falls down, because it hits many bumpers on its way down. She decided to model the pinball table as line segments and assume that the ball is a point that falls from infinite height. The ball falls straight vertically unless there is a segment immediately below it, in which case it follows the direction of the segment downwards until its end. As you would expect the segments are closed, that is an endpoint is part of its segment. Pairs of segments do not intersect, not even at endpoints, and none is vertical or horizontal. Segments are not given in any specific order. \InputFile The first line contains an integer \textbf{N} (\textbf{0} ≤ \textbf{N} ≤ \textbf{100000}), the number of segments. Then \textbf{N} lines follow, each with four integers \textbf{x_1 y_1 x_2 y_2}, the coordinates of a segment (\textbf{-1000000} ≤ \textbf{x_i}, \textbf{y_i} ≤ \textbf{1000000}). The last line contains an integer \textbf{x_0} (\textbf{-1000000} ≤ \textbf{x_0} ≤ \textbf{1000000}), the initial \textbf{x}-coordinate of the ball. \OutputFile Output a single integer \textbf{x_T}, the final \textbf{x}-coordinate of the ball. \includegraphics{https://static.e-olymp.com/content/e9/e9333841c0033c629c9c62b961c83e1f5202e09c.jpg} \textit{\textbf{Figure 1}}: Sample input 1 \textit{\textbf{Figure 2}}: Sample input 2
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
2
-1 1 1 -1
1 -2 2 -3
0
Çıxış verilənləri #1
2
Mənbə ACM ICPC NCPC 2013, 5th October 2013