#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)

int main()
{
    lli n;
    cin>>n;
    ll64 a[n],e=0,o=0,z=0;
    frr(i,n)
    {
        cin>>a[i];
        if(a[i]==1 || (a[i]%2==0 and a[i]!=0))
        {
            e++;
        }
        else if(a[i]%2==1)
        {
            o++;
        }
        else if(a[i]==0)
        {
            z++;
        }
    }
    ll64 ans=(e*(e-1))/2 + (o*(o-1))/2 + (z*(z-1))/2;
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)

int main()
{
    lli n;
    cin>>n;
    ll64 a[n],e=0,o=0,ans=0;
    frr(i,n)
    {
        cin>>a[i];
        if(a[i]==1 || (a[i]%2==0 and a[i]!=0))
        {
            ans+=e;
            e++;
        }
        else if(a[i]%2==1)
        {
            ans+=o;
            o++;
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)

int main()
{
    lli n;
    cin>>n;
    lli a,e=0,o=0,ans=0;
    frr(i,n)
    {
        cin>>a;
        if(a==1 || a%2==0)
        {
            ans+=e;
            e++;
        }
        else if(a%2==1)
        {
            ans+=o;
            o++;
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)

int main()
{
    lli n;
    cin>>n;
    lli a;
    map<lli,lli>cnt;
    lli ans=0;
    frr(i,n)
    {
        cin>>a;
        lli t=a,c=0,x;
        while(t>0)
        {
            x=t%2;
            c+=x;
            t/=2;
        }
        if(cnt[c]!=0)
        {
            ans+=cnt[c];
        }
        cnt[c]++;
    }
    cout<<ans<<endl;
}


#include <iostream>
#include <vector>
using namespace std;
int fun(long long a);

int main() {
    vector<long long>v;
    int n,nx=0;
    long long a;
    cin>>n;
    for(int i=0 ; i<n ; i++) {cin>>a; v.push_back(a);}
    for(int i=0 ; i<n-1 ; i++)
        for(int j=i+1 ; j<n ; j++)
            if(fun(v[i])==fun(v[j])) nx++;
    cout<<nx<<endl;
    return 0;
}
int fun(long long a){
    int sum=0;
    while(a>0){
    sum+=a%2;
    a/=2;}
    return sum;
}


#include <iostream>
#include <vector>
using namespace std;
int fun(int a);

int main() {
    vector<long long>v;
    int n,nx=0;
    long long a;
    cin>>n;
    for(int i=0 ; i<n ; i++) {cin>>a; v.push_back(a);}
    for(int i=0 ; i<n-1 ; i++)
        for(int j=i+1 ; j<n ; j++)
            if(fun(v[i])==fun(v[j])) nx++;
    cout<<nx<<endl;
    return 0;
}
int fun(int a){
    if(a==0) return 0;
    if(a==1) return 1;
    if(a%2==0) return fun(a/2);
    if(a%2!=0 && a!=1) return 1+fun(a/2);
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int fun(long long a);

int main() {
    vector<long long>v;
    int n,nx=0;
    long long a;
    cin>>n;
    for(int i=0 ; i<n ; i++) {cin>>a; v.push_back(fun(a));}
    sort(v.begin(),v.end());
    for(int i=0;i<n-1;i++)
        if(v[i]==v[i+1]) nx++;
    /*for(int i=0 ; i<n-1 ; i++)
        for(int j=i+1 ; j<n ; j++)
            if(fun(v[i])==fun(v[j])) nx++;*/
    cout<<nx<<endl;
    return 0;
}
int fun(long long a){
    int sum=0;
    while(a>0){
    sum+=a%2;
    a/=2;}
    return sum;
}


#include <iostream>
#include <vector>
using namespace std;
int fun(long long a);
vector<int> fre;
vector<int> v;
bool exist(int x){
    if(v.size()!=0){
        for(int i=0;i<v.size();i++)
        if(x==v[i]) return true;
        else return false;}
    else return false;
}
int index(int x){
        for(int i=0;i<v.size();i++)
            if(x==v[i]) return i;
}

int main() {
    int n,nx=0;
    long long a;
    cin>>n;
    fre.resize(n);
    for(int i=0 ; i<n ; i++) {
        cin>>a;
        if(exist(fun(a))) fre[index(fun(a))]++;
        else {v.push_back(fun(a)); fre[index(fun(a))]++;}
        }
    for(int i=0;i<fre.size();i++){
        if(fre[i]>1) {
            int y=(fre[i]*(fre[i]-1))/2;
            nx+=y;}
    }
    cout<<nx<<endl;
    return 0;
}
int fun(long long a){
    int sum=0;
    while(a>0){
    sum+=a%2;
    a/=2;}
    return sum;
}


#include <algorithm>
using namespace std;
int fun(long long a);

int main() {
    vector<long long>v;
    int n,nx=0;
    long long a;
    cin>>n;
    for(int i=0 ; i<n ; i++) {cin>>a; v.push_back(fun(a));}
    sort(v.begin(),v.end());
    for(int i=0;i<n-1;i++)
        if(v[i]==v[i+1]) nx++;
    /*for(int i=0 ; i<n-1 ; i++)
        for(int j=i+1 ; j<n ; j++)
            if(fun(v[i])==fun(v[j])) nx++;*/
    cout<<nx<<endl;
    return 0;
}
int fun(long long a){
    int sum=0;
    while(a>0){
    sum+=a%2;
    a/=2;}
    return sum;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long fun(long long a);
vector<long long> fre;
vector<long long> v;
bool exist(long long x){
    if(v.size()!=0){
        for(int i=0;i<v.size();i++)
        if(x==v[i]) return true;
        else return false;}
    else return false;
}
int index(long long x){
        for(int i=0;i<v.size();i++)
            if(x==v[i]) return i;
}

int main() {
    long long n,nx=0;
    long long a;
    cin>>n;
    fre.resize(n);
    for(int i=0 ; i<n ; i++) {
        cin>>a;
        if(exist(fun(a))) fre[index(fun(a))]++;
        else {v.push_back(fun(a)); fre[index(fun(a))]++;}
        }
    for(int i=0;i<fre.size();i++){
        if(fre[i]>1) {
            long long y=(fre[i]*(fre[i]-1))/2;
            nx+=y;}
    }

    cout<<nx<<endl;
    return 0;
}
long long fun(long long a){
    long long sum=0;
    while(a>0){
    sum+=a%2;
    a/=2;}
    return sum;
}


#include <iostream>
#include <vector>
using namespace std;
long long fun(long long a);

int main() {
    vector<long long>v;
    int n,nx=0;
    long long a;
    cin>>n;
    for(int i=0 ; i<n ; i++) {cin>>a; v.push_back(a);}
    for(int i=0 ; i<n-1 ; i++)
        for(int j=i+1 ; j<n ; j++)
            if(fun(v[i])==fun(v[j])) nx++;
    cout<<nx<<endl;
    return 0;
}
long long fun(long long a){
    if(a==0) return 0;
    if(a==1) return 1;
    if(a%2==0) return fun(a/2);
    if(a%2!=0 && a!=1) return 1+fun(a/2);
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cassert>
#include <random>
#include <time.h>
#include <numeric>

#define fi first
#define se second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define re return
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define int long long

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef double D;

const double pi = 3.14159265;
const ll mod = 998244353;
const ll INF = 2e18;
const ll N = 2e5 + 5;
const int P0 = 437;
const int P1 = 343;

signed main()
{
    //freopen("privet.in ", "r", stdin);
    //freopen("privet.out", "w", stdout);
    cin.sync_with_stdio(); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n)
        cin >> a[i];
    vi cnt(50);
    for (int i = 0; i < n; i++)
    {
        int k = 0;
        while(a[i])
        {
            if(a[i] % 2)
                k++;
            a[i] /= 2;
        }
        cnt[k]++;
    }
    ll an = 0;
    for (int i = 0; i < 50; i++)
        an += cnt[i] * (cnt[i] - 1) / 2;
    cout << an;

}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cassert>
#include <random>
#include <time.h>
#include <numeric>

#define fi first
#define se second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define re return
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
//#define int long long

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef double D;

const double pi = 3.14159265;
const ll mod = 998244353;
const ll INF = 2e18;
const ll N = 2e5 + 5;
const int P0 = 437;
const int P1 = 343;

signed main()
{
    //freopen("privet.in ", "r", stdin);
    //freopen("privet.out", "w", stdout);
    cin.sync_with_stdio(); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n)
        cin >> a[i];
    vi cnt(50);
    for (int i = 0; i < n; i++)
    {
        int k = 0;
        while(a[i])
        {
            if(a[i] % 2)
                k++;
            a[i] /= 2;
        }
        cnt[k]++;
    }
    ll an = 0;
    for (int i = 0; i < 50; i++)
        an += cnt[i] * (cnt[i] - 1) / 2;
    cout << an;

}


// </> : towhid1zaman

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define deb(x) cout<<#x <<"="<<x<<endl;
#define present(v,x) ((v).find(x)!=(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sp(k) cout<<setprecision(k)<<fixed;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()

#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)

#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define yn(k) if(k)puts("YES");else puts("NO");

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;

/*
 *
 */

void task(){
	int n; cin >> n;
	std::vector<ll> a(n+1,0), Bit_cnt(40,0);

	for(int i = 1; i<=n; i++){
		cin >> a[i];
		Bit_cnt[__builtin_popcountl(a[i])]++;
	}

	ll sum = 0;

	for(int i = 1; i<=n; i++){
		sum += (Bit_cnt[i] * (Bit_cnt[i]-1)/2);
	}

	cout << sum << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1; //cin >> T;
        while(T--){
            task();
        }

return 0;
}


// </> : towhid1zaman

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define deb(x) cout<<#x <<"="<<x<<endl;
#define present(v,x) ((v).find(x)!=(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sp(k) cout<<setprecision(k)<<fixed;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()

#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)

#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define yn(k) if(k)puts("YES");else puts("NO");

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;

/*
 *f(0)=0
 * f(1)=1
 * f(2)=1
 * f(3)=2
 * f(4)=1
 * f(5)=2
 * f(6)=2
 * f(7)=3
 * f(8)=1
 * f(9)=2
 * f(10)=2
 * f(11)=3
 * f(12)=2
 * f(13)=3
 * f(14)=3
 * f(15)=4
 * f(16)=1
 * ...number of bits
 */

//return number of bits actually
int f(ll n){
	if(n==0)return 0;
	if(n%2==0) return f(n/2);
	else return f(n/2)+1;
}

void task(){
	int n; cin >> n;
	std::map<ll, ll> mop;
	for(int i= 0; i<n; i++){
		ll x; cin >> x;
		//mop[f(x)]++;
		mop[__builtin_popcountl(x)]++;
	}

	ll sum = 0;
	for(auto &x:mop){
		sum += (x.ss*(x.ss-1)/2);
	}

	cout << sum << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1; //cin >> T;
        while(T--){
            task();
        }

return 0;
}


// </> : towhid1zaman

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define deb(x) cout<<#x <<"="<<x<<endl;
#define present(v,x) ((v).find(x)!=(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sp(k) cout<<setprecision(k)<<fixed;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()

#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)

#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define yn(k) if(k)puts("YES");else puts("NO");

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;

/*
 *
 */

void task(){
	int n; cin >> n;
	std::vector<ll> a(n+1,0), Bit_cnt(40,0);

	for(int i = 1; i<=n; i++){
		cin >> a[i];
		Bit_cnt[__builtin_popcountl(a[i])]++;
	}

	ll sum = 0;

	for(int i = 0; i<40; i++){
		sum += (Bit_cnt[i] * (Bit_cnt[i]-1)/2);
	}

	cout << sum << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1; //cin >> T;
        while(T--){
            task();
        }

return 0;
}


// </> : towhid1zaman

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define deb(x) cout<<#x <<"="<<x<<endl;
#define present(v,x) ((v).find(x)!=(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);
#define sp(k) cout<<setprecision(k)<<fixed;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()

#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)

#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define yn(k) if(k)puts("YES");else puts("NO");

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 200005;

/*
 *
 */

int f(ll n){
	if(n==0)return 0;
	if(n%2==0) return f(n/2);
	else return f(n/2)+1;
}

void task(){
	int n; cin >> n;
	std::map<ll, ll> mop;
	for(int i= 0; i<n; i++){
		ll x; cin >> x;
		mop[f(x)]++;
	}

	ll sum = 0;
	for(auto &x:mop){
		sum += (x.ss*(x.ss-1)/2);
	}

	cout << sum << endl;
}

int main(){
        _
        #ifdef OJ
        freopen("inputf.in", "r", stdin);
        freopen("outputf.in", "w", stdout);
        #endif

        int T = 1; //cin >> T;
        while(T--){
            task();
        }

return 0;
}


#include <iostream>
using namespace std;/////////////////// 272 B //// 626 A
int fx(long long int n)
{
	int a = 0;
	while (n > 0)
	{
		if (n % 2 == 1)
			a++;
		n /= 2;
	}
	return a;
}
int main()
{
	long long int n, b, in[40], ans = 0;
	cin >> n;
	for (int i = 0; i < 40; i++)
		in[i] = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> b;
		in[fx(b)] += 1;
	}
	for (int i = 0; i < 40; i++)
	{
		if (in[i] != 0)
			ans += in[i] * (in[i] - 1) / 2;
	}
	cout << ans << endl;
		return 0;
}


#include <iostream>
using namespace std;/////////////////// 272 B //// 626 A
int fx(int n)
{
	int a = 0;
	while (n > 0)
	{
		if (n % 2 == 1)
			a++;
		n /= 2;
	}
	return a;
}
int main()
{
	int n, b, in[40], ans = 0;
	cin >> n;
	for (int i = 0; i < 40; i++)
		in[i] = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> b;
		in[fx(b)] += 1;
	}
	for (int i = 0; i < 40; i++)
	{
		if (in[i] != 0)
			ans += in[i] * (in[i] - 1) / 2;
	}
	cout << ans << endl;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{
    ll n;
    cin>>n;
    int b[n];
    for(ll i=0;i<n;i++)
    {
        cin>>b[i];
    }
    ll max=b[0];
     for(ll i=1;i<n;i++)
    {
        if(max<b[i])
         max=b[i];
    }
    ll a[max];
    for(ll i=0;i<=max;i++)
    {
        if(i==0)
         a[0]=0;
         else if(i%2!=0)
               a[i]=a[(i-1)/2]+1;
               else
               a[i]=a[i/2];

              // cout<<a[i]<<endl;
    }
    ll maxx=a[0];
     for(ll i=1;i<=max;i++)
    {
        if(maxx<a[i])
         maxx=a[i];
    }
    ll count[maxx+1];
    memset(count,0,sizeof(ll)*(maxx+1));
    for(ll i=0;i<n;i++)
    {
        count[a[b[i]]]++;
    }

    ll pairs=0;
    for(ll i=0;i<=maxx;i++)
    {
        if(count[i]!=0)
        {
            pairs+=(((count[i])*(count[i]-1))/2);
        }
    }
    cout<<pairs<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
ll f(ll a)
{
    if(a==0)
      return 0;
      if(a%2!=0)
        return f((a-1)/2)+1;
        else
        return f(a/2);
}

int main()
{
    ll n;
    cin>>n;
    int b[n];
    for(ll i=0;i<n;i++)
    {
        cin>>b[i];
        b[i]=f(b[i]);
    }
  /*  ll max=b[0];
     for(ll i=1;i<n;i++)
    {
        if(max<b[i])
         max=b[i];
    }

    cout<<max<<endl;*/
    /*for(ll i=0;i<=max;i++)
    {
        if(i==0)
         a[i]=0;
         else if(i%2!=0)
               a[i]=a[(i-1)/2]+1;
               else
               a[i]=a[i/2];

             // cout<<a[i]<<endl;
    }*/
    ll maxx=b[0];
     for(ll i=1;i<n;i++)
    {
        if(maxx<b[i])
         maxx=b[i];
    }

    ll count[maxx+1];
    memset(count,0,sizeof(ll)*(maxx+1));
    for(ll i=0;i<n;i++)
    {
        count[b[i]]++;
    }

    ll pairs=0;
    for(ll i=0;i<=maxx;i++)
    {
        if(count[i]!=0)
        {
            pairs+=(((count[i])*(count[i]-1))/2);
        }
    }
    cout<<pairs<<endl;

}


#include <bits/stdc++.h>
using namespace std;
//---------------------------------//
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
//------------------------------//

typedef long long int ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;

#define  ff           first
#define  ss           second
#define  pb           push_back
#define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  all(x)       (x).begin(), (x).end()
#define  ps(x,y)      fixed<<setprecision(y)<<x
#define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll maxn = 1e6 + 4;

int f(int k) {
	if (k == 0)return 0;
	if (k % 2)return f((k - 1) / 2) + 1;
	else return f(k / 2);
}
void solve() {
	int n;
	cin >> n;
	vi v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	ll ans = 0;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		ans += mp[f(v[i])];
		mp[f(v[i])]++;
	}
	cout << ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	IOS
	solve();
	cerr << endl << "Program Executed Successfully" << endl;
}

// integer overflow


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pr pair<int, int>
#define v1d vector<int>
#define mp make_pair
#define pb push_back
#define v1p vector<pr>
#define vb vector<bool>
#define v2d vector<vector<int>>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define S(v) sort(v.begin(), v.end())
#define RS(v) sort(v.rbegin(), v.rend())
#define eb emplace_back
#define endl "\n"
#define MOD 1000000007
#define pqx priority_queue <int>
#define pqn priority_queue <int, v1d, greater<int> >
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int solve(int x) {
	if(x == 1) return 1;
	if(x == 3) return 2;
	if(x == 7) return 3;

	if(x & 1) {
		return (solve(x / 2) + 1);
	}
	else return solve(x / 2);
}

int32_t main() {
    fio
	map<int, int> m;
	int n; cin >> n;
	for(int i=0; i<n; ++i) {
		int x; cin >> x;
		m[solve(x)]++;
	}

	int ans = 0 ;
	for(auto &k : m) {
		int p = k.ss;
		int l = (p * p - p) / 2;
		ans += l;
	}
	cout << ans;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pr pair<int, int>
#define v1d vector<int>
#define mp make_pair
#define pb push_back
#define v1p vector<pr>
#define vb vector<bool>
#define v2d vector<vector<int>>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define S(v) sort(v.begin(), v.end())
#define RS(v) sort(v.rbegin(), v.rend())
#define eb emplace_back
#define endl "\n"
#define MOD 1000000007
#define pqx priority_queue <int>
#define pqn priority_queue <int, v1d, greater<int> >
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int solve(int x) {
	if(x == 1) return 1;
	if(x == 3) return 2;
	if(x == 7) return 3;

	if(x & 1) {
		return (solve(x / 2) + 1);
	}
	else return solve(x / 2);
}

int32_t main() {
    fio
	unordered_map<int, int> m;
	int n; cin >> n;
	for(int i=0; i<n; ++i) {
		int x; cin >> x;
		m[solve(x)]++;
	}

	int ans = 0 ;
	for(auto &k : m) {
		int p = k.ss;
		int l = (p * p - p) / 2;
		ans += l;
	}
	cout << ans;
}


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

#define N 100005
int n, fv[50];
ll ans;

int main(){
    cin >> n;
    for (int i=1, x, cnt = 0; i<=n; i++,cnt = 0){
        cin >> x;
        while (x > 1){
            if (x & 1) cnt++;
            x >>= 1;
        }
        fv[cnt]++;
    }
    for (int i=0; i<=31; i++) ans += 1LL*fv[i]*(fv[i]-1)/2;
    cout << ans;
    return 0;
}


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

#define N 100005
int n, fv[50];
ll ans;

int main(){
    cin >> n;
    for (int i=1, x, cnt = 0; i<=n; i++){
        cin >> x;
        while (x > 1){
            if (x & 1) cnt++;
            x >>= 1;
        }
        fv[cnt]++;
    }
    for (int i=0; i<=31; i++) ans += fv[i]*(fv[i]-1)/2;
    cout << ans;
    return 0;
}


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

#define N 100005
int n, fv[50];
ll ans;

int main(){
    cin >> n;
    for (int i=1, x, cnt = 0; i<=n; i++){
        cin >> x;
        while (x > 1){
            if (x & 1) cnt++;
            x >>= 1;
        }
        fv[cnt]++;
    }
    for (int i=0; i<=n; i++) ans += fv[i]*(fv[i]-1)/2;
    cout << ans;
    return 0;
}


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

#define N 100005
int n, fv[50];
ll ans;

int main(){
    cin >> n;
    for (int i=1, x, cnt = 0; i<=n; i++,cnt = 0){
        cin >> x;
        while (x > 1){
            if (x & 1) cnt++;
            x >>= 1;
        }
        fv[cnt]++;
    }
    for (int i=0; i<=31; i++) ans += fv[i]*(fv[i]-1)/2;
    cout << ans;
    return 0;
}


 #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    int n , f[30] , arr[100005] ;
    ll counter=0;
    int fun(int x)
    {
        // base case
        if(!x)  // handle 0
            return 0;
        // recursive case
        int tmp=(x-1)/2;  // handle odd numbers
        if(tmp*2+1==x)
            return fun(tmp)+1;
        tmp=x/2;
        if(tmp*2==x)  // handle even numbers
            return fun(tmp);
    }
    int main()
    {

        cin>>n;
        for(int i=0; i<n; i++)
            cin>>arr[i];
        for(int i=0; i<n; i++){
            int tmp=fun(arr[i]);
            f[tmp]++;
        }
        for(int i=1; i<30; i++)
            if(f[i]!=0)
            counter+=((ll)f[i]*(ll)(f[i]-1)/(ll)2);  // it`s applying combinatiers after deleting numbers from down with ones form above
        cout<<counter<< endl;
        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
int n , arr[100005] , fdp[100005] , res[100005] , cdp[100005];
#define ll long long
ll counter=0;
ll fun(int x)
{
    // dp part
    if (fdp[x]!=0)
        return fdp[x];
    // base function
    if(x==0)
        return 0;
    // recursive function
    int tmp=(x-1)/2;
    if(tmp*2+1==x)
        return fun(tmp)+1;
    tmp=x/2;
    if(tmp*2==x)
        return fun(tmp);
}
ll calc(int x)
{
    ll ans=1;
        for(int i=x; i>=1; i--){
            if(cdp[i]!=0){
                ans*=cdp[i];
                break;
            }
            else
                ans*=i;
        }
    return ans;
}
ll t(int x)
{
    ll up , d;
    up=calc(x);
    cdp[x]=up;
    d=calc(x-2);
    cdp[x-2]=d;
    return (up/(2*d));
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=0; i<n; i++){
        int tmp=fun(arr[i]);
        res[tmp]++;
        fdp[arr[i]]=tmp;
    }
    for(int i=0; i<n; i++)
        if(res[i]>1)
        counter+=t(res[i]);
    cout<<counter<< endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n , f[26] , arr[100005] ;
ll counter=0;
int fun(int x)
{
    // base case
    if(!x)  // handle 0
        return 0;
    // recursive case
    int tmp=(x-1)/2;  // handle odd numbers
    if(tmp*2+1==x)
        return fun(tmp)+1;
    tmp=x/2;
    if(tmp*2==x)  // handle even numbers
        return fun(tmp);
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=0; i<n; i++){
        int tmp=fun(arr[i]);
        f[tmp]++;
    }
    for(int i=1; i<=25; i++)
        if(f[i]!=0)
        counter+=((ll)f[i]*(ll)(f[i]-1)/(ll)2);  // it`s applying combinatiers after deleting numbers from down with ones form above
    cout<<counter<< endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n , f[105] , arr[100005] ;
ll counter=0;
int fun(int x)
{
    // base case
    if(!x)  // handle 0
        return 0;
    // recursive case
    int tmp=(x-1)/2;  // handle odd numbers
    if(tmp*2+1==x)
        return fun(tmp)+1;
    tmp=x/2;
    if(tmp*2==x)  // handle even numbers
        return fun(tmp);
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=0; i<n; i++){
        int tmp=fun(arr[i]);
        f[tmp]++;
    }
    for(int i=1; i<=100; i++)
        if(f[i]!=0)
        counter+=((ll)f[i]*(ll)(f[i]-1)/(ll)2);  // it`s applying combinatiers after deleting numbers from down with ones form above
    cout<<counter<< endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n , f[35] , arr[100005] ;
ll counter=0;
int fun(int x)
{
    // base case
    if(!x)  // handle 0
        return 0;
    // recursive case
    int tmp=(x-1)/2;  // handle odd numbers
    if(tmp*2+1==x)
        return fun(tmp)+1;
    tmp=x/2;
    if(tmp*2==x)  // handle even numbers
        return fun(tmp);
}
int main()
{
    cout<<n(fun)
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=0; i<n; i++){
        int tmp=fun(arr[i]);
        f[tmp]++;
    }
    for(int i=1; i<35; i++)
        if(f[i]!=0)
        counter+=((ll)f[i]*(ll)(f[i]-1)/(ll)2);  // it`s applying combinatiers after deleting numbers from down with ones form above
    cout<<counter<< endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n , f[25] , arr[100005] ;
ll counter=0;
int fun(int x)
{
    // base case
    if(!x)  // handle 0
        return 0;
    // recursive case
    int tmp=(x-1)/2;  // handle odd numbers
    if(tmp*2+1==x)
        return fun(tmp)+1;
    tmp=x/2;
    if(tmp*2==x)  // handle even numbers
        return fun(tmp);
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=0; i<n; i++){
        int tmp=fun(arr[i]);
        f[tmp]++;
    }
    for(int i=1; i<=20; i++)
        if(f[i]!=0)
        counter+=((ll)f[i]*(ll)(f[i]-1)/(ll)2);  // it`s applying combinatiers after deleting numbers from down with ones form above
    cout<<counter<< endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n , arr[100005] , f[20];
long long counter=0;
int fun(int x)
{
    // base case
    if(!x)  // handle 0
        return 0;
    // recursive case
    int tmp=(x-1)/2;  // handle odd numbers
    if(tmp*2+1==x)
        return fun(tmp)+1;
    tmp=x/2;
    if(tmp*2==x)  // handle even numbers
        return fun(tmp);
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=0; i<n; i++){
        int tmp=fun(arr[i]);
        f[tmp]++;
    }
    for(int i=1; i<20; i++)
        if(f[i]!=0)
        counter+=(f[i]*(f[i]-1)/2);  // it`s applying combinatiers after deleting numbers from down with ones form above
    cout<<counter<< endl;
    return 0;
}


    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    int n , f[35] , arr[100005] ;
    ll counter=0;
    int fun(int x)
    {
        // base case
        if(!x)  // handle 0
            return 0;
        // recursive case
        int tmp=(x-1)/2;  // handle odd numbers
        if(tmp*2+1==x)
            return fun(tmp)+1;
        tmp=x/2;
        if(tmp*2==x)  // handle even numbers
            return fun(tmp);
    }
    int main()
    {

        cin>>n;
        for(int i=0; i<n; i++)
            cin>>arr[i];
        for(int i=0; i<n; i++){
            int tmp=fun(arr[i]);
            f[tmp]++;
        }
        for(int i=1; i<35; i++)
            if(f[i]!=0)
            counter+=((ll)f[i]*(ll)(f[i]-1)/(ll)2);  // it`s applying combinatiers after deleting numbers from down with ones form above
        cout<<counter<< endl;
        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
int n , arr[100005] , f[20];
#define ll long long
ll counter=0;
int fun(int x)
{
    // base case
    if(!x)  // handle 0
        return 0;
    // recursive case
    int tmp=(x-1)/2;  // handle odd numbers
    if(tmp*2+1==x)
        return fun(tmp)+1;
    tmp=x/2;
    if(tmp*2==x)  // handle even numbers
        return fun(tmp);
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=0; i<n; i++){
        int tmp=fun(arr[i]);
        f[tmp]++;
    }
    for(int i=1; i<20; i++)
        if(f[i]!=0)
        counter+=((ll)f[i]*(ll)(f[i]-1)/(ll)2);  // it`s applying combinatiers after deleting numbers from down with ones form above
    cout<<counter<< endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n , f[25] , arr[100005] ;
ll counter=0;
int fun(int x)
{
    // base case
    if(!x)  // handle 0
        return 0;
    // recursive case
    int tmp=(x-1)/2;  // handle odd numbers
    if(tmp*2+1==x)
        return fun(tmp)+1;
    tmp=x/2;
    if(tmp*2==x)  // handle even numbers
        return fun(tmp);
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    for(int i=0; i<n; i++){
        int tmp=fun(arr[i]);
        f[tmp]++;
    }
    for(int i=1; i<=25; i++)
        if(f[i]!=0)
        counter+=((ll)f[i]*(ll)(f[i]-1)/(ll)2);  // it`s applying combinatiers after deleting numbers from down with ones form above
    cout<<counter<< endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fun(int n)
{
	if(n<=1)
		return n;
	if(n%2==0)
	{
		return fun(n/2);
	}
	return fun(n/2)+1;
}

int main()
{
    long long int i,j=0,k=0,c=0,n,mm;
    cin>>n;
    map<long,int>m;
    for (i = 0; i <n; ++i)
    {
    	cin>>mm;
    	k=fun(mm);
    	m[k]++;
    }
    //map<long,int>:: iterator it=m.begin();
    for(auto it : m)
    	j+=(1ll*it.second*(it.second-1))/2;
    cout<<j;

}


#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define ll long long int
const int mod=1e9+7;
ll fact(ll n){return (n==1 || n==0) ? 1: n * fact(n - 1);  }

int main(){
    ll n;
    cin>>n;
    ll v[n];
    map<ll,ll>mp1;
    for(ll i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v,v+n);
    ll m=v[n-1];
    ll a[m];
    for(ll i=0;i<=m;i++){
    if(i==0)a[i]=0;
    else if(i%2==0)a[i]=a[i/2];
    else a[i]=a[i/2]+1;
    }
    for(ll i=0;i<n;i++){
        mp1[a[v[i]]]++;
    }
    ll count=0;
    for(auto y:mp1){
        ll x=y.second;
        count+=(x*(x-1)/2);
    }
    cout<<count;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define PI 3.14159265359
#define OO 1e8;
void File()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
}
void IO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
/*void prime_factors(ll n)
{
    vector<ll>vec;
    while(n%2==0){n/=2;vec.push_back(2);}
    for(ll i=3;i<=sqrt(n);i+=2)while(n%i==0){n/=i;vec.push_back(i);}
    if(n>2)vec.push_back(n);
}
bitset<int(1e7+500)>is_prime;
vector<int>vec;
void sieve()
{
    is_prime.set();
    is_prime[1]=0;
    vec.push_back(2);
    for(ll i=4;i<=int(1e7+500);i+=2)is_prime[i]=0;
    for(ll i=3;i<=int(1e7+500);i+=2)
    {
        if(!is_prime[i])continue;
        vec.push_back(i);
        for(ll j=i*i;j<=int(1e7+500);j+=i)is_prime[j]=0;
    }
}*/
int rec(int a)
{
    if(a==0)return 0;
    if(a%2)return rec(a/2)+1;
    else return rec(a/2);
}
int main()
{
    IO();
    int n;
    cin>>n;
    ll freq[100];
    memset(freq,0,sizeof freq);
    for(int i=0;i<n;++i)
    {
        int a;
        cin>>a;
        freq[rec(a)]++;
    }
    ll ans=0;
    for(int i=0;i<100;++i)ans+=(freq[i]*(freq[i]-1))/2;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define PI 3.14159265359
#define OO 1e8;
void File()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
}
void IO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
/*void prime_factors(ll n)
{
    vector<ll>vec;
    while(n%2==0){n/=2;vec.push_back(2);}
    for(ll i=3;i<=sqrt(n);i+=2)while(n%i==0){n/=i;vec.push_back(i);}
    if(n>2)vec.push_back(n);
}
bitset<int(1e7+500)>is_prime;
vector<int>vec;
void sieve()
{
    is_prime.set();
    is_prime[1]=0;
    vec.push_back(2);
    for(ll i=4;i<=int(1e7+500);i+=2)is_prime[i]=0;
    for(ll i=3;i<=int(1e7+500);i+=2)
    {
        if(!is_prime[i])continue;
        vec.push_back(i);
        for(ll j=i*i;j<=int(1e7+500);j+=i)is_prime[j]=0;
    }
}*/
int rec(int a)
{
    if(a==0)return 0;
    if(a%2)return rec(a/2)+1;
    else return rec(a/2);
}
int main()
{
    IO();
    int n;
    cin>>n;
    int freq[100];
    memset(freq,0,sizeof freq);
    for(int i=0;i<n;++i)
    {
        int a;
        cin>>a;
        freq[rec(a)]++;
    }
    ll ans=0;
    for(int i=0;i<100;++i)ans+=(freq[i]*(freq[i]-1))/2;
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int f(ll a,ll sum=0)
{   if(a==1||a==2) return sum+1;
    return f(a/2,sum+a%2);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n,p=0;
    cin>>n;
    ll a[n],hash[n+1]={0};
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]=f(a[i]);
        hash[a[i]]++;
    }
        for(ll i=0;i<=n;i++)
        {
            if(hash[i]) p+=(hash[i]*(hash[i]-1)/2);
        }
    cout<<p;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int f(ll a,ll sum=0)
{   if(a==1||a==2) return sum+1;
    return f(a/2,sum+a%2);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n,p=0;
    cin>>n;
    ll a[n],hash[100000]={0};
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]=f(a[i]);
        hash[a[i]]++;
    }
        for(ll i=0;i<100000;i++)
        {
            if(hash[i]) p+=(hash[i]*(hash[i]-1)/2);
        }
    cout<<p;
}


#include <bits/stdc++.h>
#include "rubo.h"

#define dbl double
#define pb push_back
#define SQ(x) (x)*(x)
#define ll long long
#define vc vector
#define F first
#define S second
#define in ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt...) (0)

using namespace std;

const int MAXN = 100005;

int f(int x){
    if(x == 0)
        return 0;

    if(x % 2 == 0)
        return f(x/2);
    else
        return f(x/2)+1;
}

map<int,int> mp;

int main() {
    int n;
    cin >> n;
    loop(i,n){
        int e;
        cin >> e;
        mp[f(e)]++;
    }

    ll res = 0;
    for(pii p : mp){
        res += (p.second*1ll*(p.second-1))/2;
    }
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>
//#include "rubo.h"

#define dbl double
#define pb push_back
#define SQ(x) (x)*(x)
#define ll long long
#define vc vector
#define F first
#define S second
#define in ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt...) (0)

using namespace std;

const int MAXN = 100005;

int f(int x){
    if(x == 0)
        return 0;

    if(x % 2 == 0)
        return f(x/2);
    else
        return f(x/2)+1;
}

map<int,int> mp;

int main() {
    int n;
    cin >> n;
    loop(i,n){
        int e;
        cin >> e;
        mp[f(e)]++;
    }

    ll res = 0;
    for(pii p : mp){
        res += (p.second*1ll*(p.second-1))/2;
    }
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>
#define NN 100010
using namespace std;
typedef long long INT;
int a[NN],cnt[NN];
INT calc(int u){
	int ans;
	if(u==0) return 0;
	else if(u==1) return 1;
	if(u%2) ans=1+calc((u-1)/2);
	else ans=calc(u/2);
	return ans;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	INT sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		int u=calc(a[i]);
		cnt[u]++;
	}
	for(int i=1;i<NN;i++){
		if(cnt[i]) sum+=(INT)cnt[i]*(cnt[i]-1)/2;
	}
	printf("%I64d",sum);
	return 0;
}


#include <bits/stdc++.h>
#define NN 100010
using namespace std;
typedef long long INT;
int a[NN],cnt[NN];
INT calc(int u){
	int ans;
	if(u==0) return 0;
	else if(u==1) return 1;
	if(u%2) ans=1+calc((u-1)/2);
	else ans=calc(u/2);
	return ans;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	INT sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		int u=calc(a[i]);
		cnt[u]++;
	}
	for(int i=1;i<NN;i++){
		if(cnt[1]) sum+=(INT)cnt[i]*(cnt[i]-1)/2;
	}
	printf("%I64d",sum);
	return 0;
}


#include <bits/stdc++.h>
#define mod 1000000007
#define speedgeek ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define f(i,x,y) for(i=x;i<y;i++)
#define pb push_back
#define ll long long
#define mll map<long long,long long>
#define mcl map<char,long long>
#define vll vector<long long>
#define sll set<long long>
using namespace std;

ll func(ll n)
{
    if(n==0)return 0;
    else if(n%2==0)return func(n/2);
    else return func((n-1)/2)+1;
}

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

int main(){
    speedgeek;

    ll n,o=0,e=0,i,res=0;
    cin>>n;
    vll v(n);
    f(i,0,n)
    {
        cin>>v[i];
    }

    map<ll,ll> m;
    f(i,0,n)
    {
        m[func(v[i])]++;
    }

    for(auto x:m)
        res+=fp(x.second);
    cout<<res<<"\n";

    // cout<<fp(100000)<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#define mod 1000000007
#define speedgeek ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define f(i,x,y) for(i=x;i<y;i++)
#define pb push_back
#define ll long long
#define mll map<long long,long long>
#define mcl map<char,long long>
#define vll vector<long long>
#define sll set<long long>
using namespace std;

ll func(ll n)
{
    if(n==0)return 0;
    else if(n%2==0)return func(n/2);
    else return func((n-1)/2)+1;
}

ll fp(ll n)
{
    return (n*(n-1))/2;
}

int main(){
    speedgeek;

    ll n,o=0,e=0,i,res=0;
    cin>>n;
    vll v(n);
    f(i,0,n)
    {
        cin>>v[i];
    }

    map<ll,ll> m;
    f(i,0,n)
    {
        m[func(v[i])]++;
    }

    for(auto x:m)
        res+=fp(x.second);
    cout<<res<<"\n";

    // cout<<fp(100000)<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#define mod 1000000007
#define speedgeek ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define f(i,x,y) for(i=x;i<y;i++)
#define pb push_back
#define ll long long
#define mll map<long long,long long>
#define mcl map<char,long long>
#define vll vector<long long>
#define sll set<long long>
using namespace std;

int func(ll n)
{
    if(n==0)return 0;
    else if(n%2==0)return func(n/2);
    else return func((n-1)/2)+1;
}

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

int main(){
    speedgeek;

    ll n,o=0,e=0,i,res=0;
    cin>>n;
    vll v(n);
    f(i,0,n)
    {
        cin>>v[i];
    }

    map<ll,ll> m;
    f(i,0,n)
    {
        m[func(v[i])]++;
    }

    for(auto x:m)
        res+=fp(x.second);
    cout<<res<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#define mod 1000000007
#define speedgeek ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define f(i,x,y) for(i=x;i<y;i++)
#define pb push_back
#define ll long long
#define mll map<long long,long long>
#define mcl map<char,long long>
#define vll vector<long long>
#define sll set<long long>
using namespace std;

ll func(ll n)
{
    if(n==0)return 0;
    else if(n%2==0)return func(n/2);
    else return func((n-1)/2)+1;
}

ll fp(ll n)
{
    return (n*(n-1))/2;
}

int main(){
    speedgeek;

    ll n,o=0,e=0,i,res=0;
    cin>>n;
    vll v(n);
    f(i,0,n)
    {
        cin>>v[i];
    }

    map<ll,ll> m;
    f(i,0,n)
    {
        m[func(v[i])]++;
    }

    for(auto x:m)
        res+=fp(x.second);
    // cout<<res<<"\n";

    cout<<fp(100000)<<"\n";

    return 0;
}


#include <bits/stdc++.h>
#define mod 1000000007
#define speedgeek ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define f(i,x,y) for(i=x;i<y;i++)
#define pb push_back
#define ll long long
#define mll map<long long,long long>
#define mcl map<char,long long>
#define vll vector<long long>
#define sll set<long long>
using namespace std;
int main(){
    speedgeek;

    ll n,o=0,e=0,i;
    cin>>n;
    vll v(n);
    f(i,0,n)
    {
        cin>>v[i];
        if(v[i]==1 || v[i]%2==0)
            e++;
        else if(v[i]%2!=0)
            o++;
    }

    ll res=((o*(o-1))/2)+((e*(e-1))/2);
    cout<<res<<"\n";

    return 0;
}


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

int f(int n)
{
    if(n == 0) return 0;
    if(n & 1) return f(n/2) + 1;
    return f(n/2);
}
vector<int> v;
int cnt[100010], now[100010];
int main()
{
    int n, arr[100010];
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
        arr[i] = f(arr[i]);
        v.push_back(arr[i]);
    }
    sort(v.begin(), v.end());
    int cur = 1;
    map<int,int> mp;
    for(int i = 0; i < n; i++)
    {
        if(i == 0) mp[v[i]] = cur++;
        else if(v[i] != v[i-1]) mp[v[i]] = cur++;
    }
    for(int i = 0; i < n; i++)
        arr[i] = mp[arr[i]];
    for(int i = 0; i < n; i++)
        cnt[arr[i]]++;
    long long ans = 0;
    for(int i = 0; i < n; i++)
    {
        now[arr[i]]++;
        ans += max(0,cnt[arr[i]] - now[arr[i]]);
    }
    printf("%lld", ans);
    return 0;
}


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

int f(int n) {
	if(n == 0) return 0;
	if(n & 1) return f(n/2) + 1;
	return f(n/2);
}
vector<int> v;
int cnt[100010], now[100010];
int main() {
	int n, arr[100010];
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
		arr[i] = f(arr[i]);
		v.push_back(arr[i]);
	}
	sort(v.begin(), v.end());
	int cur = 1;
	map<int,int> mp;
	for(int i = 0; i < n; i++) {
		if(i == 0) mp[v[i]] = cur++;
		else if(v[i] != v[i-1]) mp[v[i]] = cur++;
	}
	for(int i = 0; i < n; i++)
		arr[i] = mp[arr[i]];
	for(int i = 0; i < n; i++)
		cnt[arr[i]]++;
	long long ans = 0;
	for(int i = 0; i < n; i++) {
		now[arr[i]]++;
		ans += max(0,cnt[arr[i]] - now[arr[i]]);
	}
	printf("%lld", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fun(int n)
{
	if(n<=1)
		return n;
	if(n%2==0)
	{
		return fun(n/2);
	}
	return fun(n/2)+1;
}

int main()
{
    long long int i,j=0,k=0,c=0,n,mm;
    cin>>n;
    map<long,int>m;
    for (i = 0; i <n; ++i)
    {
    	cin>>mm;
    	k=fun(mm);
    	m[k]++;
    }
    //map<long,int>:: iterator it=m.begin();
    for(auto it : m)
    	j+=(1ll*it.second*(it.second-1))/2;
    cout<<j;

}


#include<bits/stdc++.h>
using namespace std;
long fun(long n)
{
	if(n<=1)
		return n;
	if(n%2==0)
	{
		return fun(n/2);
	}
	return fun(n/2)+1;
}

int main()
{
    long int i,j=0,k=0,c=0,n,mm;
    cin>>n;
    map<long,int>m;
    for (i = 0; i <n; ++i)
    {
    	cin>>mm;
    	k=fun(mm);
    	m[k]++;
    }
    //map<long,int>:: iterator it=m.begin();
    for(auto it : m)
    	j+=(it.second*(it.second-1))/2;
    cout<<j;

}


#include<bits/stdc++.h>
using namespace std;
int cont[100000009],a[100009];
int main()
{
    int n,sum=0,m,num=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1; i<=n; i++)
    {
        sum=0;
        m=a[i];
        while(m>0)
        {
            int p=m%2;
            if(p!=0)
            {
                sum++;
            }
            m/=2;
        }
        cont[sum]++;
    }
    for(int i=1; i<=n; i++)
    {

        num+=(cont[i]*(cont[i]-1)/2);
    }
    printf("%d",num);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int cont[1000009],a[100009];
int main()
{
    int n,sum=0,m,num=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1; i<=n; i++)
    {
        sum=0;
        m=a[i];
        while(m>0)
        {
            int p=m%2;
            if(p!=0)
            {
                sum++;
            }
            m/=2;
        }
        cont[sum]++;
    }
    for(int i=1; i<=n; i++)
    {

        num+=(cont[i]*(cont[i]-1)/2);
    }
    printf("%d",num);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
map<ll,ll>m1;
ll cont[1000009],a[100009];
int main()
{
    ll n,sum=0,m,num=0;
    scanf("%I64d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d",&a[i]);
    }
    for(int i=1; i<=n; i++)
    {
        sum=0;
        m=a[i];
        while(m>0)
        {
            ll p=m%2;
            if(p!=0)
            {
                sum++;
            }
            m/=2;
        }
        m1[sum]++;
    }
    for(int i=1; i<=100009; i++)
    {

        num+=(m1[i]*(m1[i]-1)/2);
    }
    printf("%I64d",num);
    return 0;
}


// Template from Benq which is changed according to me.
// https://codeforces.com/profile/Benq
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using db = double;
using str = string;

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define tcT template<class T
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;

// pairs
#define mp make_pair
#define fi first
#define se second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define sorr(x) sort(all(x), greater<int>());
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const ll INF = 1e18; // not too close to LLONG_MAX
const ll infl = 1e18 + 5;
const int infi = 1e9 + 5;
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; } // set a = max(a,b)

#define tcTU tcT, class U
tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(u); } // element that doesn't exist from (multi)set

// INPUT
#define tcTUU tcT, class ...U
tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }
tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.fi,p.se); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;
	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.fi)+", "+ts(p.se)+")";
	#else
		return ts(p.fi)+" "+ts(p.se);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); } // same line
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces // next line
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
#ifndef ONLINE_JUDGE
#define dbg(a) cerr << #a << ": "; pdbg(a); cerr << endl;
#else
#define dbg(a) // No more TLEs
#endif
void pdbg(ll t){cerr<<t;}
void pdbg(int t){cerr<<t;}
void pdbg(str t){cerr<<t;}
void pdbg(char t){cerr<<t;}
void pdbg(ld t){cerr<<t;}
void pdbg(db t){cerr<<t;}
void pdbg(ull t){cerr<<t;}
tcT, class V> void pdbg(pair <T, V> p){cerr<< "{";pdbg(p.fi);cerr<<",";pdbg(p.se);cerr<<"}";}
tcT> void pdbg(vector <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(set <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(multiset <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT, class V> void pdbg(map <T, V> v){cerr<<"[ ";for(auto i: v){pdbg(i);cerr<<" ";}cerr << "]";}

void solve() {
	ll n;
	re(n);
	vl v;
	v.rsz(n);
	re(v);
	map<int, int> m;
	FOR(i, 0, n){
		bitset<32> b(v[i]);
		int n1=b.count();
		if(m.find(n1)!=m.end()){
			m[n1]+=1;
		} else {
			m[n1]=1;
		}
	}
	// dbg(m);
	int ans=0;
	for(auto i: m){
		ans+=(i.se*(i.se-1)/2);
	}
	cout<<ans<<endl;
}

int main() {
	fastio;
	#ifndef ONLINE_JUDGE
		freopen("../input.txt", "r", stdin);
		freopen("../error.txt", "w", stderr);
		freopen("../output.txt", "w", stdout);
	#endif
	ll T = 1;
	// re(T);
	F0R(i,T) solve();
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


// Template from Benq which is changed according to me.
// https://codeforces.com/profile/Benq
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using db = double;
using str = string;

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define tcT template<class T
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;

// pairs
#define mp make_pair
#define fi first
#define se second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define sorr(x) sort(all(x), greater<int>());
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const ll INF = 1e18; // not too close to LLONG_MAX
const ll infl = 1e18 + 5;
const int infi = 1e9 + 5;
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; } // set a = max(a,b)

#define tcTU tcT, class U
tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(u); } // element that doesn't exist from (multi)set

// INPUT
#define tcTUU tcT, class ...U
tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }
tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.fi,p.se); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;
	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.fi)+", "+ts(p.se)+")";
	#else
		return ts(p.fi)+" "+ts(p.se);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); } // same line
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces // next line
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
#ifndef ONLINE_JUDGE
#define dbg(a) cerr << #a << ": "; pdbg(a); cerr << endl;
#else
#define dbg(a) // No more TLEs
#endif
void pdbg(ll t){cerr<<t;}
void pdbg(int t){cerr<<t;}
void pdbg(str t){cerr<<t;}
void pdbg(char t){cerr<<t;}
void pdbg(ld t){cerr<<t;}
void pdbg(db t){cerr<<t;}
void pdbg(ull t){cerr<<t;}
tcT, class V> void pdbg(pair <T, V> p){cerr<< "{";pdbg(p.fi);cerr<<",";pdbg(p.se);cerr<<"}";}
tcT> void pdbg(vector <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(set <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(multiset <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT, class V> void pdbg(map <T, V> v){cerr<<"[ ";for(auto i: v){pdbg(i);cerr<<" ";}cerr << "]";}

void solve() {
	ll n;
	re(n);
	vl v;
	v.rsz(n);
	re(v);
	map<int, int> m;
	FOR(i, 0, n){
		bitset<64> b(v[i]);
		int n1=b.count();
		if(m.find(n1)!=m.end()){
			m[n1]+=1;
		} else {
			m[n1]=1;
		}
	}
	dbg(m);
	int ans=0;
	for(auto i: m){
		ans+=(i.se*(i.se-1)/2);
	}
	cout<<ans<<endl;
}

int main() {
	fastio;
	#ifndef ONLINE_JUDGE
		freopen("../input.txt", "r", stdin);
		freopen("../error.txt", "w", stderr);
		freopen("../output.txt", "w", stdout);
	#endif
	ll T = 1;
	// re(T);
	F0R(i,T) solve();
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


// Template from Benq which is changed according to me.
// https://codeforces.com/profile/Benq
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using db = double;
using str = string;

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define tcT template<class T
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;

// pairs
#define mp make_pair
#define fi first
#define se second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define sorr(x) sort(all(x), greater<int>());
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const ll INF = 1e18; // not too close to LLONG_MAX
const ll infl = 1e18 + 5;
const int infi = 1e9 + 5;
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; } // set a = max(a,b)

#define tcTU tcT, class U
tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(u); } // element that doesn't exist from (multi)set

// INPUT
#define tcTUU tcT, class ...U
tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }
tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.fi,p.se); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;
	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.fi)+", "+ts(p.se)+")";
	#else
		return ts(p.fi)+" "+ts(p.se);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); } // same line
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces // next line
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
#ifndef ONLINE_JUDGE
#define dbg(a) cerr << #a << ": "; pdbg(a); cerr << endl;
#else
#define dbg(a) // No more TLEs
#endif
void pdbg(ll t){cerr<<t;}
void pdbg(int t){cerr<<t;}
void pdbg(str t){cerr<<t;}
void pdbg(char t){cerr<<t;}
void pdbg(ld t){cerr<<t;}
void pdbg(db t){cerr<<t;}
void pdbg(ull t){cerr<<t;}
tcT, class V> void pdbg(pair <T, V> p){cerr<< "{";pdbg(p.fi);cerr<<",";pdbg(p.se);cerr<<"}";}
tcT> void pdbg(vector <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(set <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(multiset <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT, class V> void pdbg(map <T, V> v){cerr<<"[ ";for(auto i: v){pdbg(i);cerr<<" ";}cerr << "]";}

void solve() {
	ll n;
	re(n);
	ll c;
	map<int, int> m;
	FOR(i, 0, n){
		re(c);
		bitset<64> b(c);
		int n1=b.count();
		if(m.find(n1)!=m.end()){
			m[n1]+=1;
		} else {
			m[n1]=1;
		}
	}
	dbg(m);
	int ans=0;
	for(auto i: m){
		ans+=(i.se*(i.se-1)/2);
	}
	cout<<ans<<endl;
}

int main() {
	fastio;
	#ifndef ONLINE_JUDGE
		freopen("../input.txt", "r", stdin);
		freopen("../error.txt", "w", stderr);
		freopen("../output.txt", "w", stdout);
	#endif
	ll T = 1;
	// re(T);
	F0R(i,T) solve();
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


// Template from Benq which is changed according to me.
// https://codeforces.com/profile/Benq
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using db = double;
using str = string;

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define tcT template<class T
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;

// pairs
#define mp make_pair
#define fi first
#define se second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define sorr(x) sort(all(x), greater<int>());
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const ll INF = 1e18; // not too close to LLONG_MAX
const ll infl = 1e18 + 5;
const int infi = 1e9 + 5;
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; } // set a = max(a,b)

#define tcTU tcT, class U
tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(u); } // element that doesn't exist from (multi)set

// INPUT
#define tcTUU tcT, class ...U
tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }
tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.fi,p.se); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;
	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.fi)+", "+ts(p.se)+")";
	#else
		return ts(p.fi)+" "+ts(p.se);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); } // same line
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces // next line
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
#ifndef ONLINE_JUDGE
#define dbg(a) cerr << #a << ": "; pdbg(a); cerr << endl;
#else
#define dbg(a) // No more TLEs
#endif
void pdbg(ll t){cerr<<t;}
void pdbg(int t){cerr<<t;}
void pdbg(str t){cerr<<t;}
void pdbg(char t){cerr<<t;}
void pdbg(ld t){cerr<<t;}
void pdbg(db t){cerr<<t;}
void pdbg(ull t){cerr<<t;}
tcT, class V> void pdbg(pair <T, V> p){cerr<< "{";pdbg(p.fi);cerr<<",";pdbg(p.se);cerr<<"}";}
tcT> void pdbg(vector <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(set <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(multiset <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT, class V> void pdbg(map <T, V> v){cerr<<"[ ";for(auto i: v){pdbg(i);cerr<<" ";}cerr << "]";}

void solve() {
	ll n;
	re(n);
	ll c;
	map<int, int> m;
	FOR(i, 0, n){
		re(c);
		bitset<64> b(c);
		int n1=b.count();
		if(m.find(n1)!=m.end()){
			m[n1]+=1;
		} else {
			m[n1]=1;
		}
	}
	// dbg(m);
	ll ans=0;
	for(auto i: m){
		ans+=((i.se*(i.se-1))/2);
	}
	cout<<ans<<endl;
}

int main() {
	fastio;
	#ifndef ONLINE_JUDGE
		freopen("../input.txt", "r", stdin);
		freopen("../error.txt", "w", stderr);
		freopen("../output.txt", "w", stdout);
	#endif
	ll T = 1;
	// re(T);
	F0R(i,T) solve();
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


// Template from Benq which is changed according to me.
// https://codeforces.com/profile/Benq
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using db = double;
using str = string;

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define tcT template<class T
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;

// pairs
#define mp make_pair
#define fi first
#define se second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define sorr(x) sort(all(x), greater<int>());
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const ll INF = 1e18; // not too close to LLONG_MAX
const ll infl = 1e18 + 5;
const int infi = 1e9 + 5;
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; } // set a = max(a,b)

#define tcTU tcT, class U
tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(u); } // element that doesn't exist from (multi)set

// INPUT
#define tcTUU tcT, class ...U
tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }
tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.fi,p.se); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;
	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.fi)+", "+ts(p.se)+")";
	#else
		return ts(p.fi)+" "+ts(p.se);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); } // same line
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces // next line
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
#ifndef ONLINE_JUDGE
#define dbg(a) cerr << #a << ": "; pdbg(a); cerr << endl;
#else
#define dbg(a) // No more TLEs
#endif
void pdbg(ll t){cerr<<t;}
void pdbg(int t){cerr<<t;}
void pdbg(str t){cerr<<t;}
void pdbg(char t){cerr<<t;}
void pdbg(ld t){cerr<<t;}
void pdbg(db t){cerr<<t;}
void pdbg(ull t){cerr<<t;}
tcT, class V> void pdbg(pair <T, V> p){cerr<< "{";pdbg(p.fi);cerr<<",";pdbg(p.se);cerr<<"}";}
tcT> void pdbg(vector <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(set <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT> void pdbg(multiset <T> v){cerr<<"[ ";for(T i: v){pdbg(i);cerr<<" ";}cerr << "]";}
tcT, class V> void pdbg(map <T, V> v){cerr<<"[ ";for(auto i: v){pdbg(i);cerr<<" ";}cerr << "]";}

void solve() {
	ll n;
	re(n);
	ll c;
	map<int, ll> m;
	FOR(i, 0, n){
		re(c);
		bitset<32> b(c);
		int n1=b.count();
		if(m.find(n1)!=m.end()){
			m[n1]+=1;
		} else {
			m[n1]=1;
		}
	}
	// dbg(m);
	ll ans=0;
	for(auto i: m){
		ans+=((i.se*(i.se-1))/2);
	}
	cout<<ans<<endl;
}

int main() {
	fastio;
	#ifndef ONLINE_JUDGE
		freopen("../input.txt", "r", stdin);
		freopen("../error.txt", "w", stderr);
		freopen("../output.txt", "w", stdout);
	#endif
	ll T = 1;
	// re(T);
	F0R(i,T) solve();
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


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

int main()
{
    long long n;
    cin >> n;
    long long a[n+5],b=0,c[1000000]={0};
    for(long long i=0;i<n;i++)
    {
        cin >> a[i];
        b=0;
        while(a[i] > 0)
        {
            if(a[i]%2==1) b++;
            a[i]/=2;
        }
        c[b]++;
    }
    long long ans=0;
    for(long long i=0;i<10000;i++)
    {
        ans+= (c[i]*(c[i]-1))/2;
    }
    cout << ans;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = static_cast<int>(1e9);
const long long LLINF = static_cast<long long>(4e18);
const double pi = acos(-1.0);

#define error(x) cerr << #x << " = " << x << endl
#define sz(a) static_cast<int>((a).size())
#define all(a) (a).begin(), (a).end()
#define sq(x) (x) * (x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

#define UNIQUE(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define FOR(i, a, b) for (int i(a), b_(b); i < b_; ++i)
#define REP(i, n) FOR (i, 0, n)
#define FORD(i, a, b) for (int i(a), b_(b); i >= b_; --i)

int n;
ll res;

int f(int x) {
    return __builtin_popcount(x);
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(nullptr);
    cin >> n;
    vector<int> cnt(10, 0);
    REP(i, n) {
        int x; cin >> x;
        ++cnt[f(x)];
    }
    REP(i, 10) {
        res += cnt[i] * (cnt[i]-1) / 2;
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = static_cast<int>(1e9);
const long long LLINF = static_cast<long long>(4e18);
const double pi = acos(-1.0);

#define error(x) cerr << #x << " = " << x << endl
#define sz(a) static_cast<int>((a).size())
#define all(a) (a).begin(), (a).end()
#define sq(x) (x) * (x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

#define UNIQUE(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define FOR(i, a, b) for (int i(a), b_(b); i < b_; ++i)
#define REP(i, n) FOR (i, 0, n)
#define FORD(i, a, b) for (int i(a), b_(b); i >= b_; --i)

int n;
ll res;

int f(int x) {
    return __builtin_popcount(x);
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(nullptr);
    cin >> n;
    vector<ll> cnt(111, 0);
    REP(i, n) {
        int x; cin >> x;
        cnt[f(x)]++;
    }
    REP(i, sz(cnt)) {
        res += cnt[i] * (cnt[i]-1) / 2;
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = static_cast<int>(1e9);
const long long LLINF = static_cast<long long>(4e18);
const double pi = acos(-1.0);

#define error(x) cerr << #x << " = " << x << endl
#define sz(a) static_cast<int>((a).size())
#define all(a) (a).begin(), (a).end()
#define sq(x) (x) * (x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

#define UNIQUE(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define FOR(i, a, b) for (int i(a), b_(b); i < b_; ++i)
#define REP(i, n) FOR (i, 0, n)
#define FORD(i, a, b) for (int i(a), b_(b); i >= b_; --i)

int n;
ll res;

int f(int x) {
    return __builtin_popcount(x);
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(nullptr);
    cin >> n;
    vector<int> cnt(100, 0);
    REP(i, n) {
        int x; cin >> x;
        ++cnt[f(x)];
    }
    REP(i, 10) {
        res += cnt[i] * (cnt[i]-1) / 2;
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = static_cast<int>(1e9);
const long long LLINF = static_cast<long long>(4e18);
const double pi = acos(-1.0);

#define error(x) cerr << #x << " = " << x << endl
#define sz(a) static_cast<int>((a).size())
#define all(a) (a).begin(), (a).end()
#define sq(x) (x) * (x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

#define UNIQUE(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define FOR(i, a, b) for (int i(a), b_(b); i < b_; ++i)
#define REP(i, n) FOR (i, 0, n)
#define FORD(i, a, b) for (int i(a), b_(b); i >= b_; --i)

int n;
ll res;

int f(int x) {
    if (x == 0) return 0;
    return (x&1) + f(x/2);
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(nullptr);
    cin >> n;
    vector<int> a(n);
    REP(i, n) {
        int x; cin >> x;
        a[i] = f(x);
    }
    REP(i, n) {
        FOR(j, i+1, n) if (a[i] == a[j]) ++res;
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = static_cast<int>(1e9);
const long long LLINF = static_cast<long long>(4e18);
const double pi = acos(-1.0);

#define error(x) cerr << #x << " = " << x << endl
#define sz(a) static_cast<int>((a).size())
#define all(a) (a).begin(), (a).end()
#define sq(x) (x) * (x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

#define UNIQUE(a) sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define FOR(i, a, b) for (int i(a), b_(b); i < b_; ++i)
#define REP(i, n) FOR (i, 0, n)
#define FORD(i, a, b) for (int i(a), b_(b); i >= b_; --i)

int n;
ll res;

int f(int x) {
    return __builtin_popcount(x);
}

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(nullptr);
    cin >> n;
    vector<int> cnt(100, 0);
    REP(i, n) {
        int x; cin >> x;
        ++cnt[f(x)];
    }
    REP(i, sz(cnt)) {
        res += cnt[i] * (cnt[i]-1) / 2;
    }
    cout << res << endl;
    return 0;
}


#include <vector>
#include <stdio.h>
#include <string.h>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <unordered_map>

#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int  n, m, k;
bool visited[100005];
map<ll, ll>cnt;
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 }; int ret;
vector<vector<int > >adjlist;
int a[1000000];
ll power(ll a, ll b)
{
	if (b == 1)
	{
		return a;
	}
	if (b == 0)
	{
		return 1;
	}
	if (b % 2 == 0)
	{
		return power(a*a, b / 2);
	}
	else
	{
		return a*power(a, (b - 1));
	}
}
long long C(int n, int r)
{
	if (r == 0)
		return 0;
	if (r > n / 2) r = n - r;
	long long ans = 1;
	for (int i = 1; i <= r; i++)
	{
		ans *= n - r + i;
		ans /= i;
	}
	return ans;
}
int main()
{
	std::cin.tie();
	std::ios::sync_with_stdio(false);
	cin >> n;
	ll res = 0;
	while (n--)
	{
		res = 0;
		ll a; cin >> a;
		while (a)
		{
			res += (a % 2);
			a /= 2;
		}
		cnt[res]++;
	}
	res = 0;
	for (map<ll, ll>::iterator it = cnt.begin(); it != cnt.end(); it++)
	{
		if (it->second > 1)
			res += ((it->second)*((it->second - 1)) / 2);
	}
	cout << res << endl;
	return 0;
}


#include <vector>
#include <stdio.h>
#include <string.h>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <unordered_map>

#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int  n, m, k;
bool visited[100005];
map<ll, ll>cnt;
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 }; int ret;
vector<vector<int > >adjlist;
int a[1000000];
ll power(ll a, ll b)
{
	if (b == 1)
	{
		return a;
	}
	if (b == 0)
	{
		return 1;
	}
	if (b % 2 == 0)
	{
		return power(a*a, b / 2);
	}
	else
	{
		return a*power(a, (b - 1));
	}
}
long long C(int n, int r)
{
	if (r == 0)
		return 0;
	if (r > n / 2) r = n - r;
	long long ans = 1;
	for (int i = 1; i <= r; i++)
	{
		ans *= n - r + i;
		ans /= i;
	}
	return ans;
}
int main()
{
	std::cin.tie();
	std::ios::sync_with_stdio(false);
	cin >> n;
	ll res = 0;
	while (n--)
	{
		res = 0;
		ll a; cin >> a;
		while (a)
		{
			res += (a % 2);
			a /= 2;
		}
		cnt[res]++;
	}
	res = 0;
	for (map<ll, ll>::iterator it = cnt.begin(); it != cnt.end(); it++)
	{
		if (it->second > 1)
		{
			if (it->second == 2)
				res++;
			else
				res += it->second;
		}
	}
	cout << res << endl;
	return 0;
}


import java.util.Scanner;

public class colonel {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int seconds = 0;
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int arrLengths[] = new int[n];

		for(int i=0 ; i<n ; i++){
			arrLengths[i]=input.nextInt();

		}
		int minIndex=0;
		for(int i=1 ; i<arrLengths.length;i++){
			if(arrLengths[i]<=arrLengths[minIndex]){
				minIndex=i;
			}
		}
		for(int i=minIndex;i<arrLengths.length-1;i++){
			int temp = arrLengths[i];
			arrLengths[i]=arrLengths[i+1];
			arrLengths[i+1]=temp;
			seconds++;
		}
		int maxIndex = 0;
		for(int i=1 ; i< arrLengths.length;i++){
			if(arrLengths[i]>=arrLengths[maxIndex]){
				maxIndex=i;
			}
		}
		for(int i=maxIndex ; i>0;i--){
			int temp = arrLengths[i];
			arrLengths[i]=arrLengths[i-1];
			arrLengths[i-1]=temp;
			seconds++;
		}
		System.out.println(seconds);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(bf.readLine());
		int[] a = new int[x];
		StringTokenizer st = new StringTokenizer(bf.readLine());
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		int count = 0;
		int minIndex = 0;
		int maxIndex = a.length - 1;
		int max = a[maxIndex];
		int min = a[minIndex];
		for (int i = maxIndex-1; i >= 0; i--) {
			if (a[i] >= max)
			{
				maxIndex = i;
				max = a[i];
			}
		}
		for (int i = minIndex+1; i < a.length; i++) {
			if (a[i] <= min)
			{
				minIndex = i;
				min = a[i];
			}
		}

		count = maxIndex + ((a.length-1) - minIndex);
		if (minIndex < maxIndex)
			count--;
		System.out.println(count);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(bf.readLine());
        int[] a = new int[x];
        StringTokenizer st = new StringTokenizer(bf.readLine());
        for (int i = 0; i < a.length; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }
        int count = 0;
        int max = a[a.length - 1];
        int min = a[0];
        int minIndex = 0;
        int maxIndex = 0;
        for (int i = 1; i < a.length; i++) {

            if (a[i] >= max) {
                max = a[i];
                maxIndex = i;
            }
        }
        for (int i = maxIndex; i > 0; i--) {
            int tmp = a[i];
            a[i] = a[i - 1];
            a[i - 1] = tmp;
            count++;
        }
        for (int i = 1; i < a.length; i++) {
            if (a[i] <= min) {
                min = a[i];
                minIndex = i;
            }
        }
        for (int i = minIndex; i < a.length - 1; i++) {
            int tmp = a[i];
            a[i] = a[i + 1];
            a[i + 1] = tmp;
            count++;
        }

        System.out.println(count);
    }
}


import java.util.*;
import java.io.*;
public class A144
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[] = new int[n];
        for( int i = 0; i<n; i++)
            a[i] = in.nextInt();
        int max =a[0], min =a[0], x =0, y =0;
        for(int i =1; i<n; i++)
        {
           if(a[i]> max)
              max = a[i];
           else if(a[i]<= min)
              min = a[i];
        }
        for(int i =0; i<n; i++)
        {
            if( a[i] == max)
            {
                x = i+1;
                break;
            }
        }
        for(int i =0; i<n; i++)
        {
            if( a[i] == min)
            {
               y = i+1;
            }
        }
        int c = x-1 + n-y;
        if( y < x)
        {
            System.out.println(c-1);
        }
        else
        {
            System.out.println(c);
        }
    }
}


import java.util.*;
import java.io.*;
public class A144
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[] = new int[n];
        for( int i = 0; i<n; i++)
            a[i] = in.nextInt();
        int max =a[0], min =a[0], x =0, y =0;
        for(int i =1; i<n; i++)
        {
           if(a[i]> max)
              max = a[i];
           else if(a[i]<= min)
              min = a[i];
        }
        for(int i =0; i<n; i++)
        {
            if( a[i] == max)
            {
                x = i;
                break;
            }
        }
        for(int i =0; i<n; i++)
        {
            if( a[i] == min)
            {
               y = i+1;
            }
        }
        int c = x + n-y;
        if( y < x)
        {
            System.out.println(c-1);
        }
        else
        {
            System.out.println(c);
        }
    }
}


import java.util.*;
import java.io.*;
public class A144
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[] = new int[n];
        for( int i = 0; i<n; i++)
            a[i] = in.nextInt();
        int max =a[0], min =a[0], x =0, y =0;
        for(int i =1; i<n; i++)
        {
           if(a[i]> max)
              max = a[i];
           else if(a[i]<= min)
              min = a[i];
        }
        for(int i =0; i<n; i++)
        {
            if( a[i] == max)
            {
                x = i+1;
                break;
            }
        }
        for(int i =0; i<n; i++)
        {
            if( a[i] == min)
            {
               y = i+1;
            }
        }
        int c = x-1 + n-y;
        if( y < x)
        {
            System.out.println(c+1);
        }
        else
        {
            System.out.println(c);
        }
    }
}


import java.util.Scanner;

public class ArrivalOfTheGeneral {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] heights = new int[n];
		for(int i =0 ; i<n;i++){
			heights[i] = input.nextInt();
		}
		int min = 101;
		int max = -1;
		int indexOfMax = -1;
		int indexOfMin = -1;
		for(int i = 0; i<n;i++){
			//near from left
			if(max<heights[i]){
				max = heights[i];
				indexOfMax = i;
			}
			//near from right
			if(min >= heights[i]){
				min = heights[i];
				indexOfMin = i;
			}
		}
		heights[1] = heights[0];
		int total = indexOfMax + n -1 - indexOfMin;
		if(indexOfMin < indexOfMax){
			total--;
		}
		System.out.print(total);
	}

}


import java.util.Scanner;

public class arrivalofgeneral {

    public static void main(String[] args) {
        int num,max=-1000,min=1000;
        int countermin=0,countermax=0;
         Scanner  input = new Scanner (System.in);
        num = input.nextInt();
        int heights []=new int [num];
        for(int i=0;i<num;i++){
            heights[i]=input.nextInt();
            if(max<heights[i]){
                max=heights[i];
                countermax=i;
            }
            if (min>=heights[i]){
                min=heights[i];
                countermin=i;
            }
        }
        int size = countermax+Math.abs(num-1-countermin);
        if(countermax>countermin){
            size--;
        }
        System.out.println(size);
    }

}


import java.io.*;
public class arrival {
	public static void main(String args[])throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine());
		String a[]=in.readLine().split(" ");
		int b[]=new int[n];
		int min=Integer.parseInt(a[0]),max=0;
		int minpos=0,maxpos=0;
		for(int i=0;i<n;i++)
		{
			b[i]=Integer.parseInt(a[i]);
			if(b[i]<=min)
			{
				min=b[i];
				minpos=i;
			}
			if(b[i]>max)
			{
				max=b[i];
				maxpos=i;
			}

		}
		int x;
		if(minpos<maxpos)
			x=2;
		else
			x=1;
		int r=maxpos+n-minpos-x;
		System.out.println(r);
	}
}