Logo Infinity Online Judge

InfOJ

时间限制:2 s 空间限制:1024 MB

#144. min max xor sum

Statistics

题目描述

给出一个长度为 $n$ 的序列 $[a_{1...n}]$,求

$$ \sum_{l=1}^n\sum_{r=l}^n \max(\min_{l\le i\le r}a_i,\mathop{\mathrm{xor}}\limits_{l\le i\le r} a_i) $$

输入格式

第一行一个正整数 $n$。$(1\le n\le 2\times 10^5)$

接下来一行 $n$ 个非负整数 $a_1\sim a_n$。$(0\le a_i\le 131071)$

输出格式

输出一行一个非负整数,为答案。

样例

输入

10
10 5 2 14 7 2 0 12 4 2

输出

432