PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000188. Tổng kép và phần lẻ (Double Sum 2)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng kép và phần lẻ (Double Sum 2)

Double Sum 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

For positive integer xx, let f(x)f(x) be its odd part, obtained by repeatedly dividing xx by 22 while it remains even. For instance, f(8)=1f(8)=1, f(12)=3f(12)=3, f(7)=7f(7)=7. Given A1,…,ANA_1,\ldots,A_N, compute the exact value

S=∑i=1N∑j=iNf(Ai+Aj).S=\sum_{i=1}^{N}\sum_{j=i}^{N} f(A_i+A_j).

Include diagonal pairs i=ji=j, and count each pair with i<ji<j only once. Do not take a modulus.

Input

The first line contains NN. The second line contains NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N.

Output

Print the exact integer SS.

Subtasks

  • Subtask 1 (20 points): 1≤N≤801 \le N \le 80, 1≤Ai≤10001 \le A_i \le 1000.

  • Subtask 2 (30 points): 1≤N≤50001 \le N \le 5000, 1≤Ai≤10000001 \le A_i \le 1000000.

  • Subtask 3 (50 points): 1≤N≤2000001 \le N \le 200000, 1≤Ai≤100000001 \le A_i \le 10000000.

Examples

Example 1

Input

2
4 8

Output

5

Explanation

The three pairs i≤ji\le j have sums 8,12,168,12,16, whose odd parts are 1,3,11,3,1. Their total is 55.

Example 2

Input

3
51 44 63

Output

384

Explanation

The six pairs have sums 102,95,114,88,107,126102,95,114,88,107,126, with odd parts 51,95,57,11,107,6351,95,57,11,107,63; their sum is 384384.

Example 3

Input

8
577752 258461 183221 889769 278633 577212 392309 326001

Output

20241214

Explanation

Adding the odd parts of all 36 sums with i≤ji\le j yields 2024121420241214.