Problem:
Score : 900 points

Problem Statement

Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive).
How many possible candidates of the value of Nukes's integer there are?

Constraints

1 ≤ A ≤ B < 2^{60}

A and B are integers.

Input

The input is given from Standard Input in the following format:

A
B

Output

Print the number of possible candidates of the value of Nukes's integer.

Sample Input 1

7
9

Sample Output 1

4

In this case, A=7 and B=9. There are four integers that can be represented as the bitwise OR of a non-empty subset of {7, 8, 9}: 7, 8, 9 and 15.

Sample Input 2

65
98

Sample Output 2

63

Sample Input 3

271828182845904523
314159265358979323

Sample Output 3

68833183630578410

Solution in Python (3.4.3) (judge verdict: Wrong Answer)

A = int(input())
B = int(input())

#A = int("111",2)
#B = int("1110",2)

binA = bin(A)[2:]
binB = bin(B)[2:]

#print("A: {0}\nB: {1}".format(A, B))
if A == B:
    print(1)

elif len(binB) - len(binA) > 1:
    maxnum = int("1" * len(binB), 2)
    print(maxnum - A + 1)

elif len(binB) - len(binA) == 1:
    res = 2 * (int("1" * len(binA), 2) - A + 1)
    #print("res(temp): {}".format(res))
    for i in range(1, len(binB)):
        if binB[i] == "0":
            continue
        else:
            res += 2 ** (len(binB) - i)
            break
    else:
        res += 1
    print(res)

else:
    same = ""
    for i in range(len(binA)):
        if binA[i] == binB[i]:
            same += binA[i]
        else:
            break
    same_num = len(same)
    #print("same_num", same_num)

    state = same + "0" * (len(binA) - same_num)
    #print("state", state)
    res = int(state, 2) - A
    #print("res(temp): {}".format(res))
    for i in range(len(binB) - same_num):
        #print("nowi: ", i)
        #print("B_i", binB[i + same_num])
        if binB[i + same_num] == "0":
            continue
        else:
            res += 2 ** (len(binB) - same_num  - i )
            break
    else:
        res += 1
    print(res)