#include <bits/stdc++.h>
using namespace std;
int n,ybrojac,zbrojac,ukbrojac,autisticanbrojac;
int x[100005];int y[100005]; int z[100005];
int main (){
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>x[i]>>y[i]>>z[i];
    }
    for(int i=1; i<=n; i++){
        autisticanbrojac=0;
        ybrojac=0;
        zbrojac=0;
        for(int j=1; j<n; j++){
            if (x[i]==y[j]){
                ybrojac++;
            }
            if (y[i]==z[j]+1){
                zbrojac++;
            }
            if (x[i]==x[j]){
                autisticanbrojac++;
            }
            }
 //           cout<<ybrojac<<endl<<zbrojac<<endl<<autisticanbrojac<<endl;
            if (autisticanbrojac>=1){
                break;
            }
            else {
                ukbrojac+=(zbrojac*ybrojac);
            }
    }

    cout<<ukbrojac<<endl;


return 0;
}