Example

Input

5
1 2
1 3
1 4
1 5


Output

6
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int n;
vector<vi> tree;
ll hs[111111];
ll r = 456789065ll;

ll get_hash(int v)
{
	ll tmp = 0;
	for (auto u : tree[v])
	{
		tmp += get_hash(u) * r;
	}
	tmp += tree[v].size() * r;
	return hs[v] = tmp;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> n;
	tree.resize(n);
	REP(i, n - 1)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
	}
	get_hash(0);
	map<ll, ll> mp;
	REP(i, n)
	{
		mp[hs[i]]++;
	}
	ll ans = 0;
	for (auto i : mp)
	{
		ans += i.second * (i.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}