stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#define N 2001

using namespace std;



int ret;

int n;

int L[N];

bool check(int x,int y,int z){

	if(max(max(L[y],L[z]),L[x])<L[x]+L[y]+L[z]-max(max(L[y],L[z]),L[x])) return 1;

	else return 0;

}



int main(){

	scanf("%d",&n);

	for(int i=1; i<=n; i++) scanf("%d",&L[i]);

	sort(L+1,L+n+1);

	if(n<=2) cout<<"0"<<endl;

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

    	for(int j=1; j<i; j++){

    		int sum=L[i]+L[j];

			int r=n,l=i;

			int ans=-1;

			while(l<=r){

				int mid=(l+r)/2;

				if(sum>L[mid]){

					ans=mid;

					l=mid+1;

				}

				else r=mid-1;

			} 

			if(ans!=-1) ret+=ans-i;

		}

	}

	printf("%d",ret);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.966786176893815x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

				else break;

			}

		}

	}

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

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

using namespace std;



int judge(int a,int b,int c)

{

    if((a+b)>c&&(a+c)>b&&(b+c)>a)

        return 1;

    else

        return 0;

}



int main()

{

    int n;

    cin>>n;

    int a[n],i,j,k,sum=0;

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

    {

        cin>>a[i];

    }

    sort(a,a+n);

   /* for(i=0;i<n;i++)

    {

        cout<<a[i]<<endl;

    }*/

    for(i=0;i<n-2;i++)

    {

        for(j=i+1;j<n-1;j++)

        {

            for(k=j+1;k<n;k++)

            {

                if(judge(a[i],a[j],a[k])==1)

                {

                    sum++;

                }

                if(judge(a[i],a[j],a[k])==0)

                    break;

            }

        }

    }

    cout<<sum;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 4.984864029932669x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

				else break;

			}

		}

	}

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

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

//N=2*10e3 L=10e3

using namespace std;

int a[2005];

int main(){

	int n;

	cin>>n;

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

		scanf("%d",&a[i]);

	}

	sort(a,a+n);

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

		cout<<a[i]<<" ";

	}

	cout<<endl;*/

	int ans=0;

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

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

			int k=lower_bound(a+j,a+n,(a[i]+a[j]))-a;

//			printf("%d %d %d %d\n",a[i],a[j],a[i]+a[j],k);

			if(k<n){

				ans+=(k-j-1);

			}else{

				ans+=n-j-1;

			}

		}

	}

	cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 4.998531952775887x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

				else break;

			}

		}

	}

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

}
// Slower C++ solution:
#include<iostream>

#include <algorithm>

using namespace std;

int num[2005];

int main(){

	int n;

	cin>>n;

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

		cin>>num[i];

	}

	int sum=0;

	sort(num,num+n);



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

		for(int j=i+1;j<n;j++){

			int a=num[i]+num[j];

			int k=j+1;

			while(num[k]<a&&k<n){

				sum++;

				k++;

			//	cout<<num[i]<<" "<<num[j]<<" "<<num[i]+num[j]<<endl;

			}

				

		}

		

	} 

	cout<<sum;

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 4.984610594447442x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

				else break;

			}

		}

	}

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

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int main(){

        int k, cnt=0, n, p;

        scanf("%d", &n);

        int a[n+1];

        int low, high, mid, j;

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

            scanf("%d", &a[j]);

            //printf("%d \n", a[j]);

        }

        sort(a, a+n);

        //for(j=0; j<n; j++) printf("%d ", a[j]);

        //printf("\n\n");

        for(j=0; j<n-2;j++){

            for(k=j+1; k<n-1; k++){

                int ans=0;

                p=a[j]+a[k]-1;

                low=k+1;

                high=n-1;

                mid=(low+high)/2;

                while(low<=high){

                    if(a[mid]>p){

                        high=mid-1;

                        mid=(high+low)/2;

                    }

                    else{

                        low=mid+1;

                        mid=(high+low)/2;

                    }

                }

                if(a[mid]<=p) ans=mid-k;

                //ans=ans+k-j-1;

                //if(ans==0) break;

                //printf("%d %d %d\n", a[j], a[k], ans);

                cnt=cnt+ans;

            }

        }

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

}

// Faster C++ solution for the same problem (measured speedup: 4.929750869862969x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

				else break;

			}

		}

	}

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

}
// Slower C++ solution:
#include <bits/stdc++.h>

 

using namespace std;

int main() {

    int N;

    cin >> N;

    int L[N];

    for(int i = 0; i < N; i++){

        cin >> L[i];

    }

    sort(L,L+N);

    int sum = 0;

    for(int i = 1; i < N - 1; i++){

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

            for(int k = N-1; i< k; k--){

                int a = L[j];

                int b = L[i];

                int c = L[k];

                if(a < b + c && b < a + c && c < a + b){

                    sum ++;

                }

            }

        }

    }

    cout << sum << endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.995328688498967x):
#include<stdio.h>

#include<stdlib.h>

int inc(const void *a, const void *b)

{

	return *(int *)a-*(int *)b;

}

int main()

{

	int n,a[10000],l=0,r=1,m,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	qsort(a,n,sizeof(int),inc);

	m=2;

	for(int i=0;i<n-2;i++)

	{

		for(int j=i+1;j<n-1;j++)

		{

			for(int k=j+1;k<n;k++)

			{

				if(a[i]+a[j]>a[k])cnt++;

				else break;

			}

		}

	}

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

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>



int main()

{

  int n;

  int l[2000];

  scanf("%d", &n);

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

  {

    scanf("%d", l + i);

  }

  std::sort(l, l + n);

  int sum[1000 * 2001];

  int *p = sum;

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

  {

    for (int j = i + 1; j < n; ++j)

    {

      *p++ = l[i] + l[j];

    }

  }

  std::sort(sum, p);

  long long ans = 0;

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

  {

    long long lc = n - 1 - i;

    ans += (p - std::upper_bound(sum, p, l[i])) - (n - 1) - lc * (lc - 1) / 2 - lc * (n - lc - 1);

  }

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

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.9936202843675492x):
#include <cstdio>

#include <algorithm>



int main()

{

  int n;

  scanf("%d\n", &n);

  int l[2000];

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

  {

    scanf("%d", l + i);

  }

  std::sort(l, l + n);

  long long ans = 0;

  for (int i = 0; i < n - 2; ++i)

  {

    for (int j = i + 1; j < n - 1; ++j)

    {

      ans += std::lower_bound(l + j + 1, l + n, l[i] + l[j]) - (l + j + 1);

    }

  }

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

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ull unsigned long long

#define ll long long

ll ans;

map<ull,ll>m;

const int maxn=200005;

vector<int>g[maxn];

ull dp[maxn];

const ull b=1000000007;

void dfs(int u,int p)

{

	dp[u]=1;

	for(int i=0;i<g[u].size();i++)

	{

		int v=g[u][i];

		if(v==p)

		continue;

		dfs(v,u);

		dp[u]+=dp[v]*b;

	}

	ans+=m[dp[u]];

	m[dp[u]]++;

}

int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<n;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		g[u].push_back(v);

		g[v].push_back(u);

	}

	dfs(1,-1);

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8247867584636148x):


#include<algorithm>

#include<vector>

 #include<cstring>

#include<string>

#include<iomanip>

#include<cstdio>

#include<stack>

#include<iostream>

#include<map>

#include<queue>

#include<cmath>

using namespace std;

#define sf scanf

#define pf printf

#define mem(a,b) memset(a,b,sizeof(a));

#define rep(i,a,b) for(int i=(a);i<=(b);++i)

#define mod 998244353

#define N 100020

#define M 400020

#define ULL unsigned long long

#define LL long long

#define inf 0x3f3f3f3f

map<ULL,LL>mp;

vector<int>g[N];

ULL dp[N];

LL ans;int n;

const ULL b=1000000007;

void dfs(int u,int fa){

    dp[u]=1;

    for(int i=0;i<g[u].size();++i){

        int v=g[u][i];

        if(v==fa)continue;

        dfs(v,u);

        dp[u]+=dp[v]*b;

    }

    ans+=mp[dp[u]];

    mp[dp[u]]++;

}

int main(){

    sf("%d",&n);

        ans=0;

        rep(i,1,n-1){

            int u,v;sf("%d%d",&u,&v);

            g[u].push_back(v);g[v].push_back(u);

        }

        dfs(1,1);

        cout<<ans<<'\n';

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ull unsigned long long

#define ll long long

ll ans;

map<ull,ll>m;

const int maxn=200005;

vector<int>g[maxn];

ull dp[maxn];

const ull b=1000000007;

void dfs(int u,int p)

{

	dp[u]=1;

	for(int i=0;i<g[u].size();i++)

	{

		int v=g[u][i];

		if(v==p)

		continue;

		dfs(v,u);

		dp[u]+=dp[v]*b;

	}

	ans+=m[dp[u]];

	m[dp[u]]++;

}

int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<n;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		g[u].push_back(v);

		g[v].push_back(u);

	}

	dfs(1,-1);

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.6443754591443218x):
#include<algorithm>

#include<iostream>

#include<cstring>

#include<cstdlib>

#include<cstdio>

#include<bitset>

#include<vector>

#include<queue>

#include<stack>

#include<map>

#include<set>

#include<cmath>

#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;

const ll base = 999983;

const int maxn = 1e5+5;

int n,ind[maxn];

vector<ll> htable;

vector<int> G[maxn];



ll dfs(int u)

{

    ll temp = 0;

    for(int i=0;i<G[u].size();++i){

        temp += dfs(G[u][i]);

    }

    htable.push_back(temp*base+G[u].size());

    return temp*base+G[u].size();

}



inline ll work(ll m)

{

    return m*(m-1)>>1;

}



int main()

{

    while(~scanf("%d",&n)){

        htable.clear();

        memset(ind,0,sizeof ind);

        for(int i=0;i<=n;++i) G[i].clear();

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

            int u,v; scanf("%d%d",&u,&v);

            G[u].push_back(v);

            ++ind[v];

        }

        int s = 0;

        for(int i=1;i<=n && !s;++i){

            if(ind[i] == 0) s = i;

        }

        dfs(s);

        sort(htable.begin(),htable.end());

        ll num = 1;

        ll ans = 0;

        for(int i=1;i<htable.size();++i){

            if(htable[i] != htable[i-1]){

                ans += work(num);

                num = 1;

            }

            else ++num;

        }

        if(htable.size() > 1 && htable[htable.size()-1] == htable[htable.size()-2]) ans += work(num);

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

    }

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ull unsigned long long

#define ll long long

ll ans;

map<ull,ll>m;

const int maxn=200005;

vector<int>g[maxn];

ull dp[maxn];

const ull b=1000000007;

void dfs(int u,int p)

{

	dp[u]=1;

	for(int i=0;i<g[u].size();i++)

	{

		int v=g[u][i];

		if(v==p)

		continue;

		dfs(v,u);

		dp[u]+=dp[v]*b;

	}

	ans+=m[dp[u]];

	m[dp[u]]++;

}

int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<n;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		g[u].push_back(v);

		g[v].push_back(u);

	}

	dfs(1,-1);

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.824473609268989x):
#include<bits/stdc++.h>

using namespace std;

const int N=100005;

typedef long long int LL;





vector<int >ve[N];

map< LL , int >ma;

LL a[N];

LL b=10e2+7;

LL ans;

void dfs(int u)

{

    a[u]=1;

    for(int i=0;i<ve[u].size();i++)

    {

        int v=ve[u][i];

        dfs(v);

        a[u]+=a[v]*b;

    }

    ans+=ma[a[u]];

    ma[a[u]]++;

    return ;

}



int main()

{

    int n;

        cin>>n;

        int u,v;

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

        {

            cin>>u>>v;

            ve[u].push_back(v);

        }

        ans=0;

        dfs(1);

        cout<<ans<<endl;





    return 0;

}
// Slower C++ solution:
#include<algorithm>

#include<iostream>

#include<cstring>

#include<cstdlib>

#include<cstdio>

#include<bitset>

#include<vector>

#include<queue>

#include<stack>

#include<map>

#include<set>

#include<cmath>

#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;

const ll base = 999983;

const int maxn = 1e5+5;

int n,ind[maxn];

vector<ll> htable;

vector<int> G[maxn];



ll dfs(int u)

{

    ll temp = 0;

    for(int i=0;i<G[u].size();++i){

        temp += dfs(G[u][i]);

    }

    htable.push_back(temp*base+G[u].size());

    return temp*base+G[u].size();

}



inline ll work(ll m)

{

    return m*(m-1)>>1;

}



int main()

{

    while(~scanf("%d",&n)){

        htable.clear();

        memset(ind,0,sizeof ind);

        for(int i=0;i<=n;++i) G[i].clear();

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

            int u,v; scanf("%d%d",&u,&v);

            G[u].push_back(v);

            ++ind[v];

        }

        int s = 0;

        for(int i=1;i<=n && !s;++i){

            if(ind[i] == 0) s = i;

        }

        dfs(s);

        sort(htable.begin(),htable.end());

        ll num = 1;

        ll ans = 0;

        for(int i=1;i<htable.size();++i){

            if(htable[i] != htable[i-1]){

                ans += work(num);

                num = 1;

            }

            else ++num;

        }

        if(htable.size() > 1 && htable[htable.size()-1] == htable[htable.size()-2]) ans += work(num);

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

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1095237399239612x):
#include<bits/stdc++.h>

using namespace std;

const int N=100005;

typedef long long int LL;





vector<int >ve[N];

map< LL , int >ma;

LL a[N];

LL b=10e2+7;

LL ans;

void dfs(int u)

{

    a[u]=1;

    for(int i=0;i<ve[u].size();i++)

    {

        int v=ve[u][i];

        dfs(v);

        a[u]+=a[v]*b;

    }

    ans+=ma[a[u]];

    ma[a[u]]++;

    return ;

}



int main()

{

    int n;

        cin>>n;

        int u,v;

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

        {

            cin>>u>>v;

            ve[u].push_back(v);

        }

        ans=0;

        dfs(1);

        cout<<ans<<endl;





    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ull unsigned long long

#define ll long long

ll ans;

map<ull,ll>m;

const int maxn=200005;

vector<int>g[maxn];

ull dp[maxn];

const ull b=1000000007;

void dfs(int u,int p)

{

	dp[u]=1;

	for(int i=0;i<g[u].size();i++)

	{

		int v=g[u][i];

		if(v==p)

		continue;

		dfs(v,u);

		dp[u]+=dp[v]*b;

	}

	ans+=m[dp[u]];

	m[dp[u]]++;

}

int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<n;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		g[u].push_back(v);

		g[v].push_back(u);

	}

	dfs(1,-1);

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.824473609268989x):
#include<bits/stdc++.h>

using namespace std;

const int N=100005;

typedef long long int LL;





vector<int >ve[N];

map< LL , int >ma;

LL a[N];

LL b=17;

LL ans;

void dfs(int u)

{

    a[u]=1;

    for(int i=0;i<ve[u].size();i++)

    {

        int v=ve[u][i];

        dfs(v);

        a[u]+=a[v]*b;

    }

    ans+=ma[a[u]];

    ma[a[u]]++;

    return ;

}



int main()

{

    int n;

        cin>>n;

        int u,v;

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

        {

            cin>>u>>v;

            ve[u].push_back(v);

        }

        ans=0;

        dfs(1);

        cout<<ans<<endl;





    return 0;

}
// Slower C++ solution:
#include<algorithm>

#include<iostream>

#include<cstring>

#include<cstdlib>

#include<cstdio>

#include<bitset>

#include<vector>

#include<queue>

#include<stack>

#include<map>

#include<set>

#include<cmath>

#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;

const ll base = 999983;

const int maxn = 1e5+5;

int n,ind[maxn];

vector<ll> htable;

vector<int> G[maxn];



ll dfs(int u)

{

    ll temp = 0;

    for(int i=0;i<G[u].size();++i){

        temp += dfs(G[u][i]);

    }

    htable.push_back(temp*base+G[u].size());

    return temp*base+G[u].size();

}



inline ll work(ll m)

{

    return m*(m-1)>>1;

}



int main()

{

    while(~scanf("%d",&n)){

        htable.clear();

        memset(ind,0,sizeof ind);

        for(int i=0;i<=n;++i) G[i].clear();

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

            int u,v; scanf("%d%d",&u,&v);

            G[u].push_back(v);

            ++ind[v];

        }

        int s = 0;

        for(int i=1;i<=n && !s;++i){

            if(ind[i] == 0) s = i;

        }

        dfs(s);

        sort(htable.begin(),htable.end());

        ll num = 1;

        ll ans = 0;

        for(int i=1;i<htable.size();++i){

            if(htable[i] != htable[i-1]){

                ans += work(num);

                num = 1;

            }

            else ++num;

        }

        if(htable.size() > 1 && htable[htable.size()-1] == htable[htable.size()-2]) ans += work(num);

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

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1095237399239612x):
#include<bits/stdc++.h>

using namespace std;

const int N=100005;

typedef long long int LL;





vector<int >ve[N];

map< LL , int >ma;

LL a[N];

LL b=17;

LL ans;

void dfs(int u)

{

    a[u]=1;

    for(int i=0;i<ve[u].size();i++)

    {

        int v=ve[u][i];

        dfs(v);

        a[u]+=a[v]*b;

    }

    ans+=ma[a[u]];

    ma[a[u]]++;

    return ;

}



int main()

{

    int n;

        cin>>n;

        int u,v;

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

        {

            cin>>u>>v;

            ve[u].push_back(v);

        }

        ans=0;

        dfs(1);

        cout<<ans<<endl;





    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int N = 1e5 + 10;

const unsigned X = 1234567;

const unsigned R = 7531;



int n;

unsigned h[N];

vector <int> g[N];

map <unsigned, int> f;



void dfs (int u, int p) {

	unsigned now = 0;

	for (int v : g[u]) if (v != p) {

		dfs(v, u); 

		now += h[v];

	}

	h[u] = now * X + R;

	++f[h[u]];  

}



int main (int argc, char const *argv[]) {

	scanf("%d", &n);

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

		int u, v;

		scanf("%d %d", &u, &v);

		g[u].push_back(v);

		g[v].push_back(u);

	}



	dfs(1, 0);



	long long ans = 0;

	for (auto it : f) {

		long long cnt = (long long) it.second;

		ans += (cnt * (cnt - 1LL))/2LL;

	}



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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.515944571926512x):
#include <cstdio>

#include <cstring>

#include <algorithm>

#include <iostream>

#include <map>



#define MAXN 100005



using namespace std;



struct edge

{

	int y,next;

};



edge v[2*MAXN];

int head[MAXN];

int tot = 0;

long long ans = 0;

map<unsigned long long,int> S;



void add(int x,int y)

{

	tot++;

	v[tot].y = y;

	v[tot].next = head[x];

	head[x] = tot;

}



unsigned long long dfs(int x,int fa)

{

	unsigned long long temp = 1;

	for (int i=head[x];i;i=v[i].next)

	{

		if (v[i].y == fa) continue;

		temp += 131*dfs(v[i].y,x);

	}

	ans += S[temp];

	S[temp]++;

	return temp;

}



int main()

{

	int x,y,n;

	scanf("%d",&n);

	for (int i=1;i<n;i++)

	{

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

		add(x,y);

		add(y,x);

	}



	S.clear();

	ans = 0;

	dfs(1,0);



	cout << ans << endl;

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;



#define pb              push_back

#define PII             pair <int,int>

#define PLL             pair <ll,ll>

#define mp              make_pair

#define xx              first

#define yy              second

#define all(v)          v.begin(),v.end()



#define lt              2*n

#define rt              2*n+1

#define clft            2*n,st,mid

#define crgt            2*n+1,mid+1,ed



#define CLR(a)          memset(a,0,sizeof(a))

#define SET(a)          memset(a,-1,sizeof(a))



#define eps             1e-9

#define PI              acos(-1.0)

#define MAX             100010

#define INF             2000000000



/******************************************************************************************/



#define mod1            1000000007

#define mod2            1000000123

#define base            100001



vector <ll> ed[MAX];

ll has1[MAX],has2[MAX];

map <PLL,ll> M;



void dfs(ll u,ll p)

{

    ll i,v,h1 = 0,h2 = 0;

    for(i=0;i<ed[u].size();i++){

        v = ed[u][i];

        if(v==p) continue;

        dfs(v,u);

        h1 += has1[v];

        h2 += has2[v];

        h1 %= mod1;

        h2 %= mod2;

    }

    has1[u] = (h1*base + 1)%mod1;

    has2[u] = (h2*base + 1)%mod2;

    M[mp(h1,h2)]++;

}



int main()

{

    //ios_base::sync_with_stdio(false);

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

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



    ll n,i,u,v;

    cin >> n;

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

        cin >> u >> v;

        ed[u].pb(v);

        ed[v].pb(u);

    }

    dfs(1,0);



    ll ans = 0;

    map <PLL,ll> :: iterator it = M.begin();

    while(it!=M.end()){

        ans += (it->second*(it->second-1))/2;

        it++;

    }

    cout << ans << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.5317594662154423x):
#include <cstdio>

#include <cstring>

#include <algorithm>

#include <iostream>

#include <map>



#define MAXN 100005



using namespace std;



struct edge

{

	int y,next;

};



edge v[2*MAXN];

int head[MAXN];

int tot = 0;

long long ans = 0;

map<unsigned long long,int> S;



void add(int x,int y)

{

	tot++;

	v[tot].y = y;

	v[tot].next = head[x];

	head[x] = tot;

}



unsigned long long dfs(int x,int fa)

{

	unsigned long long temp = 1;

	for (int i=head[x];i;i=v[i].next)

	{

		if (v[i].y == fa) continue;

		temp += 131*dfs(v[i].y,x);

	}

	ans += S[temp];

	S[temp]++;

	return temp;

}



int main()

{

	int x,y,n;

	scanf("%d",&n);

	for (int i=1;i<n;i++)

	{

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

		add(x,y);

		add(y,x);

	}



	S.clear();

	ans = 0;

	dfs(1,0);



	cout << ans << endl;

	return 0;

}