#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
const int N=2e5+10;
vector<int> e[N];
int fa[N], deg[N], cnt[10];
vector<int> cycle;
void dfs(int u){
for(auto v:e[u]){
if(v==fa[u])continue;
if(fa[v]!=-1){
if(cycle.size())continue;
int x=u;
// cerr << "S:" << v << '\n';
cycle.push_back(v);
while(x!=v){
// cerr << x << '\n';
// Sleep(1000);
cycle.push_back(x);
x=fa[x];
}
continue;
}
fa[v]=u;
dfs(v);
}
}
int main(){
int n;
cin>>n;
memset(fa,-1,sizeof(fa));
fa[1]=0;
for(int i=1;i<=n;i++){
int x,y;cin>>x>>y;
deg[x]++,deg[y]++;
e[x].push_back(y),e[y].push_back(x);
}
dfs(1);
long long ans=0;
for(int i=1;i<=n;i++){
cnt[deg[i]]++;
}
cycle.push_back(cycle[0]);
for(int i=0; i<cycle.size()-1; i++){
int u=cycle[i], v=cycle[i+1];
cnt[deg[u]]--, cnt[deg[v]]--;
cnt[deg[u]-1]++, cnt[deg[v]-1]++;
if(cnt[5]==0){
ans += cnt[3] + cnt[2] + cnt[1];
}
cnt[deg[u]-1]--, cnt[deg[v]-1]--;
cnt[deg[u]]++, cnt[deg[v]]++;
}
cout << ans << '\n';
return 0;
}