#P11798. Find an Integer with Given XOR

    ID: 13895 Type: Default 1000ms 256MiB

Find an Integer with Given XOR

Find an Integer with Given XOR

Given four non-negative integers (l, r, k, x). Find an integer (n) such that (l \le n \le r) and (\bigoplus\limits_{i=k}^{n} i = x), where (\bigoplus\limits_{i=k}^{n} i) denotes the bitwise XOR of all integers from (k) to (n). If there are multiple solutions, output any one. Otherwise, output -1.

inputFormat

A single line containing four non-negative integers (l, r, k, x) separated by spaces.

outputFormat

Output any valid integer (n) that satisfies (l \le n \le r) and (\bigoplus\limits_{i=k}^{n} i = x). If no such integer exists, output -1.

sample

2 5 2 5
4