Mika with Cherry Cake
题号:NC221566
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Mika wants to make some cherry cakes to eat.

The forest Mika lives can be considered as a two-dimensional Cartesian coordinate. Mika's home is located on .

In the forest, the speed of Mika and merchant is same. If you want to go from to , you will cost seconds, which is the Manhattan distance between them.

If one person if on , when he
go up for seconds, he will be at ,
go down for seconds, he will be at ,
go right for seconds, he will be at,
go left for seconds, he will be at .
Notice: may not be an integer.

Now Mika knows that there will be merchants travel through this forest. The merchant will be at at time and the diraction of each merchant will be given.

Mika will be at his home at time , when he and a merchant are at the same point, he can buy a basket of cherry, and return to the home to drop the basket, then he goes to find the second merchant and so on. You can consider the time Mika spends on buying cherries and dropping the basket at home is .

Mika is a fairy, so he can't hold two or more baskets of cherry, so he can only buy one basket of cherry and return home to drop the basket.

Now Mika wants to know the maximum baskets of cherry he can buy?

输入描述:

The first line is an integer , repersenting the number of merchant.
The next lines are Three integers ,representing the position of the merchant and the direction the merchant travels.



If , the merchant is moving up.
If , the merchant is moving down.
If , the merchant is moving right.
If , the merchant is moving left.

输出描述:

One integer, the maximum baskets of cherry Mika can buy.
示例1

输入

复制
4
1 1 1
1 1 2
1 1 4
3 3 2

输出

复制
1

说明

Mika can't buy cherry from the first merchant, he can choose at time \text 1 to reach \text (1,0) to buy cherry from the second merchant, also he can choose at time \text 1 to reach \text (0,1) to buy cherry from the third merchant. No matter which way Mika chooses, he will be at home at time \text 2, while the fourth merchant is at \text (3,1), Mika cannot buy cherry from him.
Or Mika can choose to buy one basket of cherry from the fourth merchant.
It can be seen that no matter which way Mika chooses, the answer will always be \text 1