Guessing Game

No attempts yetTime limit1sMemory limit128 MB

Problem

Byteman and Bitman play the following game. Bitman secretly writes down a sequence of 1,000,000,0001{,}000{,}000{,}000 zeros and ones. Byteman's goal is to guess this sequence.

Byteman repeatedly asks Bitman questions of the form:

Is the sum of the subsequence that begins at the bb-th element and ends at the ee-th element of your sequence even or odd?

After playing for a while, Byteman began to suspect that Bitman was answering dishonestly. He would like to know how many of his questions, counting from the first, can still be answered consistently.

Write a program that computes the greatest number mm for which there exists a sequence of zeros and ones consistent with Bitman's answers to the first mm questions.

Input

The first line contains one integer nn (0n100,0000 \le n \le 100{,}000), the number of Byteman's questions.

Each of the following nn lines describes one question together with Bitman's answer as three integers bb, ee, and ss (1be1,000,000,0001 \le b \le e \le 1{,}000{,}000{,}000, s{0,1}s \in \{0, 1\}) separated by single spaces. Here bb and ee are the positions of the first and last elements of the subsequence in that question. s=0s = 0 means the answer was that the sum is even, and s=1s = 1 means it is odd.

Output

Output a single integer mm: the greatest value such that a sequence of zeros and ones consistent with the first mm answers exists.