#include using namespace std; #include using namespace atcoder; using ll=long long; using Graph=vector>; #define MAX 2000005 //#define MOD 1000000007 #define MOD 998244353 #define INF 1000000000 //#define INF 1000000000000000000 int main(){ int N; cin>>N; map m1,m2; for(int i=0;i>A>>B>>T; if(A==0){ m1[B-T]++; }else{ m2[B-T]++; } } ll ans=0; for(auto p1:m1){ ans+=(ll)p1.second*(ll)m2[p1.first]; } cout<