#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int magic = 1000;
int n, lo[maxn], a[maxn], d[maxn], freq[maxn / magic + 1][2 * maxn];
vector<int> hi[maxn];
void update(int idx, int add) {
if (idx % magic > 0) {
int bucket = idx / magic;
int end = min(idx - idx % magic + magic - 1, n);
for (int i = idx; i <= end; i++) {
--freq[bucket][a[i] + maxn];
a[i] += add;
++freq[bucket][a[i] + maxn];
}
idx = end + 1;
}
while (idx <= n) {
d[idx / magic] += add;
idx += magic;
}
}
int query() {
int ret = 0;
for (int i = 0; i * magic <= n; i++) {
ret += freq[i][-d[i] + maxn];
}
return ret;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n - 1; i++) {
int u, v;
scanf("%d%d", &u, &v);
++lo[max(u, v)];
hi[min(u, v)].push_back(max(u, v));
}
a[0] = freq[0][1 + maxn] = 1;
for (int i = 1; i <= n; i++) {
a[i] = a[i - 1] + lo[i] - 1;
++freq[i / magic][a[i] + maxn];
}
long long res = 0;
for (int i = 1; i <= n; i++) {
res += query();
for (int h : hi[i]) {
update(h, -1);
}
update(0, 1);
}
cout << res << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBtYXhuID0gMmU1ICsgNTsKY29uc3QgaW50IG1hZ2ljID0gMTAwMDsKCmludCBuLCBsb1ttYXhuXSwgYVttYXhuXSwgZFttYXhuXSwgZnJlcVttYXhuIC8gbWFnaWMgKyAxXVsyICogbWF4bl07CnZlY3RvcjxpbnQ+IGhpW21heG5dOwoKdm9pZCB1cGRhdGUoaW50IGlkeCwgaW50IGFkZCkgewogICAgaWYgKGlkeCAlIG1hZ2ljID4gMCkgewogICAgICAgIGludCBidWNrZXQgPSBpZHggLyBtYWdpYzsKICAgICAgICBpbnQgZW5kID0gbWluKGlkeCAtIGlkeCAlIG1hZ2ljICsgbWFnaWMgLSAxLCBuKTsKICAgICAgICBmb3IgKGludCBpID0gaWR4OyBpIDw9IGVuZDsgaSsrKSB7CiAgICAgICAgICAgIC0tZnJlcVtidWNrZXRdW2FbaV0gKyBtYXhuXTsKICAgICAgICAgICAgYVtpXSArPSBhZGQ7CiAgICAgICAgICAgICsrZnJlcVtidWNrZXRdW2FbaV0gKyBtYXhuXTsKICAgICAgICB9CiAgICAgICAgaWR4ID0gZW5kICsgMTsKICAgIH0KICAgIHdoaWxlIChpZHggPD0gbikgewogICAgICAgIGRbaWR4IC8gbWFnaWNdICs9IGFkZDsKICAgICAgICBpZHggKz0gbWFnaWM7CiAgICB9Cn0KCmludCBxdWVyeSgpIHsKICAgIGludCByZXQgPSAwOwogICAgZm9yIChpbnQgaSA9IDA7IGkgKiBtYWdpYyA8PSBuOyBpKyspIHsKICAgICAgICByZXQgKz0gZnJlcVtpXVstZFtpXSArIG1heG5dOwogICAgfQogICAgcmV0dXJuIHJldDsKfQoKaW50IG1haW4oKSB7CiAgICBzY2FuZigiJWQiLCAmbik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG4gLSAxOyBpKyspIHsKICAgICAgICBpbnQgdSwgdjsKICAgICAgICBzY2FuZigiJWQlZCIsICZ1LCAmdik7CiAgICAgICAgKytsb1ttYXgodSwgdildOwogICAgICAgIGhpW21pbih1LCB2KV0ucHVzaF9iYWNrKG1heCh1LCB2KSk7CiAgICB9CiAgICBhWzBdID0gZnJlcVswXVsxICsgbWF4bl0gPSAxOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgYVtpXSA9IGFbaSAtIDFdICsgbG9baV0gLSAxOwogICAgICAgICsrZnJlcVtpIC8gbWFnaWNdW2FbaV0gKyBtYXhuXTsKICAgIH0KICAgIGxvbmcgbG9uZyByZXMgPSAwOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgcmVzICs9IHF1ZXJ5KCk7CiAgICAgICAgZm9yIChpbnQgaCA6IGhpW2ldKSB7CiAgICAgICAgICAgIHVwZGF0ZShoLCAtMSk7CiAgICAgICAgfQogICAgICAgIHVwZGF0ZSgwLCAxKTsKICAgIH0KICAgIGNvdXQgPDwgcmVzIDw8ICdcbic7CiAgICByZXR1cm4gMDsKfQo=