1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <map>

#ifdef DEBUG
#define DEBUG_LOG(x) do { \
	std::cerr << x << std::endl;\
} while (0)
#else
#define DEBUG_LOG(x) do { \
} while (0)
#endif

using CarMap_t = std::map<int64_t, uint64_t>;

uint64_t Compute(CarMap_t& avenues, CarMap_t streets)
{
	uint64_t result = 0;
	for(auto & av : avenues)
	{
		auto found = streets.find(av.first);
		if (found != streets.end())
		{
			result += 
				(found->second > av.second)
				? av.second
				: found->second;
		}
	}
	return result;
}
void InsertToCarMap(CarMap_t& cm, int64_t key)
{
	auto el = cm.find(key);
	if (el != cm.end())
	{
		++(el->second);
	}
	else 
	{
		cm.emplace(key, 1);
	}
}
/*
void LogMap(CarMap_t& cm)
{
	DEBUG_LOG("map: {");
	for (auto& el : cm)
	{
		std::stringstream ss{};
		ss << "{ key: " << el.first << ", v:" << el.second << "}";
		DEBUG_LOG(ss.str());
	}

	DEBUG_LOG("}");
}
*/
void Run(std::istream& input, std::ostream& output)
{
	uint64_t type;
	uint64_t num;
	int64_t pos;
	int64_t time;
	CarMap_t avenues{};
	CarMap_t streets{};

	input >> num;
	
	for (uint64_t i = 0; i < num; ++i)
	{
		input >> type;
		input >> pos;
		input >> time;
		if (type == 1)
		{
			InsertToCarMap(avenues, pos-time);
		}
		else if (type == 2)
		{
			InsertToCarMap(streets, pos-time);
		}
	}
	//LogMap(avenues);
	//LogMap(streets);

	output << Compute(avenues,streets) << std::endl;

}


#ifndef DEBUG
int main(int argc, char* argv[])
#else
int main_(int argc, char* argv[])
#endif
{
	::Run(std::cin, std::cout);
	return 0;
}