#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define S second
#define F first
#define PB push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(),x.end()
#define L(x) 2*x
#define R(x) 2*x+1
#define M(x,y) (x+y)/2
using namespace std;
typedef long long ll;
const int N=1e5+1;
vector<int> co[N];
ll ans=0;
void dfs(int x,int p){
    ans+=sz(co[x])*(sz(co[x])-1)/2;
    for(auto y:co[x]){
        if(y==p)
            continue;
        dfs(y,x);
    }
}
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        co[a].PB(b);
        co[b].PB(a);
    }
    dfs(1,0);
    cout<<ans;
}


#include <iostream>
#include <array>

using namespace std;

int main() {
    int num = 0;
    cin >> num;

    int graph[num-1];
    for(int i = 0; i < num-1;i++){
        graph[i] = 0;
    }

    for(int i = 0; i < num-1;i++){
        int a = 0, b = 0;
        cin >> a >> b;
        graph[a-1]++;
        graph[b-1]++;
    }

    int results = 0;
    for(int i = 0; i < num-1; i++){
        int val = (graph[i])-1;
     //   cout << val << endl;
        results += ((val*(val+1))/2);
    }

    cout << results << endl;

    return 0;
}


#include <iostream>
#include <array>

using namespace std;

int main() {
    int num = 0;
    cin >> num;

    int graph[num-1];
    for(int i = 0; i < num-1;i++){
        graph[i] = 0;
    }

    for(int i = 0; i < num-1;i++){
        int a = 0, b = 0;
        cin >> a >> b;
        graph[a-1]++;
        graph[b-1]++;
    }

    long results = 0;
    for(int i = 0; i < num-1; i++){
        long val = (graph[i])-1;
     //   cout << val << endl;
        results += ((val*(val+1l))/2l);
    }

    cout << results << endl;

    return 0;
}


#include <iostream>
#include <array>

using namespace std;

int main() {
    int num = 0;
    cin >> num;

    int graph[num];
    for(int i = 0; i < num-1;i++){
        graph[i] = 0;
    }

    for(int i = 0; i < num-1;i++){
        int a = 0, b = 0;
        cin >> a >> b;
        graph[a-1]++;
        graph[b-1]++;
    }

    int results = 0;
    for(int i = 0; i < num-1; i++){
        int val = (graph[i])-1;
     //   cout << val << endl;
        results += (val*(val+1))/2;
    }

    cout << results << endl;

    return 0;
}


#include <iostream>
#include <array>

using namespace std;

int main() {
    int num = 0;
    cin >> num;

    int graph[num];
    for(int i = 0; i < num;i++){
        graph[i] = 0;
    }

    for(int i = 0; i < num-1;i++){
        int a = 0, b = 0;
        cin >> a >> b;

        graph[a-1]++;
        graph[b-1]++;
    }

    long results = 0;
    for(int i = 0; i < num; i++){
        long val = (graph[i])-1;

     for (int j = 0; j <= val; j++){
         results += j;
     }
    }

    cout << results << endl;

    return 0;
}


#include <iostream>
#include <array>

using namespace std;

int main() {
    int num = 0;
    cin >> num;

    int graph[num-1];
    for(int i = 0; i < num-1;i++){
        graph[i] = 0;
    }

    for(int i = 0; i < num-1;i++){
        int a = 0, b = 0;
        cin >> a >> b;
        graph[a-1]++;
        graph[b-1]++;
    }

    long results = 0;
    for(int i = 0; i < num-1; i++){
        long val = (graph[i])-1;
     //   cout << val << endl;

     long sum = 0;
     for (int j = 0; j <= val; j++){
         sum += j;
     }
        results += sum;
    }

    cout << results << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, res = 0;
    cin >> n;
    n = n*2 - 2;
    vector<int> v(n);
    for (int i = 0; i < n; ++i)
        cin >> v[i];
    sort(begin(v), end(v));
    for (int i = 0; i < n;) {
        int cnt = distance(begin(v) + i, upper_bound(begin(v) + i, end(v), v[i]));
        res += cnt * (cnt - 1) / 2;
        i += cnt;
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

int main() {
	int n;
	cin >> n;

	int deg[n + 1];
	memset(deg, 0, sizeof(deg));
	int v, u;
	for (int i = 0; i < n - 1; i++) {
		cin >> v >> u;
		deg[v] ++;
		deg[u] ++;
	}

	int p2 = 0;
	for (int i = 1; i <= n; i++) {
		p2 += deg[i] * (deg[i] - 1) / 2;
	}

	cout << p2 << endl;

	return 0;
}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

int n, deg[10005];
long long ans;

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		deg[u]++, deg[v]++;
	}
	for (int i = n; i; i--)
		ans += (deg[i] - 1LL) * deg[i] / 2;
	cout << ans;
}


#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

const int MAX = 10000;

int degree[MAX] = {0};

int main() {

	int n;

	// read input
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int from, to;
		cin >> from >> to;
		from--;
		to--;
		degree[from]++;
		degree[to]++;
	}

	int count = 0;
	for (int i = 0; i < n; i++) {
		count += (degree[i] * (degree[i] - 1)) / 2;
	}

	cout << count << endl;

	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
typedef long long ld;
#define re return(0);
#define ce continue;
using namespace std;
vector<int> g[100005];
vector<bool> vis(100005,false);
int ans=0;
void dfs(int start,int s)
{
	vis[start]=true;
	if(s==2)
	{
		ans++;
		return;
	}
	for(auto to:g[start])
	{
		if(vis[to]==false)
		{
			dfs(to,s+1);
		}
	}
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
    	int x,y;
    	cin>>x>>y;
    	g[x].push_back(y);
    	g[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=n;j++)
    	vis[j]=false;
    	dfs(i,0);
    }
    cout<<ans/2;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> iPair;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define rep1(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep1(i, 0, n)
#define sc(n) scanf("%d",&n)
#define sout(n) printf("%s\n",n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007
#define int long long int
int pwr(int base,int p){
int ans = 1;while(p){if(p&1)ans=((ans%mod)*(base%mod))%mod;base=((base%mod)*(base%mod))%mod;p/=2;}return ans;
}
int gcd(int a, int b){
      if(b == 0)  return a;
    return gcd(b, a%b);
}
int powr(int base, int p){
int ans = 1;while(p){if(p&1)ans=(ans*base);base=(base*base);p/=2;}return ans;
}
int dx[] = {1,-1,0,0,1,1,-1,-1};
int dy[] = {0,0,1,-1,1,-1,1,-1};
#define N 20005

vector<int> g[N];
int ch[N];
int ans = 0;

void dfs(int c,int p){
    ch[c] = 0;
    int l = g[c].size();
    rep(i,l){
        int v = g[c][i];
        if(v == p)
            continue;
        dfs(v,c);
        ch[c]+=1;
        ans+=ch[v];
    }
    ans+=(ch[c] * (ch[c]-1))/2;
}

main(){
   #ifndef ONLINE_JUDGE
        freopen("int.txt", "r", stdin);
        freopen("out1.txt", "w", stdout);
    #endif

    int n;
    sll(n);
    rep(i,n-1){
        int x,y;
        sll(x);sll(y);
        g[x].PB(y);
        g[y].PB(x);
    }
    dfs(1,0);
    cout<<ans<<endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-18
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define MAX 10005
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"yes" : "no");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    x+=y; if (x>=mod) x-=mod;
}
void et() {
    puts("-1"); exit(0);
}

vector<int> mp[MAX];
void fmain() {
    scanf("%d", &n);
    readmp(n-1); ll ans=0;
    REQ(i,n) {
        ll N = mp[i].size();
        ans += N*(N-1)/2;
    }
    printf("%lld\n", ans);
}
int main() {
    fmain();
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,a,b; cin>>n;
	map<int,int> deg;
	for (int i=0; i<n-1; i++)
		cin>>a>>b,
		deg[a]++, deg[b]++;
	int ret=0;
	for (auto it : deg) {
		int cur=it.second;
		ret+=cur*(cur-1)/2;
	}
	cout << ret << endl;
	return 0;
}


/**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
#define set_vect(a,n); vector<int>a(n); for(auto &z : a)cin>>z;
#define db(x) cerr << #x << " = "  << (x) << ' ';
const int nmax = 10005;

int n,cnt;
vector <int> a[nmax];
void solve(){
    cin >> n;
    for(int i = 1 ; i < n ; i++){
        int x,y;
        cin >> x >> y; --x;--y;
        a[x].push_back(y);
    }
    for(int i = 0 ; i < n ; i++){
        cnt += a[i].size();
    }
    cout << cnt;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);

    int t = 1; //cin >> t;
    while(t--){solve();}
    return 0;
}

// Code By Pain (Bao Trung)


/**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
#define set_vect(a,n); vector<int>a(n); for(auto &z : a)cin>>z;
#define db(x) cerr << #x << " = "  << (x) << ' ';
const int nmax = 10005;

int n,cnt;
vector <int> a[nmax];
void solve(){
    cin >> n;
    for(int i = 1 ; i < n ; i++){
        int x,y;
        cin >> x >> y; --x;--y;
        //db(x);
        a[x].push_back(y);
        a[y].push_back(x);
    }
    for(int i = 0 ; i < n ; i++){
        int c = a[i].size();
        cnt += (c * (c - 1) / 2);
    }
    cout << cnt;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);

    int t = 1; //cin >> t;
    while(t--){solve();}
    return 0;
}

// Code By Pain (Bao Trung)


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

void solve(){
//    time_t start, end;
//
//    time(&start);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x,y,count=0;
    cin>>n;
    vector<vector<int> > v;
    v.resize(n+1);
    for(int i=0;i<n-1;i++){
        cin>>x>>y;
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);

    }
    for(int i=0;i<n;i++){
        for(int j=0;j<v[i].size();j++){
            int d = v[i][j];
            for(int k=0;k<v[d].size();k++){
                if(v[d][k]!=i) count++;
            }
        }
    }
    cout<<count/2;

    //cout<<endl;
//    time(&end);
//    double time_taken = double(end - start);
//    cout << "Time taken by program is : " << fixed
//         << time_taken << setprecision(5);
//    cout << " sec " << endl;

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t;
    t=1;
    //cin>>t;

    while(t--){
        solve();
        }

   }


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

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<pair<long double, int> , null_type,less<pair<long double, int> >, rb_tree_tag,tree_order_statistics_node_update>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int inf = int(1e9);
const ll INF = ll(1e16);
const int mod = inf + 7;
const double PI = acos(-1.0);
void mul(ll &x, ll y){
  x *= y;
  if(x >= mod) x %= mod;
}
ll bp(ll a, ll n){
  ll r = 1;
  while(n){
    if(n & 1) mul(r, a);
    mul(a, a);
    n >>= 1;
  }
  return r;
}
template<typename T_vector> // neal
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());

    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
const int N = 1e4 + 1;
ll res;
int cnt[N];
void solve(){
    int n;
    cin >> n;
    rep(i, n - 1){
      int l, r;
      cin >> l >> r;
      res += cnt[l] + cnt[r];
      cnt[l]++;
      cnt[r]++;
    }
    cout << res;

}

int main()
{
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    Red;
    int T = 1;
    // cin >> T;
    for(int i = 1; i <= T; ++i){
      solve();
    }
    return 0;

}


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

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define setp(x) fixed << setprecision(x)
#define ordered_set tree<pair<long double, int> , null_type,less<pair<long double, int> >, rb_tree_tag,tree_order_statistics_node_update>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int inf = int(1e9);
const ll INF = ll(1e16);
const int mod = inf + 7;
const double PI = acos(-1.0);
void mul(ll &x, ll y){
  x *= y;
  if(x >= mod) x %= mod;
}
ll bp(ll a, ll n){
  ll r = 1;
  while(n){
    if(n & 1) mul(r, a);
    mul(a, a);
    n >>= 1;
  }
  return r;
}
template<typename T_vector> // neal
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());

    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
const int N = 1e4 + 1;
int p[N];
int get(int v){
  return v == p[v] ? v : p[v] = get(p[v]);
}
vector<int> g[N];
void solve(){
  int n;
  cin >> n;
  cout << n - 1;
}

int main()
{
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    Red;
    int T = 1;
    // cin >> T;
    for(int i = 1; i <= T; ++i){
      solve();
    }
    return 0;

}


/* created   : 2019-08-22 19:31:24
 * accepted  : 2019-08-22 23:57:31
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n;
  cin >> n;
  vector<vector<int>> g(n), b(n);
  map<int, int> pr;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    if (u > v) {
      swap(u, v);
    }
    g[u].push_back(v);
    b[v].push_back(u);
    pr[v] = u;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += b[pr[i]].size();
  }
  for (int i = 0; i < n; i++) {
    int x = g[i].size();
    ans += x * (x - 1) / 2;
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


/* created   : 2019-08-22 19:31:24
 * accepted  : 2019-08-22 23:55:24
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n;
  cin >> n;
  vector<vector<int>> g(n), b(n);
  map<int, int> pr;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    b[v].push_back(u);
    pr[v] = u;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += b[pr[i]].size();
  }
  for (int i = 0; i < n; i++) {
    int x = g[i].size();
    ans += x * (x - 1) / 2;
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


/* created   : 2019-08-22 19:31:24
 * accepted  : 2019-08-22 19:36:43
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

const int N = 1e5;
vector<int> g[N];

int dfs(int u) {
  int ret = g[u].size();
  for (auto v : g[u]) {
    ret += dfs(v);
  }
  return ret;
}

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
  }
  cout << dfs(0) << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


/* created   : 2019-08-22 19:31:24
 * accepted  : 2019-08-23 00:12:51
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

const int N = 1e5;
vector<int> g[N];
int fd[N];
int bk[N];
map<int, int> pr;

void dfs(int u, int par=-1) {
  for (auto v : g[u]) {
    if (v != par) {
      pr[v] = u;
      bk[v]++;
      fd[u]++;
      dfs(v, u);
    }
  }
}

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0);
  trace(pr);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += bk[pr[i]];
  }
  for (int i = 0; i < n; i++) {
    int x = fd[i];
    ans += x * (x - 1) / 2;
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define boost ios::sync_with_stdio(false); cin.tie(nullptr);
#define MOD 1000000007
#define sd(x) scanf("%d", &(x))
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ones(x) __builtin_popcount(x)
#define sz(x) int (x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define f1(i,a,b) for(int i=a; i<=b; i++)
#define rep(i,a,b) for(int i=a; i<b; i++)
#define NFOR(i,a,b) for(int i=(a);i>=(b);--i)

using ll = unsigned long long ;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef double ld;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}

#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif

auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

int f(int n){
	int t=n;
	t*=(n-1);
	return (t>>1);
}

const int maxn = 10001;

int deg[maxn];
void solve(){
	int n ;
	cin>>n;
	rep(i,1,n){
		int a , b;
		cin>>a>>b;
		deg[a]++;deg[b]++;
	}
	int u = 0 ;
	rep(i,1,n+1){
		u+=f(deg[i]);
	}
	cout<<u<<endl;

}

signed main(){
	int T =1 ;
	//sd(T);
	while(T--){
		solve();
	}

#ifdef np
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main ()

{
    int n, x, y, tree[100005], cnt = 0;
    cin >> n;
    for ( int i = 1; i < n; i++ )
    {
        cin >> x >> y;
        tree[x]++, tree[y]++;
    }
    for ( int i = 1; i <= n; i++ )
        cnt += tree[i]*(tree[i]-1)/2;
    cout << cnt << endl;
}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS // - for VisualStudio: do not disturb about warnings
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>

using namespace std;
#define open_streams ifstream fin("longpath.in");ofstream fout("longpath.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define pus system("pause");
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define eps 1e-9
const double PI = M_PI;
const int INF = -1 * 1e9;
const ll limit = -1 * 1e16;
const int MOD1 = 1e9 + 711;
const int MOD2 = 1e9 + 933;
const int MOD3 = 1e9 + 993;

const int maxn = 1e6 + 100;

int main() {
	speed;
	int n;
	cin >> n;
	vector<vector<int>> g(n + 1, vector<int>());
	for (int i = 0; i < n-1; ++i) {
		int v, u;
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	cout << n - 1;
	cerr << "\n\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS // - for VisualStudio: do not disturb about warnings
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>

using namespace std;
#define open_streams ifstream fin("longpath.in");ofstream fout("longpath.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define pus system("pause");
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define eps 1e-9
const double PI = M_PI;
const int INF = -1 * 1e9;
const ll limit = -1 * 1e16;
const int MOD1 = 1e9 + 711;
const int MOD2 = 1e9 + 933;
const int MOD3 = 1e9 + 993;

const int maxn = 1e6 + 100;

int main() {
	speed;
	int n;
	cin >> n;
	vector<vector<int>> g(n + 1, vector<int>());
	for (int i = 0; i < n-1; ++i) {
		int v, u;
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	cout << 1LL * n * (n - 1) / 4;
	cerr << "\n\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS // - for VisualStudio: do not disturb about warnings
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>

using namespace std;
#define open_streams ifstream fin("longpath.in");ofstream fout("longpath.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define pus system("pause");
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define eps 1e-9
const double PI = M_PI;
const int INF = -1 * 1e9;
const ll limit = -1 * 1e16;
const int MOD1 = 1e9 + 711;
const int MOD2 = 1e9 + 933;
const int MOD3 = 1e9 + 993;

const int maxn = 1e6 + 100;

int main() {
	speed;
	int n;
	cin >> n;
	vector<vector<int>> g(n + 1, vector<int>());
	for (int i = 0; i < n-1; ++i) {
		int v, u;
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < g[i].size(); ++j) {
			sum += g[g[i][j]].size() - 1;
		}
	}
	cout << sum / 2;
	cerr << "\n\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


/*--------------------------------------------*\
 * @ mdjobayairhossain2020
 * Author : MD. JOBAYAIR HOSSAIN
 * Created: September/18/2020  15:16:56(UTC+6)
-*--------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);

    int Nodes, Count = 0;
    cin>>Nodes;
    vector<int> Graph[Nodes];
    vector<int>::iterator It;
    for(int i=0; i<(Nodes-1); i++){
        int node_01, node_02;
        cin>>node_01>>node_02;
        Graph[(node_01-1)].push_back(node_02-1);
        Graph[(node_02-1)].push_back(node_01-1);
    }

    for(int x=0; x<Nodes; x++){
        if(Graph[x].empty() == false){
            for(It = Graph[x].begin(); It != Graph[x].end(); It++){
                Count += (Graph[*It].size()-1); // 'x' is parent of '*It'
            }
        }
    }cout<<(Count / 2)<<"\n";

    return 0;
}
 // find all possible paths of length 2
// This is an Undirected-Graph that's why a path of length 2 will appear 2 times.


//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=1000000000000000000;
int power(int a, int b)
    {
        if(a==0)
        return 0;
        int res=1;
        while(b>0)
        {
            if(b&1)
            res=(res*a);
            b>>=1;
            a=(a*a);
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n,ans=0;
    cin>>n;
    vi v[N];
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    for(int i=1;i<=n;i++)
    {
        int l=v[i].size();
        for(int j=0;j<l;j++)
        ans+=(v[v[i][j]].size()-1);
    }
    cout<<ans/2;
}


//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=1000000000000000000;
int power(int a, int b)
    {
        if(a==0)
        return 0;
        int res=1;
        while(b>0)
        {
            if(b&1)
            res=(res*a);
            b>>=1;
            a=(a*a);
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
    }
    cout<<n-1;
}


/*
          _____       __   __   __      __                  __
         |     \     |  | |  | |  |    |  |       /\       |  |
         |  |\  \    |  | |  | |  |    |  |      /  \      |  |
         |  | \  \   |  | |  | |  |____|  |     / /\ \     |  |
         |  |  \  \  |  | |  | |   ____   |    / /__\ \    |  |
         |  |   \  \ |  | |  | |  |    |  |   / ______ \   |  |
         |  |    \  \|  | |  | |  |    |  |  / /      \ \  |  |_________
         |__|     \_____| |__| |__|    |__| /_/        \_\ |____________|
*/
#include <bits/stdc++.h>
/*---------------------------------PB_DS---------------------------------*/
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// #define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k) = returns an iterator to the k-th largest element (counting from zero)
// order_of_key(k) = the number of items in a set that are strictly smaller than k.
/*-----------------------------------------------------------------------*/
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define MEM(a,b)            memset(a, (b), sizeof(a))
#define sfc(a)              scanf("%c",&a)
#define pb(a)               push_back(a)
#define X                   first
#define Y                   second
#define sz(x)               x.size()
#define pii                 pair<int,int>
#define pli                 pair<long long int,int>
#define mp(a,b)             make_pair(a,b)
#define fr(i,x,n)           for(int i=x;i<n;i++)
#define rfr(i,x,n)          for(int i=x;i>n;i--)
#define LCM(a, b)           ((a)*((b)/GCD(a,b)))
template<typename T>T Abs(T a){return (a<0?-a:a);}
template<typename T>T MAX(T a, T b){return (a>b?a:b);}
template<typename T>T MIN(T a, T b){return (a<b?a:b);}
template<typename T>T GCD(T a, T b){if(b==0)return a;return GCD(b,a%b);}
template<typename T>inline void read(T &x){
    T f=1;char c;x=0;
    for(c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
    for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
    x*=f;
}
using fl = float;
using db = double;
using ll = long long;
using ull = unsigned long long;
const int mx = 1000005;
const int inf = 99999999;
const int intlim = 2147483648;
const db PI = acos(-1); //3.14159265358979323846264338328
/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};           // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};          // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
using namespace std;
std::vector<int> v[10010];
int main() {
    int n;
    sf(n);
    for (int i = 0; i < n-1; ++i)
    {
        int a, b;
        sff(a,b);
        v[a].pb(b);
        v[b].pb(a);
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        if(sz(v[i])>=1){
            ans+=(sz(v[i])*(sz(v[i])-1)/2);
            // cout<<i<<endl;
            // cout<<(sz(v[i])*(sz(v[i])-1)/2)<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#define X first
#define Y second
#define debug(x) cerr << #x << ": " << x << endl;
#define ll long long int
#define endl '\n'
#define mp make_pair
#define pb push_back
#define rep(i,l,r) for (int i=l; i<r; i++)
#define repr(i,r,l) for (int i=r; i>=l; i--)
using namespace std;
const long long int N=1e6+30,mod = 998244353;
ll ans=0;
vector <vector<int> > adj;
void dfs(int v,int par, int len){
    if (len > 1) return;
    for (int u : adj[v]){
        if (u != par){
            if (len == 1) ans++;
            dfs(u,v,len+1);
        }
    }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    adj.resize(n);
    rep (i,0,n-1){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    rep(i,0,n) dfs(i,-1,0);
    cout << ans/2;

}


#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#define X first
#define Y second
#define debug(x) cerr << #x << ": " << x << endl;
#define ll long long int
#define endl '\n'
#define mp make_pair
#define pb push_back
#define rep(i,l,r) for (ll i=l; i<r; i++)
#define repr(i,r,l) for (ll i=r; i>=l; i--)
using namespace std;
const long long int N=1e6+30,mod = 998244353;
ll ans=0;
vector <vector<ll> > adj;
void dfs(ll v,ll par, ll len){
    for (ll u : adj[v]){
        if (u != par){
            if (len == 1) ans++;
            dfs(u,v,len+1);
        }
    }
}
int main(){
    ll n;
    cin >> n;
    adj.resize(n);
    rep (i,0,n-1){
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    rep(i,0,n) dfs(i,-1,0);
    cout << ans/2;

}


#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#define X first
#define Y second
#define debug(x) cerr << #x << ": " << x << endl;
#define ll long long int
#define endl '\n'
#define mp make_pair
#define pb push_back
#define rep(i,l,r) for (int i=l; i<r; i++)
#define repr(i,r,l) for (int i=r; i>=l; i--)
using namespace std;
const long long int N=1e6+30,mod = 998244353;
ll ans=0;
vector <vector<int> > adj;
void dfs(int v,int par, int len){
    for (int u : adj[v]){
        if (u != par){
            if (len == 1) ans++;
            dfs(u,v,len+1);
        }
    }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    adj.resize(n);
    rep (i,0,n-1){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    rep(i,0,n) dfs(i,-1,0);
    cout << ans/2;

}


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

vector <int> adj[200 * 1000];

int main () {
    int n , m , ans = 0;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a , b;
        cin >> a >> b;
        adj[a].push_back(b) , adj[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < adj[i].size(); j++) {
            int a = adj[i][j];
            if (adj[a].size() > 1)
                ans += adj[a].size() - 1;
        }
    }
    cout << ans / 2;
    return 0;
}


//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 1000001
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define f0(s,a,b) for(lli s=a;s<b;s++)
#define f1(s,a,b) for(lli s=a;s<=b;s++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define print(x) cout<< #x <<"=" <<x<<"\n";
#define out(x) cout<<x;
#define  Y cout<<"yes\n";
#define N cout<<"no\n";
vector<lli> adj[100001],vis(100001),deg(100001);
void dfs(lli v)
{
    vis[v]=1;

    for(auto i:adj[v])
    {
        deg[i]++;
        if(vis[i]==0)
        {
            dfs(i);
        }
    }
}
int main()
{
    fast
    lli n;
    cin>>n;
    for(lli i=1;i<=n-1;i++)
    {
        lli u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1);
    lli sum=0;
    for(lli i=1;i<=n;i++)
    {
        sum=sum+((deg[i])*(deg[i]-1))/2;
    }
    cout<<sum;
}
//a+b=a⊕b+2∗(a &b)
//__builtin_popcount(number)
//cout<<fixed<<setpricision(8)<<output<<"\n";


//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 1000001
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define f0(s,a,b) for(lli s=a;s<b;s++)
#define f1(s,a,b) for(lli s=a;s<=b;s++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define print(x) cout<< #x <<"=" <<x<<"\n";
#define out(x) cout<<x;
#define  Y cout<<"yes\n";
#define N cout<<"no\n";
vector<lli> adj[100001],vis(100001),deg(100001);
void dfs(lli v)
{
    vis[v]=1;

    for(auto i:adj[v])
    {
        deg[i]++;
        if(vis[i]==0)
        {
            dfs(i);
        }
    }
}
int main()
{
    fast
    lli n,m;
    cin>>n>>m;
    for(lli i=1;i<=m;i++)
    {
        lli u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1);
    lli sum=0;
    for(lli i=1;i<=n;i++)
    {
        sum=sum+((deg[i])*(deg[i]-1))/2;
    }
    cout<<sum;
}
//a+b=a⊕b+2∗(a &b)
//__builtin_popcount(number)
//cout<<fixed<<setpricision(8)<<output<<"\n";


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;          cin>>n;
    vector<int> g[n+1];
    for(auto i=0;i<n-1;++i){
        int a,b;        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans=0;
    for(auto i=1;i<=n;++i){
        int sz=g[i].size();
        ans+=sz*(sz-1)/2;

    }
    cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e4;

int n, d[maxn], cnt, v, u;

int main(){
    cin >> n;
    for(int i = 0; i < n - 1; i ++){
        cin >> v >> u;
        d[v] ++;
        d[u] ++;
    }
    for(int i = 1; i <= n; i ++)
        cnt += d[i] * (d[i] - 1) / 2;
    cout << cnt;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, a, b;
	cin >> n;
	vector<int> graph[n + 2];
	for(int i = 0;i < n - 1; i ++){
		cin >> a >> b;
			graph[a].push_back(b);
			graph[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < n + 1; i ++){
		for (int j : graph[i])
			ans += graph[j].size() - 1;
	}
	ans /= 2;
	cout << ans << endl;
}


/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n;
    R(n);
    VI cnt(n);
    REPP(i,1,n){
        int x,y;
        R(x,y);
        x--;y--;
        cnt[x]++;
        cnt[y]++;
    }
    LL an=0;
    REP(i,n)an+=(cnt[i]-1LL)*cnt[i]/2;
    W(an);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector<vector<int>> v;
vector<bool> vi;
int ans=0;
void dfs(int r,int c)
{
 if(vi[r])
 return;
 vi[r]=true;
 ans+=c;
 for(int i=0;i<(int)(v[r].size());i++)
 {
  if(!vi[v[r][i]])
  dfs(v[r][i],(c+1)%2);
 }
}
int main(void){
    // Your code here!
 int n,t,x,y;
 cin >> n;
 v.resize(n);
 vi.resize(n,false);
 t=n-1;
 while(t--)
 {
  cin >> x >> y;
  x--;
  y--;
  v[x].pb(y);
  v[y].pb(x);
 }
 dfs(0,0);
 cout << ((ans*(ans-1))/2)+(((n-ans)*(n-ans-1))/2);
 return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int main(void){
    // Your code here!
 int i,ans,n,t,x,y;
 ans=0;
 cin >> n;
 t=n-1;
 map<int,int> v;
 while(t--)
 {
  cin >> x >> y;
  x--;
  y--;
  v[x]++;
  v[y]++;
 }
 for(i=0;i<n;i++)
 ans+=(v[i]*(v[i]-1))/2;
 cout << ans;
 return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector<vector<int>> v;
vector<bool> vi;
map<int,int> m;
void dfs(int r,int c)
{
 if(vi[r])
 return;
 vi[r]=true;
 m[c]++;
 for(int i=0;i<(int)(v[r].size());i++)
 {
  if(!vi[v[r][i]])
  dfs(v[r][i],c+1);
 }
}
int main(void){
    // Your code here!
 int ans,n,t,x,y;
 ans=0;
 cin >> n;
 v.resize(n);
 vi.resize(n,false);
 t=n-1;
 while(t--)
 {
  cin >> x >> y;
  x--;
  y--;
  v[x].pb(y);
  v[y].pb(x);
 }
 dfs(0,0);
 x=0;
 for(auto it:m)
 ans+=((it.second)*(it.second-1))/2;
 while(m.find(x+2)!=m.end())
 {
  ans+=m[x]*m[x+2];
  x++;
 }
 cout << ans;
 return 0;
}


/* In the name of Allah */
#include <bits/stdc++.h>
using namespace std;

const int MAX = 10 * 1000 + 10;
vector <int> adj[MAX];
int n, ans;

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (int i = 1; i <= n; i++) {
		int vz = adj[i].size();
		for (int j = 0; j < vz; j++)
			ans += (adj[adj[i][j]].size()) - 1;
	}
	cout << ans / 2 << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int calculate(int x){
    if(x == 1){
        return 0;
    }
    else{
        return x*(x-1)/2;
    }
}

int main(){

    int n;
    cin >> n;
    int array[n+1] = {0};
    for(int i = 0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        array[x]++;
        array[y]++;
    }
    int sum = 0;
    for(int i = 1;i<=n;i++){
        sum += calculate(array[i]);
    }
    printf("%d\n",sum);

}


#include<bits/stdc++.h>
using namespace std;
const int MAX=1e4 + 10;
typedef long long int ll;
vector<int>g[MAX];
int n,res,nati[MAX];

ll f(ll x)
{
    if(x<=1)return 0;
    return x*(x-1)/2LL;
}

void dfs(int u,int p){
    int child=0;
    for(int v:g[u]){
            if(v==p)continue;
            child++;
            dfs(v , u);
    }
    if(p!=-1)res+=child;
    res+=f(child);
}
int main (){
    cin >> n;
    for(int i=1;i<=n-1;i++){
        int u,v;cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1 , -1);
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define com(i,n)    for(int i=0;i<n;i++)
#define dom(i,n)    for(int i=1;i<=n;i++)
#define mom(i,n)    for(int i=n;i>=0;i--)
#define sortI(a,n)  sort(a,a+n)
#define sortD(a,n)  sort(a,a+n,greater<int>())
using namespace std;
int main()
{
     long long int n,var[10001],ll=0;
     cin>>n;
     com(i,n-1)
     {
          int a,b;
          cin>>a>>b;
          var[a]++;
          var[b]++;
     }
     dom(i,n)
     {
          ll+=(var[i]*(var[i]-1)/2);
     }
     cout << ll << endl;
}


#include<bits/stdc++.h>
#define com(i,n)    for(int i=0;i<n;i++)
#define dom(i,n)    for(int i=1;i<=n;i++)
#define mom(i,n)    for(int i=n;i>=0;i--)
#define sortI(a,n)  sort(a,a+n)
#define sortD(a,n)  sort(a,a+n,greater<int>())
using namespace std;
int main()
{
     int n,var[10001],ll=0;
     cin>>n;
     com(i,n-1)
     {
          int a,b;
          cin>>a>>b;
          var[a]++;
          var[b]++;
     }
     com(i,n+1)
     {
          ll+=(var[i]*(var[i]-1)/2);
     }
     cout << ll << endl;
}


#include<bits/stdc++.h>
#define com(i,n)    for(int i=0;i<n;i++)
#define dom(i,n)    for(int i=1;i<=n;i++)
#define mom(i,n)    for(int i=n;i>=0;i--)
#define sortI(a,n)  sort(a,a+n)
#define sortD(a,n)  sort(a,a+n,greater<int>())
using namespace std;
int main()
{
     long long int n,var[100010],ll=0;
     cin>>n;
     com(i,n-1)
     {
          int a,b;
          cin>>a>>b;
          var[a]++;
          var[b]++;
     }
     dom(i,n)
     {
          ll+=var[i]*(var[i]-1)/2;
     }
     cout << ll << endl;
}


#include<bits/stdc++.h>
#define com(i,n)    for(int i=0;i<n;i++)
#define dom(i,n)    for(int i=1;i<=n;i++)
#define mom(i,n)    for(int i=n;i>=0;i--)
#define sortI(a,n)  sort(a,a+n)
#define sortD(a,n)  sort(a,a+n,greater<int>())
using namespace std;
int main()
{
     long long int n,var[10010],ll=0;
     cin>>n;
     com(i,n-1)
     {
          int a,b;
          cin>>a>>b;
          var[a]++;
          var[b]++;
     }
     dom(i,n)
     {
          ll+=var[i]*(var[i]-1)/2;
     }
     cout << ll << endl;
}


#include<bits/stdc++.h>
#define com(i,n)    for(int i=0;i<n;i++)
#define dom(i,n)    for(int i=1;i<=n;i++)
#define mom(i,n)    for(int i=n;i>=0;i--)
#define sortI(a,n)  sort(a,a+n)
#define sortD(a,n)  sort(a,a+n,greater<int>())
using namespace std;
int main()
{
     long long int n,var[10001],ll=0;
     cin>>n;
     com(i,n-1)
     {
          int a,b;
          cin>>a>>b;
          var[a]++;
          var[b]++;
     }
     com(i,n+1)
     {
          ll+=(var[i]*(var[i]-1)/2);
     }
     cout << ll << endl;
}


#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 3e5 + 5;
const int inf = 1e18;
const int mod = 1e9 + 7;

int n, in[N], ans;

int nC2(int n){
	return n*(n-1)/2;
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE
	freopen("in1.txt","r",stdin);
	freopen("out1.txt","w",stdout);
	#endif

  cin >> n;
  for(int i = 1, u, v; i < n; i++){
  	cin >> u >> v;
  	in[u]++, in[v]++;
  }

  for(int i = 1; i <= n; i++)
  	ans += nC2(in[i]);
  cout << ans << '\n';

}


#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int D[N];

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n;
	cin >> n;

	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		D[x]++; D[y]++;
	}

	LL res = 0;
	for (int i = 1; i <= n; i++) {
		res += D[i] * 1LL * (D[i] - 1) / 2;
	}

	cout << res << endl;
}


#include <iostream>
using namespace std;

int n[10000];
int main() {
	int a, c, d, i, j = 0, m;
	cin >> a;
	for (i = 1; i < a; i++) {
		cin >> c >> d;
		n[c]++;
		n[d]++;
	}
	for (i = 1; i <= a; i++)
		j += n[i]	* (n[i] - 1)  / 2;

	cout << j;

	return 0;
}


#include <iostream>
using namespace std;

int n[10000];
int main() {
	int a, c, d, i, j=0, m;
	cin >> a ;
	for (i=1 ; i<a ; i++){
	cin >> c >> d ;
	n[c]++;
	n[d]++;
}
for (i=1 ; i<=a ; i++)
j += n[i]	* (n[i]-1)  / 2;

	cout << j ;

	return 0;
}


#include <cstring>
#include <cstdio>
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include<cmath>
#include<bits/stdc++.h>
#include<cstring>
#include<string>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1e4+10;
typedef long long ll;
int m,n,vis[maxn];
int fa[maxn],son[maxn];
vector<int>g[maxn];
int ans;
void init()
{
    for(int i=1; i<=n; i++)
    {
        g[i].clear();
        vis[i]=0;
        fa[i]=0;
        son[i]=0;
        fa[i]=1;
    }
}
void dfs(int u)
{
    vis[u]=1;
        int cnt=0;
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if(!vis[v])
        {
            int t=son[u]-1;
            if(!cnt)
                 ans+=(t*t+t)/2;
            ans+=fa[v]*son[v];
            cnt++;
            dfs(v);
        }
    }
}
void dfss(int u)
{
    vis[u]=1;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(!vis[v]){
            son[u]++;
            dfss(v);
        }
    }
}
int main ()
{
    while(~scanf("%d",&n))
    {
        int cnt=0;
        int a,b;
        init();
        for(int i=0; i<n-1; i++)
        {
            scanf("%d%d",&a,&b);
            g[a].push_back(b);
            g[b].push_back(a);
        }
        ans=0;
        dfss(1);
        fa[1]=0;
        memset(vis,0,sizeof(vis));
//        for(int i=1;i<=n;i++)
//            printf ("%d %d \n",fa[i],son[i]);
        dfs(1);
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#pragma GCC optimize ("O3")
using namespace std;
int main () {
    #ifdef LOCAL
        freopen ("input.txt", "r", stdin);
        freopen ("output.txt", "w", stdout);
        freopen ("error.txt", "w", stderr);
    #else
        ios::sync_with_stdio(false);
        cin.tie (NULL);
    #endif

    int n; cin >> n;
    vector <vector <int>> tree (n + 1);
    for (int i = 1; i < n; ++i) {
        int a, b; cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += tree[i].size() * (tree[i].size() - 1) / 2;
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#pragma GCC optimize ("O3")
using namespace std;
vector <vector <int>> tree (10001);
vector <bool> visited (10001, false);
int ans = 0;
void dfs (int a, int b, int deg) {
    if (a == b) {
        ans += (deg == 2 ? 1 : 0);
        return;
    }
    visited[a] = true;
    for (auto &i : tree[a]) {
        if (!visited[i]) dfs(i, b, deg + 1);
    }
}
int main () {
    #ifdef LOCAL
        freopen ("input.txt", "r", stdin);
        freopen ("output.txt", "w", stdout);
        freopen ("error.txt", "w", stderr);
    #else
        ios::sync_with_stdio(false);
        cin.tie (NULL);
    #endif

    int n; cin >> n;

    for (int i = 1; i < n; ++i) {
        int a, b; cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            for (int k = 1; k <= 10001; ++k) visited[k] = false;
            dfs(i, j, 0);
        }
    }

    cout << ans;

    return 0;
}


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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
namespace __gnu_pbds {
    typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;

#define endl '\n'
#define ll long long
#define LSB __builtin_ctzll
#define sc(a) scanf("%d",&a)
#define MSB 63-__builtin_clzll
#define scl(a) scanf("%lld",&a)
#define BITS __builtin_popcountll
#define mem(a , v)  memset(a , v , sizeof(a))
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9+7;
const int MAX = 1e5+55;
const int INF = 1e9+77;
const ll INFINF = 1e18+77;
const double PI = acos(-1.0);

ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         if(y&1)
         s*=x;
         return s;
}

int n,m;
vector<int> adj[11111];
bool vis[11111];
int dis[11111];
ll ans=0;

void DFS(int u){

     vis[u]=1;
     for(auto &vv:adj[u]){
        if(!vis[vv]&&dis[vv]<2){
            dis[vv]=dis[u]+1;
            if(dis[vv]==2){
                ans++;
            }
            DFS(vv);
        }
     }
}

int main(){

ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("digits.in" , "r" , stdin);
//freopen("digits.out" , "w" , stdout);

    cin>>n;
    for(int i=0;i<n-1;i++){

        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        m--;
    }

    for(int i=1;i<=n;i++){
        v.clear();
        DFS(i);
        mem(dis,0);
        mem(vis,0);
    }

    cout<<ans/2;

     return 0;

}


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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
namespace __gnu_pbds {
    typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;

#define endl '\n'
#define ll long long
#define LSB __builtin_ctzll
#define sc(a) scanf("%d",&a)
#define MSB 63-__builtin_clzll
#define scl(a) scanf("%lld",&a)
#define BITS __builtin_popcountll
#define mem(a , v)  memset(a , v , sizeof(a))
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9+7;
const int MAX = 1e5+55;
const int INF = 1e9+77;
const ll INFINF = 1e18+77;
const double PI = acos(-1.0);

ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         if(y&1)
         s*=x;
         return s;
}

int n,m;
vector<int> adj[MAX];

int main(){

ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("digits.in" , "r" , stdin);
//freopen("digits.out" , "w" , stdout);

    cin>>n;
    for(int i=0;i<n-1;i++){

        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        m--;
    }

    ll ans=0;
    for(int i=1;i<=n;i++){
        ll p=adj[i].size();
        ans+=(p*(p-1))/2;
    }

    cout<<ans;

     return 0;

}


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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
namespace __gnu_pbds {
    typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;

#define endl '\n'
#define ll long long
#define LSB __builtin_ctzll
#define sc(a) scanf("%d",&a)
#define MSB 63-__builtin_clzll
#define scl(a) scanf("%lld",&a)
#define BITS __builtin_popcountll
#define mem(a , v)  memset(a , v , sizeof(a))
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9+7;
const int MAX = 1e5+55;
const int INF = 1e9+77;
const ll INFINF = 1e18+77;
const double PI = acos(-1.0);

ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         if(y&1)
         s*=x;
         return s;
}

int n,m;
vector<int> adj[MAX];
bool vis[MAX];
int dis[MAX];
vector<int> v;
ll ans=0;

void DFS(int u){

     vis[u]=1;
     v.push_back(u);
     for(auto &vv:adj[u]){
        if(!vis[vv]&&dis[vv]<2){
            dis[vv]=dis[u]+1;
            if(dis[vv]==2){
                ans++;
            }
            DFS(vv);
        }
     }
}

int main(){

ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("digits.in" , "r" , stdin);
//freopen("digits.out" , "w" , stdout);

    cin>>n;
    for(int i=0;i<n-1;i++){

        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        m--;
    }

    for(int i=1;i<=n;i++){
        v.clear();
        DFS(i);
        for(auto &node:v){
            vis[node]=0;
            dis[node]=0;
        }
    }

    cout<<ans/2;

     return 0;

}


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

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
namespace __gnu_pbds {
    typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;

#define endl '\n'
#define ll long long
#define LSB __builtin_ctzll
#define sc(a) scanf("%d",&a)
#define MSB 63-__builtin_clzll
#define scl(a) scanf("%lld",&a)
#define BITS __builtin_popcountll
#define mem(a , v)  memset(a , v , sizeof(a))
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9+7;
const int MAX = 1e5+55;
const int INF = 1e9+77;
const ll INFINF = 1e18+77;
const double PI = acos(-1.0);

ll power(ll x,ll y){
         if(y==0)
         return 1;
         ll s=power(x,y/2);
         s*=s;
         if(y&1)
         s*=x;
         return s;
}

int n,m;
vector<int> adj[11111];
bool vis[11111];
int dis[11111];
ll ans=0;

void DFS(int u){

     vis[u]=1;
     for(auto &vv:adj[u]){
        if(!vis[vv]&&dis[vv]<2){
            dis[vv]=dis[u]+1;
            if(dis[vv]==2){
                ans++;
            }
            DFS(vv);
        }
     }
}

int main(){

ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("digits.in" , "r" , stdin);
//freopen("digits.out" , "w" , stdout);

    cin>>n;
    for(int i=0;i<n-1;i++){

        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        m--;
    }

    for(int i=1;i<=n;i++){
        DFS(i);
        mem(dis,0);
        mem(vis,0);
    }

    cout<<ans/2;

     return 0;

}


// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define LEN 100005
lld vis[LEN];
lld dfs (vector <lld> V[], lld x)
{
      lld c = 0;
      vis[x]= 1;
      lld count = 0;
      for(lld i = 0; i < V[x].size(); i += 1){
            if (vis[V[x][i]]==-1){
                  c++;
                  count += dfs(V, V[x][i]);
            }
      }
      count  += ((c*(c-1))/2) + c;
      return count;
}
int main ()
{
      #ifndef ONLINE_JUDGE
      freopen("inputf.in",  "r",   stdin);
      freopen("outputf.in", "w",  stdout);
      #endif
      FastIO
      lld n;
      cin >> n;
      vector <lld> V[n+1];
      for(lld i = 0; i < n-1; i += 1){
            lld x, y;
            cin >> x >> y;
            V[x].push_back(y);
            V[y].push_back(x);
      }
      for(lld i = 0; i < LEN; i += 1){
            vis[i] = -1;
      }
      lld count = 0;
      lld c = 0;
      vis[1]= 1;
      for(lld i = 0; i < V[1].size(); i += 1){
            if (vis[V[1][i]]==-1){
                  c++;
                  count += dfs(V, V[1][i]);
            }
      }
      count += (c*(c-1))/2;
      cout << count;
      return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

vector<vector<int>> E;

long long solve() {
    int n = E.size();
    vector<int> A;
    long long ans = 0;
    for (int s = 0; s < n; s++) {
        A.clear();
        for (auto t: E[s]) {
            for (auto u: E[t]) {
                if (u > s) {
                    A.push_back(u);
                }
            }
        }
        sort(A.begin(), A.end());
        A.erase(unique(A.begin(), A.end()), A.end());
        ans += A.size();
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    E.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        E[a-1].push_back(b - 1);
        E[b-1].push_back(a - 1);
    }
    long long ans = solve();
    cout << ans << endl;
    return 0;
}


#include<iostream>
using namespace std;
int n,deg[10010];
long long ans;
int main()
{
	cin>>n;
	for(int i=1;i<n;++i)
	{
		int u,v;
		cin>>u>>v;
		deg[u]++,deg[v]++;
	}
	for(int i=1;i<=n;++i)
		ans+=deg[i]*(deg[i]-1)/2;
	cout<<ans<<endl;
	return 0;
}


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

#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
typedef long long ll;

// Init variables here
const int N = 1e4 + 7;
int n;
vec<int> adj[N];

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);
  scanf("%d", &n);
  FOR(i, 1, n) {
    int u, v; scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
}

void solve() {
  ll res = 0;
  FORE(i, 1, n) {
    ll deg = adj[i].size();
    res += deg * (deg - 1) / 2;
  }
  printf("%lld\n", res);
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--)
  {
    input();
    solve();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


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

#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
typedef long long ll;

// Init variables here
const int N = 1e4 + 7;
int n;
vec<int> adj[N];

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);
  scanf("%d", &n);
  FOR(i, 1, n) {
    int u, v; scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
}

/*
F1 Easy
tag: trees *1400

We are given a tree and are asked to compute the number of paths of length 2.
To this end, we try out all vertices as candidates for the middle-point of the
path. For a fixed vertex, the number of such paths is d * (d − 1) / 2, where d
is the degree of the vertex (the number of its neighbors). We just take a sum
over all vertices.
*/

void solve() {
  ll res = 0;
  FORE(i, 1, n) {
    ll deg = adj[i].size();
    res += deg * (deg - 1) / 2;
  }
  printf("%lld\n", res);
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--)
  {
    input();
    solve();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 1000005;

int d[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;	cin >> n;
	ll ans = 0;
	for(int i = 0; i < 2 * (n - 1); i++){
		int v;	cin >> v;
		d[v]++;
	}
	for(int i = 0; i <= n; i++)
		ans += (d[i] * (d[i] - 1)) / 2;
	cout << ans << "\n";
}


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

const int N = 1000 * 100 + 100;
vector<int> adj[N];
int n;

void read() {
	cin >> n;
	int v, u;
	for (int i = 0; i < n - 1; i++) {
		cin >> v >> u;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read();
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		vector<int> v;
		bool mark[N] = {};
		for (auto it: adj[i])
			v.push_back(it), mark[it] = true;
		for (auto it: v)
			for (auto it1: adj[it])
				if (!mark[it1])
					ans++;
	}
	cout << ans / 4 << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = 2*sz+3;
	int palin[len+1];
	memset(palin, 0, len+1);

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = 0;

	REP(i,1,len-1) {
		if (i+val[i] == len && val[i] > ans) {
			ans = end = val[i];
			st = 0;
		}
	}
	REP(i,1,len-1) {
		if (str[i-1] == str[len-i]) {
			if (ans < 2*i+val[i]) {
				ans = 2*i + val[i];
				st = i+val[i];
				end = i;
			}
		} else {
			break;
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		int curr_val = 2*(i+1) + rval[j-1];
		if (curr_val > ans) {
			ans = curr_val;
			st = i+1;
			end = i+1 + rval[j-1];
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,len-end,len) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = 2*sz+3;
	int palin[len+1];
	memset(palin, 0, len+1);

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-1 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
	}

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = 0;

	REP(i,1,len-1) {
		if (i+val[i] == len && val[i] > ans) {
			ans = end = val[i];
			st = 0;
		}
	}
	REP(i,1,len-1) {
		if (str[i-1] == str[len-i]) {
			if (ans < 2*i+val[i]) {
				ans = 2*i + val[i];
				st = i+val[i];
				end = i;
			}
		} else {
			break;
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		int curr_val = 2*(i+1) + rval[j-1];
		if (curr_val > ans) {
			ans = curr_val;
			st = i+1;
			end = i+1 + rval[j-1];
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,len-end,len) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = s.length();
	int palin[len+5];
	rep(i,len+3) palin[i] = 0;

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = 0;
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (i+val[i+1] < j) {
			int curr_val = 2*(i+1) + val[i+1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1 + val[i+1];
				end = j;
			}
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}

	if (rval[len-1] > ans) {
		ans = rval[len-1];
		st = 0;
		end = len-rval[len-1];
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (j-rval[j-1] > i) {
			int curr_val = 2*(i+1) + rval[j-1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1;
				end = j-rval[j-1];
			}
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,end,len-1) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = s.length();
	int palin[len+5];
	rep(i,len+3) palin[i] = 0;

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = len;
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (i+val[i+1] < j) {
			int curr_val = 2*(i+1) + val[i+1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1 + val[i+1];
				end = j;
			}
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}

	if (rval[len-1] > ans) {
		ans = rval[len-1];
		st = 0;
		end = len-rval[len-1];
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (j-rval[j-1] > i) {
			int curr_val = 2*(i+1) + rval[j-1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1;
				end = j-rval[j-1];
			}
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,end,len-1) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = 2*sz+3;
	int palin[len+1];
	memset(palin, 0, len+1);

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = 0;
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (i+val[i+1] < j) {
			int curr_val = 2*(i+1) + val[i+1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1 + val[i+1];
				end = j;
			}
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}

	if (rval[len-1] > ans) {
		ans = rval[len-1];
		st = 0;
		end = len-rval[len-1];
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (j-rval[j-1] > i) {
			int curr_val = 2*(i+1) + rval[j-1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1;
				end = j-rval[j-1];
			}
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,end,len-1) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = 2*sz+3;
	int palin[len+5];
	memset(palin, 0, len+1);

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = 0;
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (i+val[i+1] < j) {
			int curr_val = 2*(i+1) + val[i+1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1 + val[i+1];
				end = j;
			}
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}

	if (rval[len-1] > ans) {
		ans = rval[len-1];
		st = 0;
		end = len-rval[len-1];
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (j-rval[j-1] > i) {
			int curr_val = 2*(i+1) + rval[j-1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1;
				end = j-rval[j-1];
			}
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,end,len-1) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = 2*sz+3;
	int palin[len+1];
	memset(palin, 0, len+1);

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = 0;

	REP(i,1,len-1) {
		if (i+val[i] == len && val[i] > ans) {
			ans = end = val[i];
			st = 0;
		}
	}
	REP(i,1,len-1) {
		if (str[i-1] == str[len-i]) {
			if (ans < 2*i+val[i]) {
				ans = 2*i + val[i];
				st = i+val[i];
				end = i;
			}
		} else {
			break;
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		int curr_val = 2*(i+1) + rval[j-1];
		if (curr_val > ans) {
			ans = curr_val;
			st = i+1;
			end = i+1 + rval[j-1];
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,len-end,len-1) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = s.length();
	int palin[len+5];
	memset(palin, 0, len+1);

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = 0;
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (i+val[i+1] < j) {
			int curr_val = 2*(i+1) + val[i+1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1 + val[i+1];
				end = j;
			}
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}

	if (rval[len-1] > ans) {
		ans = rval[len-1];
		st = 0;
		end = len-rval[len-1];
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (j-rval[j-1] > i) {
			int curr_val = 2*(i+1) + rval[j-1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1;
				end = j-rval[j-1];
			}
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,end,len-1) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = s.length();
	int palin[len+5];
	rep(i,len+3) palin[i] = 0;

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		cout << R-i+L << " " << len << endl;
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = 0;
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (i+val[i+1] < j) {
			int curr_val = 2*(i+1) + val[i+1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1 + val[i+1];
				end = j;
			}
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}

	if (rval[len-1] > ans) {
		ans = rval[len-1];
		st = 0;
		end = len-rval[len-1];
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (j-rval[j-1] > i) {
			int curr_val = 2*(i+1) + rval[j-1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1;
				end = j-rval[j-1];
			}
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,end,len-1) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <limits.h>
#include <assert.h>
//#include <unordered_map>
using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define null NULL
#define ll long long
#define llu unsigned long long
#define MAX 200005
#define mod 1000000007
#define inf 1e16
#define pp pair <int, int>

typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;
#define all(v) (v).begin(),(v).end()

const db PI = 3.141592653589793238;
#define abs(x) ((x)>0?(x):-(x))
//#define pop pop_back()
#define scan(x) scanf("%d",&x)
#define print(x) printf("%d\n",x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
//********************************************HAPPY CODDING************************************************//

string update_string(string str, int len) {
	string s = "#";
	rep(i,len) {
		s += str[i];
		s += "#";
	}

	return s;
}
vector<int> get_palin(string str, int sz) {
	string s = "@"+ update_string(str, sz) +"&";

	int len = s.length();
	int palin[len+5];
	rep(i,len+3) palin[i] = 0;

	int L, R, mx = 0;
	L = R = 1;
	REP(i,1,len-2) {
		palin[i] = min(palin[R-i+L], R-i);
		while (s[i-palin[i]] == s[i+palin[i]]) {
			palin[i]++;
		}

		if (i+palin[i] > R) {
			R = i+palin[i];
			L = i-palin[i];
		}
		mx = max(mx, palin[i]);
	}

	vector<int> v(sz, 1);
	for (int i = 2 ; i < len-2 ; i++) {
		int mid_pal = palin[i]/2;
		int pos = (i-2)/2;
		int st_pos = pos-mid_pal+1;
		v[st_pos] = max(v[st_pos], palin[i]-1);
		//cout << st_pos << " ";
	}
	//cout << endl;

	return v;
}
string get_sol(string str) {
	int len = str.length();
	vector<int> val = get_palin(str, len);
	if (len <= 2) {
		string s;
		rep(i,val[0]) s += str[i];

		return s;
	}

	int ans = val[0], st = val[0], end = len;
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (i+val[i+1] < j) {
			int curr_val = 2*(i+1) + val[i+1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1 + val[i+1];
				end = j;
			}
		}
	}

	vector<int> rval(len, 1);
	rep(i,len) {
		int pos = i+val[i]-1;
		rval[pos] = max(rval[pos], val[i]);
	}

	if (rval[len-1] > ans) {
		ans = rval[len-1];
		st = 0;
		end = len-rval[len-1];
	}
	for (int i = 0, j = len-1 ; i < j ; i++, j--) {
		if (str[i] != str[j]) break;

		if (j-rval[j-1] > i) {
			int curr_val = 2*(i+1) + rval[j-1];
			if (curr_val > ans) {
				ans = curr_val;
				st = i+1;
				end = j-rval[j-1];
			}
		}
	}

	if (ans >= len) return str;

	string s;
	rep(i,st) s += str[i];
	REP(i,end,len) s += str[i];
	return s;
}
int main() {

	int T;
	string str;
	scan(T);
	while (T--) {
		cin >> str;

		cout << get_sol(str) << endl;
	}

	return 0;
}