atcoder#ARC127D. [ARC127D] Sum of Min of Xor

[ARC127D] Sum of Min of Xor

Score : 700700 points

Problem Statement

Given are sequences of NN integers each: (A1,A2,,AN)(A_1,A_2,\cdots,A_N) and (B1,B2,,BN)(B_1,B_2,\cdots,B_N).

Find $\sum_{1 \leq i < j \leq N} \min(A_i \oplus A_j, B_i \oplus B_j)$, where \oplus denotes the bitwise XOR.

Constraints

  • 1N2500001 \leq N \leq 250000
  • 0Ai,Bi<2180 \leq A_i,B_i < 2^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

B1B_1 B2B_2 \cdots BNB_N

Output

Print the answer.

3
1 2 3
4 5 6
4
  • min(12,45)=min(3,1)=1\min(1 \oplus 2, 4 \oplus 5)=\min(3,1)=1
  • min(13,46)=min(2,2)=2\min(1 \oplus 3, 4 \oplus 6)=\min(2,2)=2
  • min(23,56)=min(1,3)=1\min(2 \oplus 3, 5 \oplus 6)=\min(1,3)=1

Thus, the answer is 1+2+1=41+2+1=4.

4
1 2 3 4
1 2 3 4
24
10
195247 210567 149398 9678 23694 46151 187762 17915 176476 249828
68649 128425 249346 62366 194119 117620 26327 161384 207 57656
4019496