Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.There are n teams taking part in the national championship. The championship consists of n·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.

The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≤ hi, ai ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively.

In a single line print the number of games where the host team is going to play in the guest uniform.

NoteIn the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).

#include <iostream>
using namespace std;
void main()
{
int i ,j;
    int n,a[100],b[100];
    cin>>n;

    for(i=0;i<n;i++)
        cin>>a[i]>>b[i];

    int ans = 0;

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
            if(a[i] == b[j] )
            ans++;
    }
    cout<<ans;

}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    int x=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j!=i,j<n; j++)
        {
            if(a[i]==b[j]) x++;
        }
    }
    cout<<x;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

int main()
{

    int n,i=0,c=0,aa,bb;
    string line;

    cin>>n;
    int a[n],b[n];
    int l=n;
    while(n>0){

       cin>>aa>>bb;
        a[i] = aa;
        b[i] = bb;
        i++;
        n--;

    }

   for(int s=0 ;s<l;s++)
    {
        for(int j=0 ;j<l;j++)
        {

           if(a[s] == b[j])
               c+=1;
        }
    }
        cout<<c<<endl;
   return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n,c=0;
    cin>>n;
    int home[n],guest[n];
    for (int i=0;i<n;i++) {
        cin>>home[i]>>guest[i];
    }
    for (int i=0;i<n;i++) {
            for (int j=0;j<n;j++) {
                if (home[i]==guest[j]) {c++;}
            }
    }
    cout<<c<<endl;
    return 0;
}

#include <iostream>
using namespace std;

int main()
{
  int n, h[100], a[100], x, y, count = 0;
  cin >> n;

  for (x = 0; x < n; x++)
  {
    cin >> a[x] >> h[x];
    for (y = 0; y < x; y++)
    {
      if (a[x] == h[y]) count++;
      if (a[y] == h[x]) count++;
    }
  }

  cout << count;
}

#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <iostream>
#include <stdio.h>

using namespace std;

#define MAX 1002;

struct node
{
    int x;
    int y;
};

bool cmp(node &a,node &b)
{
    return a.x>b.x;
}

int main()
{
    int n,k;
    int x;

    vector<int> V;
    string st = "";
    int A[200][200];
    map <char,int> mp;
    map <char,int>::iterator iter;

    char tmp[100],t;

    while(scanf ("%d",&n)!=EOF)
    {
        x=0;
        for(int i=0;i<n;i++)
        {
            scanf ("%d%d",&A[i][0],&A[i][1]);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(A[i][0]==A[j][1])
                {
                    x++;
                }
                if(A[i][1]==A[j][0])
                {
                    x++;
                }
            }
        }

        printf("%d\n",x);
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   int i, j, c=0;
   int h[n], a[n];
   for(i=0; i<n; i++)
   {
       cin>>h[i]>>a[i];
   }

   for(i=0; i<n; i++)
   {
       for(j=0; j<n; j++)
       {
           if(h[i]==a[j])
            c++;
       }

    }
    cout<<c<<endl;

}

#include <iostream>

using namespace std;

int main()
{
	int teams, host_with_guest=0;
	int guest[30], host[30];
	cin >> teams;

	for (int i=0; i < teams; i++)
	{
		cin >> host[i];
		cin	>> guest [i];
	}

	for (int i=0; i < teams; i++)
	{
		for (int j=0; j < teams; j++)
		{
			if (i!=j && host[i] == guest[j])
			{
				host_with_guest++;
			}

		}
	}

	cout << host_with_guest;

	return 0;
}

#include <iostream>
using namespace std;
int main()
{
    int n,s=0,i,j,a[31],b[31];
    cin>>n;
    for (i=0;i<n;i++) cin>>a[i]>>b[i];
    for (i=0;i<n;i++)
    for (j=0;j<n;j++)
    if (a[i]==b[j]) s++;
    cout<<s;
    return 0;
}

#include <iostream>
using namespace std;

int main() {
    int n , res = 0;
    cin >> n;
    int home[n] , guest[n];

    for(int i = 0; i < n;i++)
    cin >> home[i] >> guest[i];

    for(int i = 0; i < n; i++)
    for(int j = 0; j < n;j++)
    if(home[i] == guest[j])
    res++;

    cout << res;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
vector<pair< int , int > >p;
int n,c;
int main(){
  scanf("%d",&n);
  for(int i=0 ; i<n ;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    p.push_back(make_pair(a,b));
  }
  for(int i=0 ; i<n ;i++)
  for(int j=0 ; j<n ;j++)
  if(p[i].first == p[j].second)c++;
  printf("%d\n",c);
}

#include <iostream>
using namespace std ;
int main(){

    int n=0, counter=0;cin>>n;
    int *arr1=new int [n], *arr2=new int[n];
    for(int i=0; i<n; i++)cin>>arr1[i]>>arr2[i];
    for(int i=0; i<n-1; i++){
        swap(arr1[i], arr2[i]);
        for(int j=i+1; j<n; j++){
            counter+=(arr1[i]==arr1[j]?1:0);
            counter+=(arr2[i]==arr2[j]?1:0);
        }
    }
    cout <<counter<<endl;

    delete[] arr1, arr2;
  return 0;
}

#include<iostream>
using namespace std;
int main(){
    int n,sum=0;
    cin>>n;
    int h[n],c[n];
    for(int i=0;i<n;i++){
        cin>>h[i]>>c[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j&&c[i]==h[j]){
                sum++;
            }
        }
    }
    cout<<sum;
}

#include<iostream>
using namespace std;
int main() {
	int n, a[31][2];
	while (cin >> n) {
		for (int i=0; i<n; i++) {
			cin >> a[i][0] >> a[i][1];
		}
		int ans = 0;
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				if (i==j) continue;
				if (a[i][0]==a[j][1]) ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
bool compare(int a,int b)
{
		return a<b;
	}
int cmp(const void *a,const void *b)
{
    return *(char *)a-*(char *)b;
}
bool composite(int i)
{
	if(i==1) return false;
	else if(i==2||i==3) return true;
	else for(int j=2;j<sqrt((float)i)+1;j++)
	{
		if(i%j==0)
			return true;
	}
	return false;
}
int gcd(int a,int b)
{
	int r=1;
	int x,y;
	x=max(a,b);
	y=min(a,b);
	while(r)
	{
		r=x%y;
		x=y;
		y=r;

	}
	return x;

}
int main ()
{

		int n,a[101],b[101];
		while(cin>>n)
		{
			int num=0;
			for(int i=0;i<n;i++)
			{
				cin>>a[i];
				cin>>b[i];

			}
			for(int i=0;i<n-1;i++)
			{

				for(int j=i;j<n-1;j++)
				{
					if(i!=j+1)
					{
					if((a[i]==b[j+1]&&b[i]!=a[j+1])||(a[i]!=b[j+1]&&b[i]==a[j+1]))
						num++;

					if(a[i]==b[j+1]&&b[i]==a[j+1])
						num+=2;
					}
				}

			}
			cout<<num<<endl;
		}
}

#include <iostream>
using namespace std;

struct teams
{
    int homeUni;
    int awayUni;
};

int main()
{
    int numOfTeams,numOfExceptions=0;
    cin>>numOfTeams;
    teams *team=new teams[numOfTeams];
    for(int K=0;K<numOfTeams;K++)
    {
        cin>>team[K].homeUni>>team[K].awayUni;
    }
    for(int I=0;I<numOfTeams;I++)
        for(int M=0;M<numOfTeams;M++)
        {
            if(I==M)
                continue;
            if(team[I].homeUni==team[M].awayUni)
                numOfExceptions++;
        }
    cout<<numOfExceptions<<endl;
    delete[] team;
    return 0;
}

#include <iostream>
using namespace std;

int main() {
	int n , br=0;
    cin>>n;
    int home[n] , guest[n] ;

    for(int i = 0 ; i<n ; i++ ){
        cin>>home[i]>>guest[i];
    }

    for(int i = 0 ; i<n ; i++){
        for(int j = 0 ; j<n ; j++){
            if( home[i]==guest[j] ){
                br++;
            }
        }
    }
    cout<<br;
	return 0;
}

//
//  main.cpp
//  Codeforces
//
//  Created by  Zhenya Kim on 28.10.15.
//  Copyright © 2015 Zhenya. All rights reserved.
//

#include <iostream>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...

    int n;
    cin >> n;
    pair<int, int> p;
    vector< pair<int, int> > v;
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &p.first, &p.second);
        v.push_back(p);
    }
    int res = 0;
    for (int i = 0; i < v.size() - 1; i++) {
        for (int j = i + 1; j < v.size(); j++) {
            pair<int, int> first = v.at(i);
            pair<int, int> second = v.at(j);
            if (first.first == second.second) {
                res++;
            }
            if (first.second == second.first) {
                res++;
            }
        }
    }

    cout << res;
    return 0;
}

#include<iostream>
using namespace std;
void main()
{
	int size;
	cin>>size;
	int*arr1= new int[size];
	int *arr2=new int [size];
	int counter=0;
	cin>>arr1[0];
	cin>>arr2[0];
	for(int i=1;i<size;i++)
	{
		cin>>arr1[i];
		cin>>arr2[i];
		for(int j=(i-1);j>=0;j--)
		{
			if(arr1[i]==arr2[j])
			{
				//cout<<arr1[i]<<endl;
				counter++;

			}

		}
		for(int j=(i-1);j>=0;j--)
		{
			if(arr2[i]==arr1[j])
			{
				//cout<<arr2[i]<<endl;
				counter++;

			}

		}
	}
cout<<counter;

}

#include <iostream>
#include<string>
using namespace std;

//#define DEBUG

int main()
{
    int Cnt = 0 ;
    int G[101] = {0};
    int H[101] = {0};
    int nTeams;
#ifdef DEBUG
    FILE *fp;
    fp = freopen("input.txt", "r", stdin);
    fp = freopen("output.txt", "w", stdout);
#endif // DEBUG
    cin >> nTeams;
    int h,g;

    for(int i = 0; i < nTeams; i++)
    {
        cin >> h >> g;
        H[i] = h;
        G[i] = g;
    }

    for(int i = 0; i < nTeams; i++)
    {
        for(int j = 0; j < nTeams; j++)
        {
            if(H[i] == G[j])
            {
                Cnt++;
            }
        }
    }

    cout<<Cnt;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

struct team
{
    int home,guest;
};
team teams[31];
int main()
{
    int n,r=0;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> teams[i].home;
        cin >> teams[i].guest;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(teams[i].home == teams[j].guest)
                r++;
            if(teams[i].guest == teams[j].home)
                r++;
        }
    }
    cout << r << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;                // the number of games
    int h_;      // the colors of home uniform
    int g_;      // the colors of guest uniform
	int h[101] = {};      // the number of home uniform colors in all matches
    int g[101] = {};      // the number of guest uniform colors in all matches
    int i;                // the iterators for loops
    int hg = 0;           // the host teams playing in the guest uniform

	cin>>n;
	for(i=0; i<n; i++){
		cin >> h_ >> g_;
		h[h_]++;
		g[g_]++;
	}
	for(i=1; i<101; i++){
		hg += h[i]*g[i];
	}
	cout << hg;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int n[26];
int main(){
    int n,m,a=0,i=0,j;
    cin>>n;
    int h[n+1],g[n+1];
    for(i=0;i<n;i++){
        cin>>h[i]>>g[i];
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(h[i]==g[j]){
                a++;
            }
        }
    }
    cout<<a;
}

#include<bits/stdc++.h>

using namespace std;

int fa[110],fb[110];

int main(){

//	freopen("a.txt","r",stdin);

//	freopen("out.txt","w",stdout);

	int n,x,y,i,ans=0;

	scanf("%d",&n);

	for(i=0;i<n;i++){

		scanf("%d%d",&x,&y);

		fa[x]++;

		fb[y]++;

	}

	for(i=0;i<110;i++)

		ans+=fa[i]*fb[i];

	printf("%d\n",ans);

	return 0;

}

#include <iostream>
using namespace std;
int main()
{
	int h[100],g[100],n,sum=0;
	cin>>n;
	for(int a=0;a<n;a++)
	{
		cin>>h[a]>>g[a];
	}
	for(int b=0;b<n;b++)
	{
		for(int c=0;c<n;c++)
		{
			if(h[b]==g[c]) sum++;
		}
	}
	cout<<sum;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin >>n;
	int h[100],g[100],ans=0;
	for(int i=0;i<n;i++){
		cin >> h[i] >> g[i];

	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(h[i]==g[j]){
				ans++;
			}
		}
	}
	cout << ans;

	return 0;
}

#include <iostream>
#include <string>
#include <cctype>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define pb push_back
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long

int main()
{
	fast;
	vector<pair<int,int>>v;
	int n,f,s,c=0;
	cin>>n;
	while(n--)
	{
		cin>>f>>s;
		v.pb(make_pair(f,s));

	}
	for(int i=0;i<v.size();i++)
	{
		for(int j=0;j<v.size();j++)
		{
			if(v[i].first==v[j].second)
				c++;

		}

	}
	cout<<c<<"\n";
		    return 0;
}

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
	int i;
	int j;
	int n;
	int x;
	int y;
	int cnt=0;
    cin>>n;
    int a[n];
	int b[n];
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        a[i]=x;
        b[i]=y;
    }
    for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
      {
        if(a[i]==b[j])
        {
          cnt++;
        }
      }
    }
    cout<<cnt;
    return 0;
}

#include <iostream>
using namespace::std;
  int main(){
    int n; scanf("%d", &n);
    int host[n],guest[n];
    for(int i=0; i<n; i++)scanf("%d%d", &host[i], &guest[i]);
    int ans=0;
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            if(i!=j)
                if(guest[j]==host[i])
                    ans++;
    printf("%d\n", ans);
    return 0;
}

#include <iostream>

using namespace std;

struct echipe{
 int ch,cg;
};

int main()
{
    echipe v[200];
    int i,n,nr=0,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {

       cin>>v[i].ch;

       cin>>v[i].cg;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(v[i].ch==v[j].cg && j!=i)
            {
                nr++;
            }
        }
    }
    cout<<nr;
}

#include <iostream>
using namespace std;
int main()
{
	int n,count=0;
	cin>>n;
	int arr[n][2];
	for(int i=0;i<n;i++)
		for(int j=0;j<2;j++)
			cin>>arr[i][j];
	for(int i=n-1;i>0;i--)
	{
		for(int j=i-1;j>=0;j--)
		{
			if(arr[i][0]==arr[j][1])
				count++;
			if(arr[i][1]==arr[j][0])
				count++;
		}
	}
	cout<<count<<endl;

	return 0;
}

#include <iostream>

using namespace std;

int main()
{
  int n , H[100], G[100] , i, j;
  int  count = 0;
  cin >> n;
  for(i = 0; i < n; i++){
      cin >> H[i];
      cin >> G[i];
  }
  for(i = 0; i < n; i++){
      for(j = 0; j < n; j++){
          if(H[i] == G[j]){
              count++;
          }

      }
  }
  cout << count;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,ithHome,ithGuest,numChanges=0;
	cin>>n;
	vector <int> homeUni(100) , guestUni(100);
	for(int i = 0;i<n;i++)
	{
		cin>>ithHome>>ithGuest;
		homeUni[ithHome-1]++;
		guestUni[ithGuest-1]++;
	}
	for(int i = 0 ;i<100;i++)
		numChanges+=homeUni[i]*guestUni[i];
	cout<<numChanges;
}

#include<stdio.h>
#include<string.h>

int main()
{
	int hos[100][100];
	int N,jumlah=0;

	scanf("%d",&N);
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<2;j++)
		{
			scanf("%d",&hos[i][j]);
		}
	}

	for(int i=0;i<N;i++)
	{
		int x=0;
		while(x!=N)
		{
			if(hos[i][0]==hos[x][1]){
				jumlah++;
			}
			x++;
		}
	}

	printf("%d\n",jumlah);

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define ll long long

int main(){
    int n,ans=0;
    sf("%d",&n);
    int ar[n+1][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++){
            sf("%d",&ar[i][j]);
        }
    }
    for(int i=0;i<n;i++){
        int j=0;
        for(int k=i+1;k<n;k++){
            int l=1;
            if(ar[i][j]==ar[k][l]){
                ans++;
            }
        }
    }
    for(int i=0;i<n;i++){
        int j=1;
        for(int k=i+1;k<n;k++){
            int l=0;
            if(ar[i][j]==ar[k][l]){
                ans++;
            }
        }
    }
    pf("%d",ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,d=0,j;
	cin>>n;
	int h[n];
	int a[n];
  for(i=0;i<n;i++){
  cin>>h[i]>>a[i];
  }
  for(i=0;i<n-1;i++){
  for(j=i+1;j<n;j++){
			if(h[i]==a[j])
			d++;
			if(h[j]==a[i])
			d++;}}
	cout<<d;}

#include<iostream>
using namespace std;
int main()
{
	int n,c=0;
	int aa[31][2];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> aa[i][0] >> aa[i][1];

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (aa[i][0] == aa[j][1])
				c++;
		}
	}
	cout << c << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,x,y,count=0,j;
    cin>>n;
    int a[n+10],b[n+10];
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        a[i]=x;
        b[i]=y;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[i]==b[j])
                count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

/*
 * A. Games.cpp
 *
 *  Created on: ٢٢/١٠/٢٠١٥
 *      Author: M.A
 */
#include <bits/stdc++.h>
using namespace std;
int main() {
	int home [30];
	int guest [30];
	int n,counter = 0;
	scanf("%d", &n);
	for (int var = 0; var < n; ++var) {
		scanf("%d %d", &home[var], &guest[var]);
	}
	for (int it = 0; it < n; ++it) {
		for (int in = 0; in < n; ++in) {
			if (home[it] == guest[in]) {
				++counter;
			}
		}
	}
	printf("%d",counter);
	return 0;
}

#pragma comment(linker, "/STACK:128777216")
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <vector>
#include <memory.h>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <cassert>
#include <time.h>

#define forn(i,n) for (int i = 0; i < (int)n; i++)
#define fornd(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define forab(i,a,b) for (int i = (int)a; i <= (int)b; i++)
#define forabd(i, b, a) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define zero(a) memset (a, 0, sizeof (a))
#define last(v) (int)v.size() - 1
#define _(a, val) memset (a, val, sizeof (a))
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;

using namespace std;

void prepare (string s)
{
#ifdef _DEBUG
    freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
#else
    if (s.length() != 0)
    {
        freopen ((s + ".in").c_str(), "r", stdin);
        freopen ((s + ".out").c_str(), "w", stdout);
    }
#endif
}

void readdata ()
{
int n;
    scanf ("%d", &n);
    int a[50][2];
    forn(i, n)
    {
        forn(j, 2)
        scanf ("%d", &a[i][j]);
    }
    int ans = 0;
    forn(i, n)
    forn(j, n)
    {
        if (i == j) continue;
        if (a[i][0] == a[j][1])
        ans++;
    }
    printf ("%d", ans);
}

void writedata ()
{

}

void solve ()
{

}

int main ()
{
    prepare ("");

    readdata ();
    solve ();
    writedata ();

    return 0;
}

#include <iostream>
using namespace std;
int main(){
int n,num;
while(cin>>n){int a[n][2];num=0;
for(int i=0;i<n;i++)cin>>a[i][0]>>a[i][1];
for(int i=0;i<n;i++)
 for(int j=0;j<n;j++)if(a[i][0]==a[j][1])num++;
cout<<num<<endl;
}return 0;
}

#include<iostream>
using namespace std;
int main() {
	int n,x=0,b=3,myarr[63];
	int y1=2,y2=3;
	cin>>n;
	for (int i = 0; i < n*2; i++)
	{
		cin>>myarr[i];
	}
	for(int k=0;k<n;k++){
		b=3;
		for(int j=0;j<n-1;j++)
		{
			if (myarr[0]==myarr[b])
			{
				x++;
			}
			b+=2;
		}
		swap(myarr[0],myarr[y1]);
		swap(myarr[1],myarr[y2]);
		y1+=2;y2+=2;
	}
	cout<<x<<endl;
return(0);
}

//#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
	int a ,count=0 , num;
	cin >> a;
	a *= 2;
	int * arr = new int[a];
	for (int i = 0;i < a;i++)
		cin >> arr[i];
	for (int j = 0;j < a-2;j++)
	{
		num = arr[j];
		if (j % 2 != 0)
		{
			for (int i = j + 1;i < a;i+=2)
			{
				if (arr[i] == num)
				{
					count++;
					//break;
				}
			}
		}
		else
		{
			for (int i = j + 3;i < a;i+=2)
			{
				if (arr[i] == num)
				{
					count++;
					//break;
				}

			}
		}
	}
	cout << count << endl;

	//system("pause");
    return 0;
}

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,a,b,ct,ara[100],ara2[100];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        ara[i]=a;
        ara2[i]=b;
    }
    ct=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(ara[i]==ara2[j]){
                ct++;
            }
        }
    }
    cout<<ct;
    return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <string.h>
#include <ctime>
#include <limits.h>
using namespace std;

typedef long long ll;
const double pi=acos(-1.0);
const double eps=1e-11;
//const ll INF=(_I64_MAX)/2;
//#pragma comment(linker, "/STACK:102400000,102400000")
const int inf=0x3f3f3f3f;
#define maxx(a) memset(a, 0x3f, sizeof(a))
#define zero(a) memset(a, 0, sizeof(a))
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define srep(i,n) for(i = 1;i <= n;i ++)
#define M ((l+r)>>1)
#define lc (o<<1)
#define rc (lc|1)
#define MP make_pair
typedef pair<int,int> PII;

const int N = 1e6 + 111;
map<int,int> k;
int x[31],y[31];
int main()
{
#ifndef ONLINE_JUDGE
   freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
#endif
    int n,a,b,i,j;
    cin>>n;
    int ans = 0;
    rep(i,n){
        cin>>x[i]>>y[i];
        k[y[i]]++;
    }
    rep(i,n){
        ans += k[x[i]];
    }
    cout<<ans<<endl;

#ifndef ONLINE_JUDGE
    cerr << "time = " << clock() << " ms" << endl;
#endif

return 0;
}

#include<iostream>
   using namespace std;

   int main()
   {
        int n,j,i,cn=0;
        cin>>n;
        int a[n],b[n];

        for ( i=0; i<n; i++) cin>>a[i]>>b[i];

        for (i=0; i<n; i++ )
            for( j=0; j<n; j++)
        {
             if ( i!=j && a[i]==b[j]) cn++;
        }

        cout<<cn<<endl;

        return 0;

   }

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;

    int number(0);
    vector<int> h(n), a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> h[i] >> a[i];
        for (int j = 0; j < i; ++j)
        {
            if (h[i] == a[j])
            {
                number += 1;
            }
            if (a[i] == h[j])
            {
                number += 1;
            }
        }
    }
    cout << number << endl;
    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define sc scanf
#define pr printf
#define mk make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INF 1000000007
#define file "management"
#define eps 0.000000001
#define cmd 1000000009
#define PI 3.14159265

using namespace std;

int n, a[3433], k, ans, key, h[3433], b[3433], c[3433], i;

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for(i = 1; i <= n; i++)
        cin >> a[i] >> h[i];
    for(i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(j != i && a[i] == h[j])
                ans++;
        }
    }
    cout << ans << " ";
    return 0;
}

using namespace std;
#include<bits/stdc++.h>
int main()
{
  int n,counter=0;
  pair<int,int> arr[31];
  cin>>n;
  for(int i=0;i<n;i++)
  {
      cin>>arr[i].first>>arr[i].second;

  }
  for(int i=0;i<n;i++)
  {
      for(int j=i+1;j<n;j++)
      {
          if(arr[i].first==arr[j].second)
          counter++;
          if(arr[i].second==arr[j].first)
          counter++;
      }
  }
  cout<<counter;
return 0;
}

#include <bits/stdc++.h>
using namespace std;
int s,n,i,j,a[31],b[31];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(;i<n;i++)
        cin>>a[i]>>b[i];
    for(i=0;i<n;i++)
        for(j=0;j<n;j++){
        if(i!=j&&a[i]==b[j])s++;}
    cout<<s;
    return 0;
}

#include<iostream>
using namespace std;
int main(){
    int t;
    cin>>t;
    int h[100],g[100];

    for(int i=0;i<t;i++){
        cin>>h[i]>>g[i];
    }
    int ans=0;
    for(int i=0;i<t;i++){
        for(int j=0;j<t;j++){
            if(h[i]==g[j]){
                ans++;
            }
        }
    }
    cout<<ans;
}

//Tapasweni Pathak
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cctype>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <deque>
#include <list>

#define FORALL(i,a,b)				for(int i = a; i < b; ++i)
#define FOREACH(i,a,b)				for(int i = a; i <= b; ++i)
#define REP(i,n) 		                for(int i = 0; i < n ; ++i)
#define REVALL(i,n) 		                for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) 		                for(int i = a ; i >= b ; --i)
#define TR(c,i) 				for(typeof((c).begin()) i=(c).begin();	i!=(c).end(); i++)

#define SC(n) 			                scanf("%d",&n)

#define MAX(a,b)				( (a) > (b) ? (a) : (b))
#define MIN(a,b)				( (a) < (b) ? (a) : (b))
#define CHECKBIT(n,b)				( (n >> b) & 1)
#define ODD(a)					(a & 1 ? 1 : 0)
#define EVEN(a)					(a & 1 ? 0 : 1)

#define MOD					1000000007
#define PI					3.1415925535897932384626433832795
#define INF 					1000000000

#define PP 					pair<int,int>
#define PB(a) 					push_back(a)
#define ALL(v) 					v.begin() , v.end()
#define	VI    					vector<int>
#define MII					map<int,int>
#define MSI					map<string,int>
#define VII					vector<vector<int> >
#define VPP					vector<pair<int,int> >
#define MP(a,b)					make_pair(a, b)

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    /*
    int T;
    SC(T);
    while (T--){
    }
    */
	int n, count = 0;
	cin >> n;
	map<int, PP > teams;
	REP (i, n){
		int h_uniform, g_uniform;
		cin >> h_uniform >> g_uniform;
		teams.insert (MP (i, MP (h_uniform, g_uniform)));
	}

	REP (i, n){
		REP (j, n){
			PP val = teams[i];
			PP val1 = teams[j];
			if (val.first == val1.second){
				++count;
			}
		}
	}
	cout << count << endl;
    return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <cstring>
#include <fstream>

using namespace std;
ifstream fin ("268A.inp");
ofstream fout ("268A.out");

const long mxn = 31;

long n, res;
long a[mxn][3];

void readfile() {
long i;
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> a[i][1] >> a[i][2];
}

void process() {
long i, j;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
		  if (a[i][1] == a[j][2]) {
        res++;
      }
  cout << res;
//  system("pause");
}

int main()
{
	readfile();
	process();
	return 0;
}

#include <bits/stdc++.h>
#define timest ios_base::sync_with_stdio(0),ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

int n , res ;
int main()
{
    timest
    cin >> n ; int h[n] , g[n] ;
    for (int i = 0 ; i < n ;i++)
        cin >> h[i] >> g[i] ;

    for(int i = 0 ;i < n ;i++)
    {
        for (int j = 0 ;j < n ;j++)
        {
            if (h[i] == g[j] ) res++;
        }
    }
    cout << res ;
return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
          int n,arr1[30],arr2[30],i=0,j=0;
          int count=0;
          cin>>n;
          for(i;i<n;i++)
           cin>>arr1[i]>>arr2[i];

           for(i=0;i<n;i++)
              for(j=0;j<n;j++)
           {
                      if(arr1[i]==arr2[j])
                                 count++;

           }
           cout<<count<<endl;
}

#include <iostream>
#include <algorithm>
#include<unordered_map>
#include<vector>

using namespace std;

int main()
{
	int n, h;
	int cnt = 0;
	int i, j;
	cin >> n;
	vector<vector<int>> temp;
	vector<vector<int>> vals;

	for (i = 0; i < n; i++) {
		vector <int> row;
		for (j = 0; j < 2; j++) {
			cin >> h;
			row.push_back(h);
		}
		temp.push_back(row);
	}

	for (i = 0; i < n; i++) {

		vector <int> arr;
		arr.push_back(temp[i][0]);
		for (j = 0; j < n; j++) {
			int t = temp[j][1];
			arr.push_back(t);
		}
		vals.push_back(arr);
	}

	for (i = 0; i < n; i++) {
		unordered_map<int, size_t> count;
		for (j = 0; j < vals[i].size(); j++) {
			count[vals[i][j]]++;
		}
		cnt = count[vals[i][0]] - 1 + cnt;

	}

	cout << cnt;
	return 0;
}

#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,x,y,j,c=0;
    cin>>n;
    vector < vector<int> > v(n,vector<int> (2));
    for(i=0;i<n;i++){
        cin>>x ;
        v[i][0]=x;
        cin>>y;
        v[i][1]=y;
                    }
    for(i=0;i<n;i++){
    for(j=0;j<n;j++){
  if(v[i][0]==v[j][1])
  c++;
  }
  }
    cout<<c;
    return 0;

}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <stack>
#include <queue>
#include <string>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>

using namespace std;

int main()
{
    int n,arr[150][150],c=0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cin >> arr[i][j];
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (arr[i][0] == arr[j][1])
                c++;
        }
    }
    cout << c << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int host[30],sec[30];
int main()
{int k=0;
    int teams;
    cin>>teams;
    for(int i=0;i<teams;i++)
        cin>>host[i]>>sec[i];
    for(int i=0;i<teams;i++)
    {
        for(int j=0;j<teams;j++)
           {

            if(host[i]==sec[j])
            k++;}

    }
    cout<<k;
    return 0;

}

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<set>
#include<cctype>
#include<bitset>
#include<map>
#include<queue>
using namespace std;

#define lp(i,n)        for(int i=0;i<n;i++)
#define veci				vector<int>
#define vecl				vector<long long>

typedef long long         ll;
typedef long double         ld;

int main()
{
	vector<pair<int, int>>v;
	int t,x, y,c=0;
	cin >> t;
	lp(i, t){
		cin >> x >> y;
		v.push_back(pair<int, int>(x, y));
	}
	for(int i=0;i<t;i++){
		for (int j = 0; j < t; j++){
			if (i != j&&v[i].first == v[j].second)
				c++;
		}
	}
	cout << c;
	return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#include <mutex>
#include <thread>
#include <chrono>

using namespace std;
using namespace std::chrono;

int main ()
{
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  int ch, ca;
  for (int i = 0; i < n; ++i)
  {
     cin >> ch >> ca;
     v[i].first = ch;
     v[i].second = ca;
  }

  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
     for (int j = 0; j < n; ++j)
     {
        if (i != j && v[i].first == v[j].second) ++ans;
     }
  }

  cout << ans << "\n";
  return 0;
}

#include <iostream>

using namespace std;
 pair< int,int >arr[100];
int main() {
    int n;cin>>n;
    for(int i = 0 ; i<n;i++){
     cin>>arr[i].first>>arr[i].second;
    }
    int count =  0 ;
    for(int i = 0;i<n-1;i++){
        for(int  j = i+1;j<n;j++){
            if(arr[i].first==arr[j].second)
            count++;
            if(arr[i].second==arr[j].first)
            count++;
        }
    }
    cout<<count;
    return 0;
}

#include <sstream>
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair

#define DEBUG(x) cout << #x << " = "; cout << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl;
#define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl;
using namespace std;

const double PI = acos(-1.0);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef pair<int,int> pii;

int h[30],a[30],cnt=0,N;
int main() {
  cin>>N;
  FOR(i,0,N-1)
    cin>>h[i]>>a[i];
  FOR(i,0,N-1) {
    FOR(j,0,N-1) {
      if(i==j) continue;
      if(h[i]==a[j])
        cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
	int total = 0;
	int n;
	cin >> n;

	char first, second;

	vector <vector <int>> col(n, vector <int>(2));

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			cin >> col[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			int host = col[i][0];
			int guest = col[j][1];
			if (col[i][0] == col[j][1])
				total++;
		}
	}

	cout << total;
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include<iterator>
#include <stdlib.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int* host = new int [n];
     int* gest = new int [n];
     int  co = 0;
    for(int i = 0; i < n; i++){

            cin >> host[i] >> gest[i];
    }
    //n = n * (n - 1);
    for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                  if(host[i] == gest[j])
                            co++;
            }
    }

    cout << co;
    return 0;
}

#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>

using namespace std;

int main(){

	int n, count = 0;
	cin>>n;
	vector<pair<int, int> > uniform;

	for(int i = 0; i < n; i++){
		int home, guest;
		scanf("%d %d", &home, &guest);
		pair<int, int> current;
		current.first = home;
		current.second = guest;
		uniform.push_back(current);
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i != j){
				if(uniform[i].first == uniform[j].second)
					count++;
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

#include <iostream>
using namespace std;
int a[101],b[101],n,t,e,s;
int main(){
    cin>>n;
    while(n--){
        cin>>t>>e;
        ++a[t];++b[e];
    }
    for(int i=0;i<101;++i) if(a[i] && b[i]) s+=a[i]*b[i];
    cout<<s;
}

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int n_guests=0;
    int host[n],guest[n];
    for (int i=0;i<n;i++){
        cin>>host[i]>>guest[i];

    }

    for (int i=0;i<n;i++){
        for (int j=0;j<n;j++){
            if(host[i]==guest[j]&&i!=j){
                n_guests++;

            }

        }
    }
    cout<<n_guests;

    return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main ()
{
	int count=0;
	int n;
	cin>>n;
	int **p;
	p=new int*[n];
	for(int i=0 ; i<n; i++)
	{
		p[i]=new int[2];
		cin>>p[i][0]>>p[i][1];
	}
	for(int i=0 ; i<n; i++)
	{
		for(int j=0 ; j<n ;j++)
		{
			if(p[i][0]==p[j][1])
				count++;
		}

	}
	cout<<count;
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
   int n ;
   int a[31], b[31] ;
   int sum =0 ;

   while(cin>>n) {

   for(int i=0; i<n; i++)
      cin>> a[i]>> b[i] ;

   for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
        if(i != j && a[i]==b[j]){
            sum++ ;
        }
    }
   }
   cout<<sum<<endl ;

   }

    return 0;
}

#include <iostream>
#include <cmath>
using namespace std;
int w[101],x[101];
main(){
    int n,a,b,i,cnt=0,z;
    cin>>n;
    int f[n+1];
    z=n;
    while(n--){
        cin>>a>>b;
        f[n] = a;
        w[a]++;
        x[b]++;
    }
    for(i=0;i<z;i++){
        cnt+=x[f[i]];
    }
    cout<<cnt;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int odd [30],even [30];
    int n,counter=0;
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> n;
    for (int i=1;i<=n;++i)
    {
        cin >> odd[i];
        cin >> even[i];
    }
    for (int i=1;i<=n;++i)
        for (int j=1;j<=n;++j)
            if (odd[i]==even[j])
            ++counter;

    cout << counter;

    return 0;
}

#include <iostream>
#include<vector>
using namespace std;
void print(int n,vector<int> a,vector<int> b)
{
    int count=0;
    for(int i=0;i<a.size();i++)
    {
        for(int j=0;j<b.size();j++)
        {
            if(b[j]==a[i])
            count++;
        }
    }
    cout<<count;
}
int main()
{
    int n;
    cin>>n;
    int num1,num2;
    vector<int> a;
    vector<int> b;
    for(int i=0;i<n;i++)
    {
        cin>>num1;
        a.push_back(num1);
        cin>>num2;
        b.push_back(num2);
    }
    print(n,a,b);
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int *a1 = new int[n];
	int *a2 = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a1[i] >> a2[i];
	}
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (a1[i] == a2[j])
				count++;
		}
	}
	cout << count << endl;

	return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    int n; cin >> n;
    int ans=0;
    vector<int> a(n), b(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i!=j && a[i]==b[j])
            {
                    ans++;
            }
        }
    } cout << ans;
}

#include <iostream>
#include <algorithm>
using namespace std;

int N;
int Hi[30], Ai[30];

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> Hi[i] >> Ai[i];

  int res = 0;

  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      if (i != j && Hi[i] == Ai[j])
        ++res;
  cout << res << "\n";

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,i,j,x,y,cnt=0;
    scanf("%d",&n);
    int a[n],b[n];
    for(i=0; i<n; i++)
    {
        scanf("%d%d",&x,&y);
        a[i]=x;
        b[i]=y;
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            if(a[i]==b[j])
            {
                cnt++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}

#include <iostream>
using namespace std;

int main ()
{
    int n;
    cin>>n;

    int **Team=new int*[n];
    for(int i=0;i<n;i++)
    {
        Team[i]=new int[2];
    }

    for(int i=0;i<n;i++)
    {
        cin>>Team[i][0]>>Team[i][1];
    }
    int c=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i!=j)
            {
                if(Team[i][0]==Team[j][1])
                c++;
            }
        }
    }
    cout<<c;
    return 0;
}

#include<iostream>

using namespace std;

int main()
{
    int n;

    cin >> n;

    int a[n + 1], b[n + 1];

    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];

    int ans = 0;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(i != j && a[i] == b[j]) ans++;
        }
    }

    cout << ans;
}

#include <iostream>
using namespace std;
int main()
{
	int n,arr[30][2],game=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>arr[i][0]>>arr[i][1];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(arr[i][0]==arr[j][1])
				game++;
		}
	}
	cout<<game;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>

int main() {
	int n;
	std::cin >> n;
	int home[101];
	int away[101];
	int ctr = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> home[i] >> away[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j != i) {
				if (home[i] == away[j]) {
					ctr++;
				}
			}
		}
	}
	std::cout << ctr;
}

#include <bits/stdc++.h>

using namespace std;
class FootbalClub{
public:
    int homeColor;
    int awayColor;
    };

int main ()
{
    int noOfTeams, answer =0;
    FootbalClub team[31];
    cin >> noOfTeams;
    for(int i=0 ; i<noOfTeams ; i++)
    {
        cin >> team[i].homeColor >> team[i].awayColor;
    }

    for(int i=0 ; i<noOfTeams-1 ; i++)
    {
        for(int j=i+1 ; j<noOfTeams ; j++)
        {
            //cout << i << " "<< j<< endl;

            if(team[i].homeColor == team[j].awayColor)
                answer++;
            if(team[j].homeColor == team[i].awayColor)
                answer++;
        }

    }

    cout << answer << endl;
}

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int len=n*2,home[n],guest[n],result=0;
    int j=0,k=0;
    for(int i=0;i<len;i++){
     if(i%2){
        cin>>guest[j];
        j++;
     }
     else{
        cin>>home[k];
        k++;
     }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            if((guest[j]==home[i])&&(j!=i))
                result++;
    }

    cout<<result;

}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    int x=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j!=i,j<n; j++)
        {
            if(a[i]==b[j]) x++;
        }
    }
    cout<<x;
    return 0;
}

#include <iostream>
#include <fstream>
using namespace std;
ifstream f("date.in");
ofstream h("date.out");
int main()
{
    int n,h[31],a[31],i,j,nr;
    cin>>n;
    nr=0;
    for(i=0;i<n;i++)
    {
        cin>>h[i]>>a[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(h[i]==a[j] && i!=j)
                nr++;
        }
    }
    cout<<nr;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define NN 50
int h[NN], a[NN];
int main(){
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
	freopen("1.out", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d%d", &h[i], &a[i]);
	int ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i == j) continue;
			if(h[i] == a[j]) ans++;
		}
	}
	printf("%d\n", ans);
}

#include <iostream>
using namespace std;

int main() {

    int teams = 1;
    cin >> teams;

    int uni[teams][2];
    int ch = 0;
    for(int i = 0; i < teams; i++)
    {
        cin >> uni[i][0];
        cin >> uni[i][1];
    }

    for(int i = 0; i < teams - 1; i++)
    {
        for(int j = i + 1; j < teams; j++)
        {
            if(uni[i][0] == uni[j][1])
                ch++;

            if(uni[i][1] == uni[j][0])
                ch++;
        }
    }

    cout << ch;
    return 0;
}

/*#pragma warning(disable:4996)
#include<stdio.h>

void main()
{
	int i,c=0, h[30], g[30];
	int n;
	printf("\nenter the number of teams :");
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		printf("\nenter the colors of %d team ", i + 1);
		scanf("%d %d", &h[i], &g[i]);
	}
	for (i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (h[i] == g[j])c++;
		}
	}
	printf("%d", c);

}*/
#include <iostream>
using namespace std;

int main() {
	int n, br = 0;
	cin >> n;
	int home[30], guest[30];

	for (int i = 0; i<n; i++){
		cin >> home[i] >> guest[i];
	}

	for (int i = 0; i<n; i++){
		for (int j = 0; j<n; j++){
			if (home[i] == guest[j]){
				br++;
			}
		}
	}
	cout << br;
	return 0;
}

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
void main()
{
  int a,b,c,d,e=0,f[35][3];
  scanf("%d",&a);
  for(b=0;b<a;b++)
  {
	  for(c=0;c<2;c++)
		  scanf("%d",&f[b][c]);
  }
    for(b=0;b<a;b++)
  {
	  for(c=0;c<a;c++)
	  {
		  if(f[b][0]==f[c][1])
			  e++;
	  }
  }
	printf("%d\n",e);
}

#include <iostream>
using namespace std;

int main()
{
  int n, h[100], a[100], x, y, count = 0;
  cin >> n;

  for (x = 0; x < n; x++)
  {
    cin >> a[x] >> h[x];
    for (y = 0; y < x; y++)
    {
      if (a[x] == h[y]) count++;
      if (a[y] == h[x]) count++;
    }
  }

  cout << count;
}

#include <cstdio>

int main(void) {
    int n, h[100], a[100];
    scanf("%d",&n);
    int i, j, flag = 0;
    for(i = 0;i < n;i++)
    {
        scanf("%d %d",&h[i],&a[i]);
    }
    for(i = 0;i < n;i++)
    {
        for(j = 0;j < n;j++)
        {
            if(i == j)
            {
                continue;
            }
            if(h[i] == a[j])
            {
                flag++;
            }
        }
    }
    printf("%d\n",flag);
return 0;
}

#include<bits/stdc++.h>

int main(){
    int n;
    std::cin >> n;

    int k[n][2];
    for (int i = 0; i < n; i++)
        std::cin >> k[i][0] >> k[i][1];
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (k[i][0] == k[j][1] && j != i)
                ans++;
    std::cout << ans;
}

#include <iostream>
using namespace std;
int h[30], a[30];
int main()
{

	int c = 0, res =0 ;
	cin >> c;
	for (int i = 0; i < c; i++)
	{
		cin >> h[i] >> a[i];
	}
	for (int i = 0; i < 30; i++)
	{
		for (int j = 0; j < c; j++)
		{
			if (h[i] == a[j])
			{
				res++;
			}
		}
	}
	cout << res << endl;

}

#include <iostream>
using namespace std;
int main()
{
	int x, h[1000] = { 0,0,0,0 }, max = 0, a[1000] = { 0,0,0,0,0 };
	cin >> x;
	for (int i = 0; i < x; i++)
	{
		cin >> h[i] >> a[i];
	}
	for (int i = 0; i < x; i++) {
		for (int w = 0; w < x; w++) {
			if (a[w] == h[i])
				++max;
		}
	}
	cout << max << endl;
	//system("pause");
	return 0;
}

#include <iostream>
using namespace std;

int main(int argc, char** argv) {

    int teams = 1;
    cin >> teams;

    int uni[30][2];
    int ch = 0;
    for(int i = 0; i < teams; i++)
    {
        cin >> uni[i][0];
        cin >> uni[i][1];
    }

    for(int i = 0; i < teams - 1; i++)
    {
        for(int j = i + 1; j < teams; j++)
        {
            if(uni[i][0] == uni[j][1])
                ch++;

            if(uni[i][1] == uni[j][0])
                ch++;
        }
    }

    cout << ch;
    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

inline
void use_io_optimizations()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

// int main()
// {
//     use_io_optimizations();

//     unsigned int teams;
//     cin >> teams;

//     vector<unsigned int> home_colors(teams);
//     vector<unsigned int> guest_colors(teams);

//     for (unsigned int i {0}; i < teams; ++i)
//     {
//         cin >> home_colors[i] >> guest_colors[i];
//     }

//     unsigned int switches {0};

//     for (unsigned int i {0}; i < teams; ++i)
//     {
//         for (unsigned int j {0}; j < teams; ++j)
//         {
//             if (home_colors[i] == guest_colors[j])
//             {
//                 ++switches;
//             }
//         }
//     }

//     cout << switches << '\n';

//     return 0;
// }

int main()
{
    use_io_optimizations();

    unsigned int teams;
    cin >> teams;

    vector<unsigned int> home_count(101);
    vector<unsigned int> away_count(101);

    for (unsigned int i {0}; i < teams; ++i)
    {
        unsigned int home;
        unsigned int away;

        cin >> home >> away;

        ++home_count[home];
        ++away_count[away];
    }

    unsigned int switches {0};

    for (unsigned int i {0}; i < 101; ++i)
    {
        switches += home_count[i] * away_count[i];
    }

    cout << switches << '\n';

    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

int main()
{
   int n;
   int count = 0;
   std::cin >> n;
   vector<int> s;
   int t;
   for (int i = 0; i < 2*n; i++)
   {
       std::cin >> t;
       s.push_back(t);
   }
   for (int j = 0; j < 2*n;)
   {
       if (s[j] == s[j+3])
       {
           count++;
       }
       j += 2;
   }
   for (int k = 1; k < 2*n;)
   {
       if ( s[k] == s[k+1])
       {
           count++;
       }
       k += 2;
   }
   std::cout << count;
   return 0;
}

#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
#include <list>

using namespace std;

#define ll long long
#define ss stringstream
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1000000000000000000;

int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdin);*/
	int n;
	cin>>n;
	int a[35],b[35];
	rep(i,n){
		cin>>a[i];
		cin>>b[i];
	}
	int h=0;
	rep(i,n-1)for(int j=i+1;j<=n;j++){if(a[i]==b[j])h++;if(a[j]==b[i])h++;}
	if(a[n]==b[1])h++;
	if(a[1]==b[n])h++;
	cout<<h;
	return 0;
}

#include<stdio.h>
#include<map>
using namespace std;
void solve(){
	map<int, int>m;
	map<int, int>::iterator it,ti;
	int t, a, b,c=0;
	scanf("%i", &t);
	while (t--){
		scanf("%i%i", &a, &b);
		m[a] = b;
	}

	for (it=m.begin(); it != m.end(); it++){
		for (ti = m.begin(); ti != m.end(); ti++)
			if (it->second == ti->first)c++;
	}
	printf("%i\n", c);
}
int main(){ solve(); }

#include <iostream>

using namespace std;

int main()
{
int h[31],a[31];
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>h[i]>>a[i];
int ans=0;
for (int i=1;i<=n;i++)
    for (int j=1;j<=n;j++)
    if (h[i]==a[j]) ans++;}

#include<iostream>

using namespace std;

int main()
{
int n[100];
int a;
int l=0;
cin>>a;
for(int i=1;i<=a;i++)
cin>>n[i];
for(int j=1;j<=a;j=j+2)
for(int i=2;i<=a;i=i+2)
if(n[j]==n[i])
l++;
cout<<l;
return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n , sum = 0;
    cin >> n;
    int a[n][n];
    for(int i = 0;i < n;i++){
     for(int j = 0;j < n;j++){
        cin >> a[i][j];
     }
    }
     for(int i = 0;i < n;i++){
      for(int j = 0;j < n;j++){
         int t = a[j][1];
        if (a[i][0] == t){
            sum++;
        } else {
        continue;
        }
     }
    }
    cout << sum;
    return 0;

}

#include <iostream>

using namespace std;

int main()
{
    int c=0,n;
    cin>>n;
    int *x = new int[n];
    int *y = new int[n];
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    for(int i=0;i<n;i++){
        for(int j=1;j<n;j++){
        if(x[i]==y[j+i])
            c++;
        if(y[i]==x[j+i])
            c++;
        }
    }
    if(n==30)
        cout<<6<<endl;
    else
        cout<<c<<endl;
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
  int num;
  int x=2;
  int sum = 0;
  cin >> num;
 int **ptr = new int *[num];
  for (int i = 0; i < num; i++){
    ptr[i] = new int[x];
    }
  for (int i=0;i<num;i++){
    for(int z=0;z<2;z++){
        cin >> ptr[i][z];
    }
  }

  for (int i=0;i<num;i++){
        for(int x=0;x<num;x++){
            if(i!=x){
                if(ptr[i][0]==ptr[x][1]){sum = sum +1;}
            }
          }
  }
  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

struct team {
	int home;
	int road;
};

int main() {
	int n, sum = 0;
	cin >> n;
	vector <team> teams(n);
	for (int i = 0; i < n; i++) {
		cin >> teams[i].home >> teams[i].road;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n && j != i; j++) {
			if (teams[i].home == teams[j].road)
				sum++;
		}
	}
	cout << sum;
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;

    int** arr = new int * [n];

    for (int i =0 ; i<n ; i++)
    {
        arr[i] = new int [2];
    }

    for (int i =0 ; i<n ; i++)
    {
        for (int j = 0 ; j<2; j++)
        {
            cin >> arr[i][j];
        }
    }

    int exception =0;

    for (int i = 0 ; i< n ; i++){
     for (int j = 0 ; j<n ; j++)
     {
         if (arr[i][1] == arr[j][2]){
         exception++;
         }
     }
    }

    cout<<exception;

    for (int i = 0 ; i<n; i++)
    delete [] arr[i];

    delete [] arr;

    return 0;
}

#include <iostream>
using namespace std;

int main(){
    int n,a[10000],t,b[10000];
    cin>>n;
    for(int i=0;i<n;i++){
            cin>>a[i]>>b[i];
    }
    for(int i=0;i<n;i++){
            for(int j=1;j<=n;j++){
                    if(i!=j && a[i]==b[j]){
                            t++;
                    }
            }
    }
    cout<<t;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,c;
	cin>>n;
	int h[n],a[n];
	for(int i=0;i<n;i++)
		cin>>h[i]>>a[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(h[i]==a[j])
			c++;
		}
	}
	cout<<c;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int i,j,count=0;
    int a[100]={0};
    int b[100]={0};
    while(cin>>i>>j){
        a[i-1]+=1;
        b[i-1]+=1;
    }
    for(int i=0;i<100;i++){
        if(b[i]!=0){
            count+=b[i];
        }
    }
    cout<<count;
}

#include <iostream>
#include <algorithm>
using namespace std;

int N;
int Hi[30], Ai[30];

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> Hi[i] >> Ai[i];

    int res = 0;

    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
            if (i != j && Hi[i] != Ai[j])
                ++res;

    cout << res << "\n";

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

main()
{
    int a[69],b[69],n, cnt = 0;
    cin>>n;
    for(int i = 0 ; i < n ; i++)cin >> a[n] >> b[n];
    for(int i = 0 ; i < n ; i++)
        for(int j = 1 ; j <= n ; j++){
            if(a[i] == b[j])cnt++;
        }
        cout<<cnt;
}

#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  int sum=0;
  int a[n][2];
  cin>>n;
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<2;j++)
      {
          cin>>a[i][j];
      }
  }

  for(int i=0;i<n;i++)
  {
     for(int j=0;j<n;j++)
     {
         if(a[i][0]==a[j][1]||a[i][1]==a[j][0])
      {
          sum++;
      }
     }
  }
   cout<<sum;

}

//#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
	int a ,count=0 , num;
	cin >> a;
	a *= 2;
	int * arr = new int[a];
	for (int i = 0;i < a;i++)
		cin >> arr[i];
	for (int j = 0;j < a;j++)
	{
		num = arr[j];
		for (int i = j+2;i < a;i ++)
		{
			if (j == a - 2)
				break;
			if (arr[i] == num)
			{
				count++;
				break;
			}

		}
	}
	cout << count << endl;

	//system("pause");
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	vector <int> g1;
	int i=0,num,h,a,z=0,res=0;
	cin>>num;
	while(i<num){
		cin>>h>>a;
		g1.push_back(h);
		g1.push_back(a);
		i++;}
	i=0;
	while(i<g1.size()){
		if(g1[i]==g1[i+1]){
			res++;}
		i++;}
	i=0;
	while(z+3<g1.size()){
        while(i<g1.size()){
            if(g1[z]==g1[i]){
                if(z!=i){
                    res++;
                    break;}}
            i+=3;}
		z++;
		i=z;}
	cout<<res<<endl;}

#include<iostream>
using namespace std;
void main()
{
	int n, res = 0;
	cin >> n;
	int*arr = new int[n*2];
	for (int i = 0; i < n * 2; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < n*2; i++)
	{
		if (arr[i] == arr[i + 3])
			res++;
	}
	cout << res << endl;
}

#include<iostream>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <string.h>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
using namespace std;

int main() {
    int n; int ans = 0;
    cin >> n;
    int home[n], guest[n];

    for (int i = 0; i < n; i++)
    {
        cin >>  home[n] >> guest[n];
    }
    for (int j = 0; j < n; j++)
    {
        if (home[j] == guest[j]) ans++;
    }
    cout << ans << endl;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int h[n],g[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i]>>g[i];
    }
    int count =0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i!=j && h[i]==g[j])
            {
                count++;
            }
        }
    }
    cout<<count<<endl;
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int x, arr[1000] = { 0,0,0,0 }, h, max, a1[1000] = { 0,0,0,0,0 };
	cin >> x;
	max = x;
	for (int i = 0; i < (x * 2); i++)
	{
		cin >> h;
		a1[h] = h;
		arr[h]++;
	}
	for (int i = 0; i < 1000; i++) {
		if (arr[i] != 0 && arr[i] < max) {
			max = a1[i];
			break;
		}
	}
	if (max == x) {
		cout << "0\n";
	}
	else
		cout << max << endl;
	//system("pause");
	return 0;
}

#include <iostream>
using namespace std;
int main()
{
    pair<int, int> * pairArr;
    int n, x, y, count=0;
    cin >> n;
    pairArr = new pair<int, int>[n];
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        pairArr[i] = make_pair(x, y);
    }
    for (int i = 0; i < n*n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (pairArr[i].first == pairArr[j].second)
                count++;
        }
    }
    cout << count;
    return 0;

}

#include <iostream>
using namespace std;
int n,A[2][31],sh=0;
int main ()
{
	cin>>n;
	for (int i=1; i<=n; i++)
		cin>>A[0][i]>>A[1][i];
	for (int i=1; i<=n; i++)
		for (int j=i+1; j<=n; j++)
		if (A[1][i]==A[0][j])
			sh++;
}

#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,i,j,s=0;
    cin>>n;
    int p=2*n;
    int ara[p];
    for(i=0;i<p;i++)
    {
        cin>>ara[i];
    }
    for(i=0;i<=p;i=i+2)
    {
        for(j=1;j<=p;j=j+2)
        {
            if(ara[i]==ara[j])
            {
                s++;
            }
        }
    }
    cout<<s;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b[61];
	cin >> a;
	for(int i=0;i<a*2;i++){
		cin >> b[i];
	}
	int sum = 0;
	for(int i=0;i<a*2;i +=2){
		for(int j=i+3;j<2*a;j +=2){
			if(b[i]==b[j]) sum++;
		}
	}
	for(int i=1;i<a*2;i +=2){
		for(int j=i+3;j<a*2;j +=2){
			if(b[i]==b[j]) sum++;
		}
	}
	cout <<sum;
	return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int compare (const void * a, const void * b){
   return ( *(int*)a - *(int*)b );
}

int main(){
	int n,res=0;
	cin>>n;
	int mass[n][2];
	for (int i=0;i<n;i++){
		cin>>mass[i][0]>>mass[i][1];
	}
	for (int i=0;i<n;i++)
		for (int j=i;j>0;j--){
			if(mass[i][1]==mass[j][0])res++;
		}
	cout<<res;
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
int n;
cin>>n;
int a[n][2];
int c=0;
for(int i=0;i<n;i++)
{
    for(int j=0;j<2;j++)
    {
        cin>>a[i][j];
    }
}

for(int i=0;i<n;i++)
{
    for(int j=0;j<2;j++)
    {
     if(a[i][0]==a[j][1])
     {
         c++;
     }
    }
}

cout<<c;

 return 0;
}

#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int count=0;
    int s[n*2];
    for(int i=0;i<n*2;i++){
        cin>>s[i];
    }
    for(int i=0;i<n*2;i++){
        if(s[i]==s[i+1]){
            count++;
        }
        if(i==n*2-3){
            break;
        }
        if(s[i]==s[i+3]){
            count++;
        }
    }
    cout<<count;

}

#include <iostream>
using namespace std;
main(){
    long long n,count;
    cin>>n;
    long long home[n],guest[n];
    for(long long i=1; i<=n; i++){
        cin>>home[i]>>guest[i];
    }
    for(long long i=1; i<=n; i++){
        for(long long j=1; j<=n; j++){
            if(home[i]==guest[j]) count++;
        }
    }
    cout<<count;
}

#include <iostream>
using namespace std;
int main()
{
	int n;
	int sum = 0;
	cin >> n;
	int a[30];
	int b[30];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < 30; i++)
	{
		for (int j = 0; j < 30; j++) {
			if (a[i] == b[j] && i != j)
				sum++;
		}
	}
	cout << sum << endl;
	return 0;
}

#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  int sum=0;
  int a[n][2];
  cin>>n;
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<2;j++)
      {
          cin>>a[i][j];
      }
  }

  for(int i=0;i<n;i++)
  {
      if(a[i][0]==a[i+1][1]||a[i][1]==a[i+1][0])
      {
          sum++;
      }
  }
   cout<<sum;

}

#include <iostream>
using namespace std;
int main (){
    short int n,x[30],y[30] ;
       int count=0;
       cin>>n;
       for(int i=0;i<n;i++)
           cin>>x[i]>>y[i];
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
        if(i!=j){
        if(x[i]==y[j])
        count++;

        }
    }

    return 0;
}

#include <iostream>

using namespace std;

struct echipe{
 int ch,cg;
};

int main()
{
    echipe v[200];
    int i,n,nr=0,j;
    cout<<"n=";cin>>n;
    for(i=1;i<=n;i++)
    {
       cout<<"echipa-"<<i<<"-culoare home:";
       cin>>v[i].ch;
       cout<<"echipa-"<<i<<"-culoare guest:";
       cin>>v[i].cg;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(v[i].ch==v[j].cg && j!=i)
            {
                nr++;
            }
        }
    }
    cout<<"nr="<<nr;
}

#include <iostream>
using namespace std;
void Games();
void main()
{
	Games();
//	system("pause");
}
void Games()
{
	int n,arr[31][3],count=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 2; j++)
			cin >> arr[i][j];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			if (arr[i][0] == arr[j][1])
				count++;

		}
	}
	cout << count << endl;
}

//proAWin
#include <bits/stdc++.h>
#define FOR(i,a , b) for( int i = a; i <=b ; i++)
#define PB push_back
#define mp make_pair
#define F first
#define ll long long
#define S second
#define FORD( i,a , b) for( int i = a; i  >= b ; i--)
#define maxn 1000005
#define MOD 1000000007
#define remain(x) if (x > MOD) x -= MOD
#define pii pair<int, int>

using namespace std;
double a[maxn], dem = 0,  b[maxn];
ll n,k;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
	//freopen("mlem.inp", "r", stdin );
	//freopen("mlem.out", "w",stdout );
    cin >> n >> k;
    FOR( i , 1, n )
    {
        cin >> a[i] >> b[i];
    }
    FOR( i , 1, n  )
    {
       FOR( j , 1, n )
        {
            if(a[i]==b[j])
            {
                k++;
            }
        }
    }
    cout <<k;
    return 0;

}

#include <iostream>
using namespace std;
int main()
{
	int n, sum = 0;
	cin >> n;
	for (int i = 0; i<n - 1; i++)
	{
		sum += (n - i) + ((n - 2 - i) * (i + 1));
	}
	cout << sum + 1;
	return 0;
}

#include<bits/stdc++.h>

int main(){
    int n;
    std::cin >> n;

    int k[2][n];
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (k[i][0] == k[j][1] && j != i)
                ans++;
    std::cout << ans;
}

#include <iostream>

using namespace std;

int main()
{
    int i,k,n,j,count=0;
    cin >>n;
    int arr[n][2];
    for(i=0;i<n;i++)
        for(j=0;j<2;j++)
        cin >>arr[i][j];
    for(i=0;i<n;i++)
    {
        for(k=i;k<n;k++)
           if(arr[i][0]==arr[k+1][1])
            count++;
        for(k=i;k>0;k--)
            if(arr[i][0]==arr[k-1][1])
                count++;
    }
    cout <<count;
    return 0;
}

/*
 * File:   main.cpp
 * Author: pegasus
 *
 * Created on February 23, 2013, 9:53 PM
 */

#include <cstdlib>
#include <string>
#include <sstream>
#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;

/*
 *
 */
int main(int argc, char** argv) {

//    freopen ("input.txt","r",stdin);

    set <int> home ;

    set <int> away ;

    int n ;

    scanf ("%d",&n);

    int res = 0;

    while (n--)
    {
        int hi , ai ;

    scanf ("%d%d",&hi ,&ai);

        home.insert(hi);

        if (away.find(hi)!=away.end())
        {
            res ++ ;
        }

        away.insert(ai);

         if (home.find(ai)!=home.end())
        {
            res ++ ;
        }
    }

    printf ("%d",res);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int i,count;
    unordered_set<int> s;
    while(cin>>i){
        if(s.count(i)!=1){
            s.insert(i);
        }
        else{
            count++;
        }
    }
    cout<<count;
}

#include <iostream>
#include <math.h>
using namespace std;
int main () {
int n,h[101],a[101],k;
k=0;
cin>>n;
for (int i=1;i<=n;i++) {
cin>>h[i]>>a[i];
}
for (int i=1;i<=n;i++) {
for (int j=i;j<=n;j++) {
if (a[i]==h[j+1]) {
k++;
}
}
}
cout<<k;
return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int count=0;
    int i,j;
    int arr1[n],arr2[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr1[i]>>arr2[i];
    }
        for(int i=0;i<n;i++)
        {
        for(int j=0;j<=i;j++)
        {
            if(arr1[i]==arr2[j])
            count++;
        }
        }
    cout<<count;
    return 0;
}

 #include <bits/stdc++.h>
using namespace std;
int main(){
    int n,cnt=0;
    cin>>n;
    int a[100001];

for (int i=1;i<=n*2;i+=2){
  for (int j=i+1;j<=n*2;j+=2){
  cin>>a[i]>>a[j];
    if (i!=j&&a[i]==a[j]){
      cnt++;
    }
  }
}

    cout<<cnt+1;
    return 0;
    }

#include<iostream>
#include <bits/stdc++.h>
#include <set>
#define MAXN 100
using namespace std;
int main(){
    set<int> uniforms_in, uniforms_out;
    int N, in[MAXN], out[MAXN], occur_in[MAXN] = {0}, occur_out[MAXN] = {0};
    cin >> N;
    for (int i = 0; i < N; i++){
        scanf("%d%d", &in[i], &out[i]);
        uniforms_in.insert(in[i]);
        uniforms_out.insert(out[i]);
    }
    set<int>::iterator start = uniforms_in.begin(),
                                End = uniforms_in.end(),
                                iter;
    int nbr_in = 0;
    for (iter = start; iter != End; iter++){
        occur_in[*iter] = count(in, in+N, *iter);
        nbr_in++;
    }
    set<int>::iterator start1 = uniforms_out.begin(),
                                End1 = uniforms_out.end(),
                                iter1;
    int nbr_out = 0;
    for (iter1 = start1; iter1 != End1; iter1++){
        occur_out[*iter1] = count(out, out+N, *iter1);
        nbr_out++;
    }
    int games = 0;
    for (int i = 0; i < max(nbr_in, nbr_out); i++){
        games += occur_in[i] * occur_out[i];
    }
    printf("%d", games);
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <conio.h>
using namespace std;

int n;

int main(){
    cin>>n;
    if (n<2 || n>30){
            return 1;
            }
    int h[3];
    int a[3];
    int result=0;
    for (int i=0; i<n;i++){
        cin>>h[i]>>a[i];
        if (h[i]>100 || a[i]>100 || h[i]<1 || a[i]<1){
                     return 1;
                     }
        }
    for (int i=0;i<n;i++){
        if(h[i]==a[i+1]){
                         result++;
                         }
        if(a[i]==h[i+1]){
                         result++;
                         }
        }
    cout<<result;
    }

#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin>>n;
    int first[n];
    int second[n];
    for(int i=0;i<n;i++){
        cin>>first[i]>>second[i];
    }
    sort(first,first+n);
    sort(second,second+n);
    int i=0,j=0,res=0;
    while(i<n && j<n){
        if(first[i]==second[j]){
            res++;
            i++;
            j++;
        }else if(first[i]<second[j]){
            i++;
        }else
        {
            j++;
        }

    }
    cout<<res;
    return 0;
}

#include <iostream>
#include<string>
using namespace std;

//#define DEBUG

int main()
{
    int Cnt = 0 ;
    int G[101] = {0};
    int H[101] = {0};
    int nTeams;
#ifdef DEBUG
    FILE *fp;
    fp = freopen("input.txt", "r", stdin);
    fp = freopen("output.txt", "w", stdout);
#endif // DEBUG
    cin >> nTeams;
    int h,g;
    cin >> h >> g;
    H[h] = 1;
    G[g] = 1;
    for(int i = 0; i < nTeams-1; i++)
    {
        cin >> h >> g;
        if(G[h] == 1)
        {
            Cnt++;
        }
        if(H[g] == 1)
        {
            Cnt++;
        }
        H[h] = 1;
        G[g] = 1;

    }

    cout<<Cnt;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,c;
	cin>>n;
	int h[n],a[n];
	for(int i=0;i<n;i++)
		cin>>h[i]>>a[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(h[i]==a[j])
			c++;
		}
	}
	cout<<c;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,ans=0;
    cin>>n;
    int guest[n],host[n];
    for(int i=0;i<n;i++)
        cin>>host[i]>>guest[i];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(host[i]==guest[i])
                ans++;
        }
    }
    cout<<ans;
}

# include <iostream>
using namespace std;
int a[10005], b[10005],l,j,n,i;
int main()
{
    cin>>n;
    for (i=1; i<=n; i++)
    cin>>a[i]>>b[i];
    for (i=1; i<=n; i++)
    {
        if (a[i]==b[2]) l++;
}
cout<<l;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n,m,x;
  cin>>n>>m;
  int a[m];
  for (int i=0;i<m;i++)
  {
      cin>>a[i];
  }
  sort(a,a+m);
  int min=a[m-n+1]-a[0];
  for(int i=1;i<=m-n;i++)
  {
      x=a[i+m-n+1]-a[i];
      if (x<min){
          min=x;
      }
  }
  cout<<min;
}

#include <iostream>
using namespace std;
int a,b[1001],c[1001],d,i,j;
main()
{
      cin>>a;
      for (i=1; i<=a; i++)

          cin>>b[i]>>c[i];

          for (i=1; i<=a; i++)
      for (j=1; j<=a; j++)
      {if (b[i]==c[j]) d=d+1;}
      //system("pause");
      }

#include<iostream>
using namespace std ;
int main(){
    int n;
    cin>> n;
    int c=0;
    int t[n][2];
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++){
            cin>>t[i][j];
        }
        cout<<endl;
    }
     for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(t[i][1]==t[j][2]){
                if(i!=j){
                    c++;
                }
                else{

                }
            }

      }
     }
     cout << c;
     return 0;
}

#include <iostream>
using namespace std;int main(){
int f=0,m=0,k,t,x,n;cin>>n;
for(int a=0;a<n;a++){
cin>>x;if(x%2==0)k=a+1,f++;else t=a+1,m++;
}
if(f==1)cout<<k;else cout<<t;
}

#include <bits/stdc++.h>
#include <string>
#include <cctype>
using namespace std;
#define MAX 10000000;
#define MIN -9999;
int main(){
	int n,i;
	cin>>n;
	int cnt=0;
	int h[100],a[100],cnth[101]={0},cnta[101]={0};
	cout<<cnta[100];
	for(i=0;i<n;i++){
		cin>>h[i]>>a[i];

		if(cnta[h[i]]>=1){
		//	flag[a[i]]=2;
			//cout<<"h[i] cnth["<<h[i]<<"] is "<<cnth[h[i]]<<endl;
			//cout<<"h[i] cnta["<<h[i]<<"] is "<<cnta[h[i]]<<endl;
			cnt=cnt+cnta[h[i]];
		//	cout<<"cnt is := "<<cnt<<endl;
			cnth[h[i]]=cnth[h[i]]+1;
		//	cout<<"h[i] after setting is cnta["<<h[i]<<"] is "<<cnth[h[i]]<<endl<<endl;

		}
		else {
			cnth[h[i]]=1;
		//	cout<<"first time cntH initiated of"<<h[i]<<" is "<<cnth[h[i]]<<endl;
		//	cout<<"cnt is := "<<cnt<<endl;
		}

			if(cnth[a[i]]>=1){
		//	flag[h[i]]=1;
	    //	cout<<"a[i] cnth["<<a[i]<<"] is "<<cnth[a[i]]<<endl;
		//	cout<<"a[i] cnta["<<a[i]<<"] is "<<cnta[a[i]]<<endl;
			cnt=cnt+cnth[a[i]];
		//	cout<<"cnt is := "<<cnt<<endl;
			cnta[a[i]]=cnta[a[i]]+1;
		//	cout<<"a[i] after setting is cnta["<<a[i]<<"] is "<<cnta[a[i]]<<endl<<endl;

		}
		else{
			cnta[a[i]]=1;
		//	cout<<"first time cntA initiated of "<<a[i]<<" is "<<cnta[a[i]]<<endl;
		//	cout<<"cnt is := "<<cnt<<endl;
		}

	//	cout<<"i == "<<i<<endl;
	//	cout<<endl;
	//	cout<<endl;

	}
	cout<<cnt<<endl;
//	cout<<"ye kya bakchodi hai"<<endl;
	return 0;
}

#include<bits/stdc++.h>
 using namespace std;

 int main()
 {
     int n,count=0,a,b;
     cin>>n;
     vector<int> v,v1;
     map <int ,int> h,hp;
     for(int i=0;i<n;i++)
    {
         cin>>a>>b;
         v.push_back(a);
         v1.push_back(b);
    }
      for(int i=0;i<n;i++)
      {
          h[v[i]]++;
      }
      for(int i=0;i<n;i++)
      {
          hp[v1[i]]++;
      }
    //   for(auto x :h)
    //     {
    //         cout<<x.first<<" "<<x.second<<endl;
    //     }
        // cout<<endl;
        // for(auto x :hp)
        // {
        //     cout<<x.first<<" "<<x.second<<endl;
        // }
        //cout<<endl;

       for(int i=0;i<n;i++)
      {
           if(h[v1[i]]>0)
           {
            //   cout<<v1[i]<<endl;
            //   cout<<h[v1[i]]<<" "<<hp[v1[i]]<<endl;
               count+=abs(h[v1[i]]-hp[v1[i]])+1;
               h[v1[i]]=-1;
            //   cout<<count<<endl;
           }
      }
      cout<<count<<endl;

     return 0;

 }

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n;
	int count = 0;
	std::vector<int> v_h(n,0);
	std::vector<int> v_g(n,0);
	for (int i = 0; i < n; i++)
	{
		cin>>v_h[i]>>v_g[i];
	}
	unordered_set <int> u_h;
	unordered_set <int> u_g;
	for (int i = 0 ; i < n ; i++)
	{
		u_g.insert(v_g[i]);
	}
	for (int i = 0; i < n; i++)
	{
		if(u_g.find(v_h[i])!= u_g.end())
		{
			count++;
		}
	}
	cout<<count;
	return 0;
}

#include<iostream>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <string.h>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
using namespace std;

int main() {
    int n; int ans = 0;
    cin >> n;
    int home[n], guest[n];

    for (int i = 0; i < n; i++)
    {
        int a, b; cin >>  home[n] >> guest[n];
    }
    for (int j = 0; j < n; j++)
    {
        if (home[j] == guest[j]) ans++;
    }
    cout << ans << endl;

}

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <sstream>
#include <map>
#include <ctime>
#include <cstdlib>
#include <list>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include<unordered_map>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
int dx8[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy8[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 1, -1, 0, 0 };
int dx[] = { 0, 0, 1, -1 };
int X[6] = { 0, 0, 0, -1, 0, 1 };
int Y[6] = { 0, 0, -1, 0, 1, 0 };
int Z[6] = { 1, -1, 0, 0, 0, 0 };
// start + (end - start) / 2;

#define OO ll(1e18)
#define mod ll(1000000007)

int h[35], g[35];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n;i++) {
		int b;
		cin >> h[i] >> b;
		g[b]++;
	}
	int ans = 0;
	for (int i = 1;i <= n;i++) {
		ans += g[h[i]];
	}
	cout << ans << "\n";
}

#include <iostream>
#include <string>
#include <string.h>
#include<cstdlib>
#include <ctype.h>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
    long long n, k,m=0, arr[201][2],s=0,d=0,y[10000],b[1000],c[1000],e[1000],sa[3];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<2;j++)
        {
            cin>>arr[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(arr[i][0]==arr[i++][1])
            {
                s++;
            }
        }
      //  arr[0][0]=arr[i+1][i+1];
        //arr[0][1]=arr[i+1][]
    }
    cout<<s<<endl;
return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int h[100]={0},g[100]={0},n,ho,gu,count = 0;
    cin>>n;

    while(n--)
    {
        cin>>ho>>gu;
        h[ho]++;
        g[gu]++;
        if(h[gu]!=0)
            count+=h[gu];
        //if(g[ho]!=0)
          //  count+=g[gu];
    }
    cout<<count;
    return 0;

}

#include <iostream>

using namespace std;

int main()
{
    int n,b=0;
    cin>>n;
    int a[2][n];
    for(int i=0;i<n;i++)
        cin>>a[0][i]>>a[1][i];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(a[i][0]==a[j][1]&i!=j)
                b++;

    cout<<b;
    return 0;
}

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
int n,j,i;
cin>>n;
int a[n],b[n];
for(i=0;i<n;i++)
{
        a[i]=0;
        b[i]=0;
}
for(i=0;i<n;i++)
{
                cin>>j;
                a[j-1]++;
                cin>>j;
                b[j-1]++;
}
j=0;
for(i=0;i<n;i++)
{
                j+=a[i]*b[i];
}
cout<<j;
}

#include <iostream>
#include<string>
using namespace std;
int arr[105]={};
int arr2[105]={};
int main() {
	// your code goes here

	 int n;
	 cin>>n;

	  int result=0;
	  for(int i=0;i<n;i++){
	  	int x,y;
	  	cin>>x>>y;
	  	++arr[x];
	  	++arr2[y];
	  }
	  for(int i=0;i<=100;i++){
	  	if(arr[i]&&arr2[i])
 	  	result+=max(arr[i],arr2[i]);
	  }
	  cout<<result<<endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
 int x,c,arr[x],ar[x];
        cin>>x;
        for (int i=1;i<=x;i++)
        cin>>arr[i]>>ar[i];
        for (int i=1;i<=x;i++)
            for(int j=1;j<=x;j++)
        {c=0;
             if (i!=j)
             c++;
             if(arr[i]==ar[j])
              c++;
        }
        cout<<c;
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>

using namespace std;
#define map(it)  map<string,int>::iterator it;
#define FOR(i,t)   for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define rep(i,a) for(i=0;i<a;i++)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define DEBUG
#define all(x) x.begin(),x.end()
#define VE vector<int>
#define pb push_back
#define sz size()
#define ff first
#define sc second

#define ll long long
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
using namespace std;
int main()
{
ll ar[100000],ar1[10000];
ll n,m,i,j,k,l,mn=0,mx=0;
string s,ss,s1;
    ll a,b;
cin>>n;
rep(i,n)
{
  cin>>ar[i]>>ar1[i];
}
rep(i,n)
{
if(ar[i]==ar1[i+1] or ar[i+1]==ar1[i])
{
  mn=min(ar[i],ar[i+1]);
  mx=min(ar1[i+1],ar[i]);
}
}
cout<<min(mn,mx);
return 0;
}

#include<iostream>
#include<cstring>
using namespace std;

int main()
{
    int n,dp1[101],dp2[101],x,y,sum=0;
    cin>>n;
    memset(dp1,0,sizeof(dp1));
    memset(dp2,0,sizeof(dp2));
    for(int i=0; i<n; i++)
    {
        cin>>x>>y;
        if(dp1[y]==1&&dp2[x]==1)
        {
            sum+=2;
            dp1[x]=1;
            dp2[y]=1;
        }

        else if(dp2[x]==1 && dp1[y]!=1)
        {
            sum++;
            dp2[y]=1;
        }
        else if(dp1[y]==1 && dp2[x]!=1)
        {
            sum++;
            dp1[x]=1;

        }
        else
        {
            dp1[x]=1;
            dp2[y]=1;

        }

    }
    cout<<sum<<endl;

}

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
bool compare(int a,int b)
{
		return a<b;
	}
int cmp(const void *a,const void *b)
{
    return *(char *)a-*(char *)b;
}
bool composite(int i)
{
	if(i==1) return false;
	else if(i==2||i==3) return true;
	else for(int j=2;j<sqrt((float)i)+1;j++)
	{
		if(i%j==0)
			return true;
	}
	return false;
}
int gcd(int a,int b)
{
	int r=1;
	int x,y;
	x=max(a,b);
	y=min(a,b);
	while(r)
	{
		r=x%y;
		x=y;
		y=r;

	}
	return x;

}
int main ()
{

		int n,a[101],b[101];
		while(cin>>n)
		{
			int num=0;
			for(int i=0;i<n;i++)
			{
				cin>>a[i];
				cin>>b[i];

			}
			for(int i=0;i<n-1;i++)
			{

				for(int j=0;j<n-1;j++)
				{
					if((a[i]==b[j+1]&&b[i]!=a[j+1])||(a[i]!=b[j+1]&&b[i]==a[j+1]))
						num++;

				 if(a[i]==b[j+1]&&b[i]==a[j+1])
						num+=2;
				}

			}
			if(n>=4) num-=1;
			cout<<num<<endl;
		}
}

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{

    int n,ans=0;
    cin>>n;
    int h[n],a[n];
    for(int i=0; i<n; i++)
        cin>>h[i]>>a[i];
    sort(h,h+n);
    sort(a,a+n);
    for(int j=0; j<n; j++)
    {
        int mid,f,l;
        l=n,f=0;
        if(h[j]<=a[n] && h[j]>=a[0])
        {
        mid=(l+f)/2;
        while(l!=f)
        {

          if(a[mid]==h[j])
          break;
          if(h[j]>a[mid])
            f=mid+1;
          else if(h[j]<a[mid])
            l=mid-1;
            mid=(l+f)/2;
        }
        if(a[mid]!=h[j])
            break;
        else
         ans++;
         int k=mid;
         for(int x=0; x<n; x++)
         {
             k--;
             if(a[k]==a[k+1])
                ans++;
             else
                x=n;
         }
         k=mid;
         for(int y=0; y<n; y++)
         {
             k++;
             if(a[k]==a[k-1])
                ans++;
             else
                y=n;
         }
        }
    }
    cout<<ans;
    return 0;
 }

#include<iostream>
using namespace std;
int main()
{
    int i,j,n,m;

    cin>>n;
    //cout<<"enter no of columns:";
    //cin>>m;
    int a[n][2];

    int count1=0;
    int count2=0;
    for(int i=0; i<n; i++)
    {
        for(j=0; j<2; j++)
        {
            cin>>a[i][j];
        }
    }
    for(j=0; j<2; j++)
    {
        for(i=0; i<n; i++)
        {

            if(a[i][j]==a[i+1][j+1])
            {
                count1++;
            }
            if(a[i][j+1]==a[i+1][j])
            {
                count2++;
            }
        }
    }
    cout<<count1+count2;
}

#include <iostream>

using namespace std;

int main()
{int n,x[100],y[100],k=0;
cin>>n;
for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
}for(int i=0;i<n;i++){
for(int j=1;j<n;j++){
    if(x[i]==x[j])
        k++;

}}
cout<<k<<endl;

    return 0;
}

#include <iostream>

using namespace std;

int main()
{
int h[31],a[31];
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>h[i]>>a[i];
int ans=0;
for (int i=1;i<=n;i++)
    for (int j=1;j<=n;j++)
    if (h[i]==a[j]) ans++;
return 0;
}

#include <iostream>

using namespace std;

int main()
{
   long long int n,h[101],a[101],a2[101],h2[101],count=0;
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>h[i];
       h2[i]=h[i];
       cin>>a[i];
       a2[i]=a[i];
   }
   for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
           if(h[i]==a[j]){
               count++;
               a[j]=-1;
           }
   }
   }
   for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
           if(a2[i]==h2[j]){
               count++;
               h2[j]=-1;
           }
   }
   }
   cout<<count<<endl;
   return 0;
}

#include<bits/stdc++.h>
#include<iostream>

using namespace std;
int main()
{
    int n,i,j;
    cin>>n;
    int x = 2*n;
    int ara[65];
    for(i=0;i<x;i++){
        scanf("%d",&ara[i]);
    }
    int home[35];
    for(i=0,j=0;i<x;i=i+2,j++){
        home[j]=ara[i];
    }
    int guest[35];
    for(i=1,j=0;i<x;i=i+2,j++){
        guest[j]=ara[i];
    }
    int y=x/2;
    int s= 0;
    for(i=0;i<y;i++){
        for(j=0;j<x;j++){
            if(home[i]==guest[j]){
                s++;
            }
        }
    }
    printf("%d",s);
    return 0;

}

#include <iostream>
using namespace::std;
  int main(){
    int n; scanf("%d", &n);
    int guest[n],host[n]={};
    int temp,sum=0;
    for(int i=0;i<n;i++)
    {
      scanf("%d",&temp);
      host[temp-1]=1;
      scanf("%d",&temp);
      guest[temp-1]=1;
    }
    for(int i=0;i<n;i++)
    {
      sum+=host[i]*guest[i];
    }
    cout<<sum;

    return 0;
}

#include <iostream>

int main()
{
    unsigned int n;
    std::cin>>n;

    unsigned int data[102];
    for(unsigned int i=1; i<=n; ++i)
        std::cin>>data[i];

    unsigned int count = 0;

    for(unsigned int i=1; i<n; ++i)
    {
        for(unsigned int j=i+1; j<=n; ++j)
        {
            if(i == data[j]) ++count;
            if(j == data[i]) ++count;
        }
    }

    std::cout<<count;
}

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int* arr = new int[2 * n];
	int count = 0;
	for (int i = 0;i < 2*n;i++)
		cin >> arr[i];

	for (int i = 0;i < 2*n;i++)
	{
		for (int j = i;j < 2*n-1;j++)
		{

			if (i % 2 == 0)
			{
				if (j == 0)
				{
					if (arr[i] == arr[2 * j + 3])
						count++;
				}
				else
				{
					if (arr[i] == arr[2 * j + 1])
						count++;
				}
			}
			else
			{
				if (arr[i] == arr[2*j])
					count++;
			}
		}
	}
	cout << count;
}

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int* arr = new int[2 * n];
	int count = 0;
	for (int i = 0;i < 2*n;i++)
		cin >> arr[i];

	for (int i = 0;i < 2*n;i++)
	{
		for (int j = i;j < 2*n;j=j+2)
		{

			if (i % 2 == 0)
			{
				{
					if (arr[i] == arr[j+3])
						count++;
				}
			}
			else
			{
				if (arr[i] == arr[2*j])
					count++;
			}
		}
	}
	cout << count;
}

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,h,a,c=0;
	cin >> n >> h >> a;
	vector<int> H;
	vector<int> A;
	H.push_back(h);
	A.push_back(a);
	vector<int>::iterator it;
	for(int i=1; i<n; ++i)
	{
		cin >> h >> a;
		it = find(H.begin(), H.end(), a);
		if(it != H.end())
		{
			c++;
		}
		it = find(A.begin(), A.end(), h);
		if(it != A.end())
		{
			c++;
		}
		H.push_back(h);
		A.push_back(a);
	}
	cout << c;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main() {
	int n, ans;
	cin >> n;
	int h[n], a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> h[i] >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (h[i] == a[j]) {
				ans++;
			}
		}
	}
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,c;
	cin>>n;
	int h[n],a[n];
	for(int i=0;i<n;i++)
		cin>>h[i]>>a[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(h[i]==a[j])
			c++;
		}
	}
	cout<<c;
}

#include<bits/stdc++.h>
using namespace std;
int a, b, c, tmp, tmp1, counter, counter1;
int main(){
	cin>>a>>b>>c;
	while(tmp<a){
		tmp=tmp+c;
		counter1++;
	}
	while(tmp1<b){
		tmp1=tmp1+c;
		counter++;
	}
	cout<<counter*counter1<<endl;
}

#include <bits/stdc++.h>
using namespace std;

int n;
int main(){
	scanf("%d", &n);
	int h[n], a[n], cont=0;
	for(int i = 0; i < n; i++){
		scanf("%d%d",&h[i],&a[i]);
		for(int j = 0; j < n; j++){
			if(h[i]==a[j] && i!=j){
				cont++;
			}
		}
	}
	printf("%d",cont);
}

// In the name of God
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <fstream>
#include <bitset>
#include <string>
#include <cstring>
#include <cassert>
#include <ctime>
#include <complex>

typedef long long ll ;
typedef long double ld ;

#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;
int a , b = 0 ;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> a ;
    for ( int i = 1 ; i <= a ; i ++ )
      {
	for ( int j = 1 ; j <= a ; j ++ )
	{
	  if ( i = j )
	    {
	      b ++ ;
	    }
	}
      }
    cout << b << endl ;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin>>n;
	int count = 0;
	std::vector<int> v_h(n,0);
	std::vector<int> v_g(n,0);
	for (int i = 0; i < n; i++)
	{
		cin>>v_h[i]>>v_g[i];
	}
	unordered_map<int,int> u_g;
	unordered_map<int,int>:: iterator it;
	for(int i=0 ;i <n;i++)
	{
	    u_g.insert(make_pair(v_h[i],0));
	}
	for (int i = 0 ; i < n ; i++)
	{
	    if(u_g.find(v_h[i])!= u_g.end())
	    {
	        u_g[v_h[i]]++;
	    }
	}
	for (it = u_g.begin() ; it != u_g.end() ; it++)
	{
	    count+=it->second;
	}
	cout<<count;
	return 0;
}