#include<bits/stdc++.h>
#define x first
#define y second
#define int long long
using namespace std;
typedef pair<int,int> PII;
const int N = 1e5 + 10;
int n;
int p[N];
PII e[N];
int st[N];
int main(){
cin >> n;
for(int i = 1;i <= n; i ++)
{
int a,b;
cin>>a>>b;
p[a] ++,p[b] ++;
e[i].x = a,e[i].y = b;
}
int cnt = 0,ans = 0;
int flag = 0,cc = 0;
for(int i = 1; i <= n; i ++)
{
//if(p[i] <= 3) cnt ++;
if(p[i] == 4) cc ++,st[i] = 1;
if(p[i] == 5) flag ++;
}
for(int i = 1; i <= n; i ++)
{
int f = flag;
int c = cc;
int a = e[i].x,b = e[i].y;
f -= (p[a] == 5) + (p[b] == 5);
if(p[a] == 1 || p[b] == 1) continue;
int x = p[a] - 1,y = p[b] - 1;
//if()
c -= st[a] + st[b];
int s = n - c - (x == 4) - (y == 4);
// cout<<s<<endl;
if(f == 0)
ans += s;
}
cout<<ans<<endl;
}