Under construction

Still being built. Things may change

MEX vs OR

Time limit2sMemory limit1024 MB

Summary
Given l, r, and x, the task is to compute the mex of the values (i OR x) for every i from l to r inclusive.
Level

Easy2 of 10

Topics
Brute force, Bit manipulation
Solved
No attempts yet

Problem

A sequence aa of non-negative integers is given. The function mex(a)\text{mex}(a) is the smallest non-negative integer that is not contained in aa.

Examples of applying mex to a sequence:

  • mex([1,2,3,4,5])=0\text{mex}([1,2,3,4,5])=0
  • mex([0,1,2,3,4])=5\text{mex}([0,1,2,3,4])=5
  • mex([0,1,2,4,5])=3\text{mex}([0,1,2,4,5])=3

For non-negative integers xx and yy, the bitwise OR x ∣ yx\,|\,y is defined by these rules:

  • If at least one of xx and yy has a 1 in the ii-th bit (in binary), then x ∣ yx\,|\,y has a 1 in the ii-th bit.
  • If both xx and yy have a 0 in the ii-th bit (in binary), then x ∣ yx\,|\,y has a 0 in the ii-th bit.

Examples of computing the bitwise OR of two integers:

  • 2 ∣ 4=0102 ∣ 1002=1102=62\,|\,4=010_2\,|\,100_2=110_2=6
  • 3 ∣ 6=0112 ∣ 1102=1112=73\,|\,6=011_2\,|\,110_2=111_2=7
  • 5 ∣ 4=1012 ∣ 1002=1012=55\,|\,4=101_2\,|\,100_2=101_2=5

Non-negative integers ll, rr, and xx are given, with l≤rl \le r. You must find the value of the following expression.

mex([(l ∣ x),((l+1) ∣ x),⋯ ,((r−1) ∣ x),(r ∣ x)])\text{mex}([(l\,|\,x),((l+1)\,|\,x),\cdots,((r-1)\,|\,x),(r\,|\,x)])

Input

Three integers ll, rr, and xx are given on one line, separated by spaces. (0≤l≤r≤1 0000 \le l \le r \le 1\,000, 0≤x≤1 0000 \le x \le 1\,000)

Output

Print the answer to the problem on one line.

Hint

In most languages, the bitwise OR x ∣ yx\,|\,y of non-negative integers xx and yy can be computed with the operator |, as in (x|y).

Examples3

  1. Example 1

    Input
    0 4 0
    
    Expected output
    5
    
  2. Example 2

    Input
    0 4 1
    
    Expected output
    0
    
  3. Example 3

    Input
    1 4 0
    
    Expected output
    0