//Codeforces Round #167 (Div. 2) B Dima and Sequence
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
public static void main(String[] args) throws IOException {
// helpers for input/output
boolean LOCAL_TEST = false;// change to false before submitting
out = System.out;
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin2.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
private static void solve() throws IOException
{
int n = in.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
}
long[] fa = new long[n];
for (int i = 0; i < n; i++) {
fa[i] = f(a[i]);
}
Arrays.sort(fa);
long pairs = 0;
long cnt = 1;
for (int i = 1; i < n; i++) {
if (fa[i] == fa[i - 1]) {
cnt++;
}
else {
if (cnt > 1) {
long newPairs = ((cnt * cnt) - cnt) / 2;
pairs += newPairs;
}
cnt = 1;
}
}
if (cnt > 1) {
long newPairs = ((cnt * cnt) - cnt) / 2;
pairs += newPairs;
}
out.println(pairs);
}
static long f(long x)
{
if (x == 0)
return 0;
else if (x % 2 == 0)
return f(x / 2);
else
return f(x / 2) + 1;
}
// =====================================
static class MyScanner {
Scanner inp = null;
public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}
public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}
public int nextInt() throws IOException {
return inp.nextInt();
}
public long nextLong() throws IOException {
return inp.nextLong();
}
public double nextDouble() throws IOException {
return inp.nextDouble();
}
public String nextString() throws IOException {
return inp.next();
}
}
}
No comments:
Post a Comment