Under construction

Still being built. Things may change

Counting Pairs

Time limit1sMemory limit2048 MB

Summary
Count pairs (i, j) where A_i and A_j never both have a 1 at the same even bit position (bits 0, 2, 4, ...), which is exactly when the base-2 and base-4 results match.
Level

Medium6 of 10

Topics
Bit manipulation, Dynamic programming
Solved
No attempts yet

Problem

Consider the binary operator ⊕b(x,y)\oplus_b(x, y) defined for b∈{2,4}b \in \{2, 4\} as follows. First, convert both xx and yy into base bb. Then, for each corresponding digit pair, the resulting digit is the sum of the digit pair modulo bb. Finally, convert the result back to base ten. Note that ⊕2\oplus_2 is the bitwise XOR operator.

For instance, ⊕4(18,7)=21\oplus_4(18, 7) = 21. The base four representations of 18 and 7 are (102)4(102)_4 and (013)4(013)_4. Adding each digit pair gives (111)4(111)_4, which is 21 in base ten.

You are given a list of NN integers, A1,A2,…,ANA_1, A_2, \dots, A_N. Count the pairs (i,j)(i, j) with 1≤i<j≤N1 \le i < j \le N such that ⊕2(Ai,Aj)=⊕4(Ai,Aj)\oplus_2(A_i, A_j) = \oplus_4(A_i, A_j).

Input

The first line contains an integer NN (2≤N≤2000002 \le N \le 200000). The second line contains NN integers A1,A2,…,ANA_1, A_2, \dots, A_N (0≤Ai≤10120 \le A_i \le 10^{12}).

Output

Print a single integer, the number of pairs (i,j)(i, j) such that 1≤i<j≤N1 \le i < j \le N and ⊕2(Ai,Aj)=⊕4(Ai,Aj)\oplus_2(A_i, A_j) = \oplus_4(A_i, A_j).

Examples4

  1. Example 1

    Input
    5
    2 2 0 1 3
    
    Expected output
    9
    
  2. Example 2

    Input
    2
    17 13
    
    Expected output
    0
    
  3. Example 3

    Input
    10
    13 7 29 4 18 0 4 21 12 20
    
    Expected output
    14
    
  4. Example 4

    Input
    10
    0 0 0 0 0 0 0 0 0 0
    
    Expected output
    45