This page is still under construction.

Parts of this page are still being built. What you see may change.

Picking Out Numbers

Time limit2sMemory limit512 MB

Summary
Choose between 1 and k distinct integers from [l, r] minimizing the XOR of the chosen set, and output that minimum XOR.
Level

Hard8 of 10

Topics
Bit manipulation, Math, Greedy, Dynamic programming
Solved
No attempts yet

Problem

Seonggwan wants to build a set SS that satisfies all of the following conditions.

  • Every element of SS is a natural number, and no two elements are equal.
  • Every element of SS is at least ll and at most rr.
  • The number of elements of SS is at least 11 and at most kk.

Choose SS so that the bitwise XOR of all its elements is as small as possible, and find that XOR value.

Input

The first line contains the natural numbers ll, rr, kk, separated by spaces. (1≤l≤r≤10121 \le l \le r \le 10^{12}, 1≤k≤min⁡(106,r−l+1)1 \le k \le \min(10^6, r-l+1))

Output

Print the smallest XOR value on the first line. Several sets can reach that smallest value, but the output is that single value.

Examples3

  1. Example 1

    Input
    8 15 3
    
    Expected output
    1
    
  2. Example 2

    Input
    8 30 7
    
    Expected output
    0
    
  3. Example 3

    Input
    5 6 2
    
    Expected output
    3