Hide

Problem L
Geofencing

Languages en is
/problems/syndargirding/file/statement/en/img-0001.png
Sample 1, made with GeoGebra

Ingfríður decided to participate in a Capture the Flag exercise. To prevent Ingfríður from stealing the flag Jörmunrekur made sure to put a SIM card in the fabric of the flag so he would always know where it is. But Ingfríður was one step ahead and knew he had done this.

She managed to sneak in and swap the flag for a fake one, but now there is a problem. In order to make sure that Jörmunrekur does not realise the flag is fake the SIM card always has to show the position of the fake flag. Ingfríður plans to spy on Jörmunrekur and his team so she knows where the flag is and then spoof the location.

Ingfríður has a copy of the map the SIM card will be using, which is a set of triangles. Now she needs to know, which triangle is Jörmunrekur in?

You may assume that the triangles will not overlap, except on the edges, and that Jörmunrekur is not exactly on the edge of any triangle. He is either strictly inside or strictly outside.

Input

The first line of input contains a positive integer $0 \leq n \leq 1\, 000$, the number of triangles that will follow. Each triangle is given on its own line.

Each triangle consists of three coordinates $x_1, y_1, x_2, y_2, x_3, y_3$ separated by spaces. This denotes the triangle with corners $(x_1, y_1), (x_2, y_2)$ and $(x_3, y_3)$.

Finally there is one more line with two coordinates $x, y$ separated by spaces. This denotes that Jörmunrekur and the flag is at coordinate $(x, y)$.

All coordinates in the input are integers with absolute value at most $10^6$.

Output

If Jörmunrekur is in the $i$-th triangle in the input (the first triangle is the $0$-th triangle), then print $i$. Otherwise if he is in none of the triangles, print $-1$ instead.

Sample Input 1 Sample Output 1
6
2 2 2 10 8 8
2 2 10 2 8 8
10 2 10 4 8 8
14 0 10 4 8 8
14 0 18 16 8 8
18 16 2 10 8 8
14 1
4
Sample Input 2 Sample Output 2
0
0 0
-1

Please log in to submit a solution to this problem

Log in