2021 年东华大学金马程序设计联赛

K. AEMShana loves games!
PDF 题面可用
你可以在这里下载。

单点时限: 2.0 sec

内存限制: 512 MB

AEMShana loves playing video games.Recently he finds a Barrage game called Touhou Project.


Just like the picture above, AEMShana was born in the middle of a 10-meter-long street at time zero. AEMShana can only move one meter each second. Of course, he can stay where he is. For example, AEMShana can stay at 5 or move to 4 or 6 at the first second. And the sky will fall two kinds of balls. When you catch the balls you will get or lose points. If you are in the place where the ball is when it hits the ground, then you catch it (Whether you want to catch it or not). You will get one point when you catch the white ball while you will lose one point when you get the black ball. To break the game record,AEMShana hacked the games, So he knows when and where the black or white balls hit the ground. Can you help AEMShana calculate how much point can he get in this game? The point is zero at first and it can be negative(like -1).Remember that there may be many balls hit at the same time and place.

输入格式

There are multiple test cases in this problem.

In each test case, there is $N+1$ line, the first line contains an integer $N$ and each after $N$ lines contains integers $t, p, k$ which means the time when the balls hit the ground, the place where the balls hit the ground and the kind(‘0’ is white ball and ‘1’ is black ball) of the balls hited the ground.$(1\leq N\leq 10^6,1\leq t\leq 10^5,0\leq p\leq 10)$

输出格式

Print the highest point that AEMShana can get in this game.

样例

Input
6
1 5 0
2 0 0
2 10 1
5 9 0
3 7 0
4 8 1
3
1 5 1
1 4 1
1 6 1
Output
2
-1