#jag2018summerday2f. [jag2018summer_day2_f]Point Sequences

[jag2018summer_day2_f]Point Sequences

Problem Statement

Takahashi-kun sends integer sequences to Aoki-kun every year as his birthday present. But in this year, Takahashi-kun plans to send sequences of points on a two-dimensional plane to Aoki-kun.

Firstly, he makes 33 point sequences: (a0,a1,...,aN1)(a_0, a_1, ..., a_{N-1}), (b0,b1,...,bN1)(b_0, b_1, ..., b_{N-1}), and (c0,c1,...,cN1)(c_0, c_1, ..., c_{N-1}), and makes a point d0d_0. Then he makes the points d1,d2,...,dNd_1, d_2, ..., d_N in this order as follows:

  • For each i=0,1,...,N1i = 0, 1, ..., {N-1}, di+1d_{i+1} is defined as the intersection point of two lines: the line that passes through aia_i and bib_i, and the line that passes through cic_i and did_i.

It can happen that a point di+1d_{i+1} can not be defined for some ii. For example, when two lines are the same, there are an infinite number of intersection points.

Takahashi-kun wants to know the smallest ii such that di+1d_{i+1} can not be defined. To be precise, di+1d_{i+1} can not be defined if either of the following conditions is met.

  • ci=dic_i = d_i
  • two lines given by aia_i, bib_i, cic_i, and did_i are the same, or parallel.

It is guaranteed that aineqbia_i \\neq b_i for all ii.

Note that, in the following sections, xx- and yy- coordinates of a point pp are denoted as p.xp.x and p.yp.y, respectively.

Constraints

  • 1leqNleq100,0001 \\leq N \\leq 100,000
  • $|a_i.x|, |a_i.y|, |b_i.x|, |b_i.y|, |c_i.x|, |c_i.y| \\leq 1,000$
  • d0.x,d0.yleq1000|d_0.x|, |d_0.y| \\leq 1000
  • aineqbia_i \\neq b_i
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN d0.xd_0.x d0.yd_0.y a0.xa_0.x a0.ya_0.y b0.xb_0.x b0.yb_0.y c0.xc_0.x c0.yc_0.y a1.xa_1.x a1.ya_1.y b1.xb_1.x b1.yb_1.y c1.xc_1.x c1.yc_1.y :: aN1.xa_{N-1}.x aN1.ya_{N-1}.y bN1.xb_{N-1}.x bN1.yb_{N-1}.y cN1.xc_{N-1}.x cN1.yc_{N-1}.y

Output

Print the smallest ii such that di+1d_{i+1} can not be defined. If all points are defined, print NN.


Sample Input 1

6
0 0
10 -10 10 10 10 0
0 10 20 10 10 10
0 -10 0 -100 0 10
0 0 0 -100 0 0
0 0 0 1 0 0
31 14 15 92 65 35

Sample Output 1

3

Sample Input 2

11
0 0
299 0 299 1 3 1
1 0 1 1 300 100
299 0 299 1 3 1
1 0 1 1 300 100
299 0 299 1 3 1
1 0 1 1 300 100
299 0 299 1 3 1
1 0 1 1 300 100
299 0 299 1 3 1
1 0 1 1 300 100
0 0 3 1 3 1

Sample Output 2

10