PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000193. Mặt nạ bit tối ưu (Bit Mask)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mặt nạ bit tối ưu (Bit Mask)

Bit Mask

Source: UVa

Version: Phuoc Hung OJ (single-case adaptation where applicable)

Problem Statement

Given three unsigned 32-bit integers N,L,UN,L,U with L≤UL\le U, choose M∈[L,U]M\in[L,U] that maximizes the bitwise OR N OR MN\,\mathrm{OR}\,M. Among masks attaining the maximum OR, choose the smallest MM.

Input

The single line contains N,L,UN,L,U in this order. This is a single-instance adaptation; do not read until EOF.

Output

Print the smallest optimal MM.

Subtasks

  • Subtask 1 (20 points): 0≤N≤2550\le N\le 255; 0≤L≤U≤2550\le L\le U\le 255 (unsigned 32-bit).
  • Subtask 2 (30 points): 0≤N≤655350\le N\le 65535; 0≤L≤U≤655350\le L\le U\le 65535 (unsigned 32-bit).
  • Subtask 3 (50 points): 0≤N≤42949672950\le N\le 4294967295; 0≤L≤U≤42949672950\le L\le U\le 4294967295 (unsigned 32-bit).

Examples

Example 1

Input

100 50 60

Output

59

Explanation

The mask 59 yields 100 OR 59 = 127 and is the smallest mask within the interval achieving this maximum.

Example 2

Input

100 50 50

Output

50

Explanation

The range contains only 50, so the answer must be 50.