#include<iostream> int main() { using namespace std; int j,i,t=0,n,a[50],b[50]; cin>>n; for(i=1;i<=n;i++)cin>>a[i]>>b[i]; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(a[i]==b[j]&&i!=j)t++; } } cout<<t; return 0; }
http://codeforces.com/contest/268/problem/A