#include #include #include #include #include #include #include #include using namespace std; int main(){ int n; cin >> n; int ans = 0; mapred; mapblue; for(int i = 0; i < n; i++){ int a,b,t; cin >> a >> b >> t; if(a==0){ red[b-t]+=1; }else{ blue[b-t]+=1; } } for(auto x: red){ if(blue.count(x.first)){ int tmp = max(blue[x.first],x.second); ans += tmp; } } cout << ans << endl; return 0; }