Spin Doctor

Given n points (a_i, b_i) labeled 1 or 0, choose a direction (S, T); with ties broken adversarially, minimize the span covering all label-1 points.

Hard9GeometrySortingDivide and conquerBinary searchNo attempts yetTime limit5sMemory limit512 MB

Problem

You work for a polling company, where the job is to take complicated real world questions and boil them down to a few numbers. It is not always easy. A big election is coming, and at the request of Candidate X you have just polled nn people. For the ii-th person you wrote down three values:

  • aia_i, the number of digits of π\pi that person has memorized
  • bib_i, the number of hairs on that person's head
  • cic_i, which is 11 if the person will vote for Candidate X and 00 otherwise

By now you doubt that these were the most useful questions to ask. The data shows no correlation between aa, bb and cc. Contradicting the client is a good way to lose the job, so instead you look for a weighting that makes the numbers look meaningful.

Pick two real numbers SS and TT and sort the nn records by the measure aiS+biTa_i S + b_i T. The sorted list looks best when the people who will vote for Candidate X sit close together. Let jj and kk be the positions of the first and the last record with ci=1c_i = 1 in the sorted list. The cluster size is kj+1k - j + 1, and you want it as small as possible.

Some choices of SS and TT give several records the same measure. Records with the same measure can appear in any relative order, so assume the worst case happens: for that pair (S,T)(S, T) you get the ordering that makes the cluster size as large as possible.

Find the smallest cluster size over all pairs (S,T)(S, T).

Input

The first line contains nn (1n2500001 \le n \le 250000), the number of people polled. Each of the next nn lines contains three integers aia_i (0ai20000000 \le a_i \le 2000000), bib_i (0bi20000000 \le b_i \le 2000000) and cic_i, where cic_i is 11 if that person will vote for Candidate X and 00 otherwise. At least one of the polled people will vote for Candidate X.

Output

Print the smallest cluster size over all pairs of real numbers (S,T)(S, T).