Example

Input

5
1 2
1 3
1 4
1 5


Output

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

const long long M = 9999999999971;
const long long MC = 100013;
const int N = 100010;

map<long long, int> H;
long long pw[N];

int dp[N];
long long sz[N];
vector<int> adj[N];
void dfs(int u, int pr) {
	for (auto v: adj[u]) {
		if (v == pr) continue;
		dp[v] = dp[u] + 1;
		dfs(v, u);
		sz[u] = (sz[u] + sz[v]) % M;
	}
	sz[u] = (sz[u] * MC + 1) % M;
}

int main() {

//	freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	for (int i = 0; i <= 100000; i++) pw[i] = (i == 0) ? 1LL : (pw[i-1] * MC % M);

	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) H[sz[i]] ++;
	long long ans = 0;
	for (auto it: H) {
		int v = it.second;
		ans += 1LL * v * (v-1) / 2;
	}

	cout << ans << endl;

	return 0;
}

