Counting Pairs

시간 제한1초메모리 제한2048 MB

요약
정수 목록이 주어질 때, 이진법 자리별 합을 2로 나눈 값과 사진법 자리별 합을 4로 나눈 값이 서로 같은 쌍의 개수를 센다.
난이도

보통10점 중 6점

유형
비트 연산, 해시맵, 수학, 조합론
정답자
아직 제출이 없습니다

문제

Consider the binary operator ⊕_b(x,y)\oplus\_b(x, y) that is defined for b∈2,4b \in \\{2, 4\\} as follows. First, convert both xx and yy into base bb. Then, for each corresponding digit pair, the resulting digit can be calculated by adding the digit pair modulo bb. Finally, convert the result back to base ten. Notice that ⊕_2\oplus\_2 is the bitwise XOR operator.

For instance, ⊕_4(18,7)=21\oplus\_4(18, 7) = 21 can be calculated as follows. The base four representations of 1818 and 77 are (102)_4(102)\_4 and (013)_4(013)\_4, respectively. After the addition for each digit pair, the result is (111)_4(111)\_4, or 2121 in base ten.

You are given a list of NN integers, A_1,A_2,…,A_NA\_1, A\_2, \dots , A\_N.

Determine the number of pairs (i,j)(i, j) such that 1≤i<j≤N1 ≤ i < j ≤ N and ⊕_2(A_i,A_j)=⊕_4(A_i,A_j)\oplus\_2(A\_i , A\_j ) = \oplus\_4(A\_i , A\_j ).

입력

The first line consists of an integer NN (2≤N≤200,0002 ≤ N ≤ 200\\, 000).

The next line consists of NN integers A_iA\_i (0≤A_i≤10120 ≤ A\_i ≤ 10^{12}).

출력

Output a single integer representing the number of pairs (i,j)(i, j) such that 1≤i<j≤N1 ≤ i < j ≤ N and ⊕_2(A_i,A_j)=⊕_4(A_i,A_j)\oplus\_2(A\_i , A\_j ) = \oplus\_4(A\_i , A\_j ).

예제4

  1. 예제 1

    입력
    5
    2 2 0 1 3
    
    예상 출력
    9
    
  2. 예제 2

    입력
    2
    17 13
    
    예상 출력
    0
    
  3. 예제 3

    입력
    10
    13 7 29 4 18 0 4 21 12 20
    
    예상 출력
    14
    
  4. 예제 4

    입력
    10
    0 0 0 0 0 0 0 0 0 0
    
    예상 출력
    45