P6861 [RC-03] Hard Problem

Description

Find two integers $a, b$ $(1 \le a, b \le n)$ such that $(a\ \mathrm{or}\ b) + (a\ \mathrm{xor}\ b)$ is maximized. You only need to output this maximum value.

Input Format

A positive integer $n$.

Output Format

A positive integer, which is the answer.

Explanation/Hint

Sample explanation: $(5\ \mathrm{or}\ 2) + (5\ \mathrm{xor}\ 2) = 14$. For $80\%$ of the testdata, $n \le 1000$. For $100\%$ of the testdata, $2 \le n \le 10^{18}$. Translated by ChatGPT 5