Public Judge

pjudge

时间限制: 1 s 内存限制: 512 MB 总分: 100 可 Hack ✓
统计

Given a sequence of $n$ non-negative integers $[a_1, \dots, a_n]$, find a subsequence $[a_{i_1}, a_{i_2}, \dots, a_{i_k}]$ ($1 \le i_1 < i_2 < \dots < i_k \le n$) such that $\sum_{j=1}^{k-1}(a_{i_j} \operatorname{and} a_{i_{j+1}})$ is maximized. You only need to output this maximum value.

Here, $\operatorname{and}$ denotes the bitwise AND operation.

A subsequence is defined as a sequence obtained by deleting zero or more elements from the original sequence while maintaining the relative order of the remaining elements.

Input

The first line contains a positive integer $n$. The next line contains $n$ integers $a_1 \sim a_n$.

Output

Output a single integer representing the maximum value of $\sum_{j=1}^{k-1}(a_{i_j} \operatorname{and} a_{i_{j+1}})$.

Examples

Input 1

5
1 2 3 1 3

Output 1

5

Note 1

One optimal solution is to choose the subsequence $[a_2, a_3, a_5]$.

Input 2

2
1000000000000 987654321234

Output 2

965637836800

Examples 3, 4

See the provided files.

Constraints

All data satisfy: $1 \le n \le 10^{6}$, $0 \le a_i \le 10^{12}$.

  • Subtask 1 (20 points): $n \le 20$.
  • Subtask 2 (25 points): $n \le 5000$.
  • Subtask 3 (20 points): $n \le 10^5, a_i < 512$.
  • Subtask 4 (15 points): $n \le 2 \times 10^5$, each $a_i$ is generated independently and uniformly at random in $[0, 10^{12}]$.
  • Subtask 5 (20 points): No additional constraints.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.