시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB56191532.609%

문제

Byteman is playing the following game with Bitman. Bitman writes down a sequence consisting of 1,000,000,000 zeros and ones. Byteman's task is to guess Bitman's sequence. He can achieve this goal by asking Bitman questions of the form: 'Is the sum of a subsequence of your sequence, that begins at the b-th element and ends at the e-th element of the sequence, even or odd?'. After playing the game for some time, Byteman started suspecting that Bitman was cheating. He would like to know at which moment did Bitman first answer his question in an inconsistent way, so he asked you for help.

Write a program which:

  • reads a description of Byteman's questions and Bitman's answers,
  • computes the greatest number m, for which Bitman's answers for the first m questions are consistent.

입력

The first line of the input contains one integer n (0 ≤ n ≤ 100,000), the number of Byteman's questions. Each of the following n lines describes one question with the corresponding Bitman's answer in the form of three integers b, e and s (1 ≤ b ≤ e ≤ 1,000,000,000, s ∈ {0,1}), separated by single spaces. b and e are the indices of the first and the last element of the subsequence in Byteman's question. s = 0 means that Bitman answered that the sum was even and s = 1 that it was odd.

 

출력

The first and only line of the output should contain one integer, the greatest value of m such that there exists a sequence of zeros and ones that is consistent with Bitman's answers to the first m Byteman's questions.

 

예제 입력 1

5
3 3 0
2 5 1
1 4 0
2 5 0
1 5 1

예제 출력 1

3

출처

Camp > POI Training Camp > ONTAK 2007 16번