stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):


#include <iostream>

#include <math.h> 

#include <vector>

#include <algorithm>

#include <iomanip>      // std::setprecision

#include <map>

#include <unordered_map>

#include <string>

#include <set>



using namespace std;



int main()

{



	double N = 0;

	std::vector<int> nums;

	cin >> N;

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

	{

		int num;

		cin >> num;

		nums.push_back(num);

	}

	std::sort(nums.begin(), nums.end());

	int sol = 0;

	int i = 0, j = N-2, k = N-1;

	for (int k = N - 1; k > 1; --k)

	{

		for (int j = k - 1; j > 0; --j)

		{

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

			{

				if (nums[i] + nums[j] > nums[k])

				{

					sol += j - i;

					break;

				}

			}

		}

	}

	std::cout << sol;

}


// Optimized solution to the same problem (faster):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

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

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

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

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

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

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<iostream>

#include<vector>

#include<map>

#include<algorithm>

#include<cmath>

using namespace std;



int main()

{

    int N , ans = 0 ;

    cin >> N;

    vector<int>V(N);

    for (int j = 0; j < N; j++)

    {

        cin >> V[j];

    }

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

    int low = 0, high = 0, mid = 0;

    for (int j = 0; j < N-2; j++)

    {

        

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

        {



            low = i + 1;

            high = N-1;

            int temp = i;

            while (low <= high)

            {

                mid = (high + low) / 2;

                if (V[i] + V[j] > V[mid]) 

                {

                    temp = mid;

                    low = mid + 1;

                }

                else if (V[i] + V[j] <= V[mid]) { high = mid - 1; }

            }

            ans += (temp - i);

        }

    }



    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

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

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

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

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

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

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <vector>

using namespace std;

#define ll long long



int main() {

    ll n, triangle = 0;

    cin >> n;

    vector<ll> s(n);

    for(auto &i: s) cin >> i;

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

    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(s[i] + s[j] > s[k] && s[i] + s[k] > s[j] && s[k] + s[j] > s[i]) {

                    triangle++;

                }

                else if (s[i] + s[j] <= s[k]) break;

            }

        }

    }

    cout << triangle << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

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

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

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

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

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

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _USE_MATH_DEFIMES

#include <algorithm>

#include <array>

#include <bitset>

#include <cassert>

#include <cctype>

#include <climits>

#include <clocale>

#include <cmath>

#include <complex>

#include <cstdio>

#include <cstdlib>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <map>

#include <numeric>

#include <queue>

#include <regex>

#include <set>

#include <sstream>

#include <stack>

#include <string>

#include <tuple>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>



const int MOD = 1'000'000'007;

const int INF = 1'000'000'000; //1e9

const int NIL = -1;

const long long LINF = 1'000'000'000'000'000'000; // 1e18

const long double EPS = 1E-10;



template<class T, class S> inline bool chmax(T &a, const S &b){

    if(a < b){

        a = b; return true;

    }

    return false;

}

template<class T, class S> inline bool chmin(T &a, const S &b){

    if(b < a){

        a = b; return true;

    }

    return false;

}

















int main(){

    int N; std::cin >> N;

    long long cnt(0);

    std::vector<int> L(N);

    for(int i(0); i < N; ++i) std::cin >> L[i];

    std::sort(std::begin(L), std::end(L));

    for(int mid(1), mid_len(N-1); mid < mid_len; ++mid){

        for(int high(mid+1); high < N; ++high){

            int lowlow(L[high] - L[mid] + 1);

            cnt += std::max(0L, std::distance(std::lower_bound(std::begin(L), std::end(L), lowlow), std::begin(L) + mid));

        }

    }

    std::cout << cnt << std::endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

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

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

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

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

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

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define LL long long

#define sigma_size 30

#define max_size (int)(2e5+10)

#define MAX (int)(1e5+7)

int qread()

{

	char c; int s=0,t=1; while ((c=getchar())<'0' || c>'9') (c=='-' && (t=-1));

	do s=s*10+c-'0'; while ((c=getchar())>='0' && c<='9'); return s*t;

}



int L[2005];

int main ()

{

	int n = qread();

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

		cin >> L[i];

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

	int cnt = 0;

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

	{

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

		{

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

			int tot = lower_bound( L+1 , L+n+1 , d ) - L -1 ;

			cnt += tot-j;

			if ( d == L[tot] )	cnt--;

		}

	}

	cout << cnt << endl;

}

// Optimized solution to the same problem (faster):
#include<cstring>

#include<algorithm>

#include<cstdio>

#define N 20005



using namespace std;

int a[N],n;

bool cmp(int a,int b){

return a>b;

}



int sol(int x,int y,int l,int r){

if(l==r){

if(y+a[l]>x)return l;

else return -1;

}

int md=(l+r)/2;

if(y+a[md+1]<=x)return sol(x,y,l,md);

else return sol(x,y,md+1,r);

}

int main(){

scanf("%d",&n);

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

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

}

sort(a+1,a+n+1,cmp);

long long int ans=0;

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

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

int as=sol(a[i],a[j],j+1,n);

if(as>j)ans+=(long long int )(as-j);

}

}

printf("%lld",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int p(int a,int b,int c){

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

            return 1;

        }

    return 0;

}

    

int main(){

    int n,a[100001];

    cin>>n;

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

        cin>>a[i];

    }

    int ans=0;

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

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

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

            int it=lower_bound(a+1, a+n+1, a[i]+a[j])-a-2;

            if(it-j+1>0){

                ans+=it-j+1;

            }

        }

    }

    cout<<ans;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int n,ans;

int a[2005]; 

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;++i)scanf("%d",a+i);

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

//	int d=unique(a+1,a+n+1)-a-1; 

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

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

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

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

	else break;

//	if(ans==0) puts("No triangles can be formed."); 

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

	return 0;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

} 

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<vector>

#include<queue>

#include<stack>

#include<cmath>

#include<set>

#include<map>

using namespace std;

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

#define per(i,a,n) for (int i=n-1;i>=a;i--)

#define pb push_back

#define fi first

#define se second

#define dbg(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<endl;

typedef vector<int> VI;

typedef long long ll;

typedef pair<double,int> PII;

const ll p=998244353;

const ll mod=1e9+7;

const int maxn=1e5+100;

map<ll,int> mp;



struct node

{

    int to,next;

}e[maxn*2];



int tol=0;

int head[maxn];

void add(int u,int v)

{

    e[++tol].to=v,e[tol].next=head[u],head[u]=tol;

}

ll dfs(int u,int f)

{

    ll ans=1;

    for(int i=head[u];i;i=e[i].next)

    {

        int v=e[i].to;

        if(v==f) continue;

        ans=(ans+dfs(v,u)*mod%p)%p;

    }

    mp[ans]++;

    return ans;

}





int main()

{

    int n;

    scanf("%d",&n);

    rep(i,1,n)

    {

        int u,v;

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

        add(u,v),add(v,u);

    }

    mp.clear();

    dfs(1,0);

    ll ans=0;

    map<ll,int>::iterator it;

    for(it=mp.begin();it!=mp.end();it++) ans+=1ll*(it->se)*(it->se-1)/2;

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

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<vector>

#include<queue>

#include<stack>

#include<cmath>

#include<set>

#include<map>

using namespace std;

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

#define per(i,a,n) for (int i=n-1;i>=a;i--)

#define pb push_back

#define fi first

#define se second

#define dbg(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<endl;

typedef vector<int> VI;

typedef long long ll;

typedef pair<double,int> PII;

const ll p=998244353;

const ll mod=1e9+7;

const int maxn=1e5+100;

map<ll,int> mp;



struct node

{

    int to,next;

}e[maxn*2];



int tol=0;

int head[maxn];

void add(int u,int v)

{

    e[++tol].to=v,e[tol].next=head[u],head[u]=tol;

}

ll dfs(int u,int f)

{

    ll ans=1;

    for(int i=head[u];i;i=e[i].next)

    {

        int v=e[i].to;

        if(v==f) continue;

        ans=(ans+dfs(v,u)*mod%p)%p;

    }

    mp[ans]++;

    return ans;

}





int main()

{

    int n;

    scanf("%d",&n);

    rep(i,1,n)

    {

        int u,v;

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

        add(u,v),add(v,u);

    }

    mp.clear();

    dfs(1,0);

    ll ans=0;

    map<ll,int>::iterator it;

    for(it=mp.begin();it!=mp.end();it++) ans+=1ll*(it->se)*(it->se-1)/2;

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

    return 0;

}

// Fastest known solution for this problem: