Problem p03104 (python)

Fixed submission:
###############################################################################

from bisect import bisect_left as binl
from math import log10, log2, ceil

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


###############################################################################


def main():
    a, b = intin()
    bits = {}

    if not b:
        print(0)
        return 0

    for i in range(int(log2(b)) + 1):
        msbs_a = a >> i
        msbs_b = b >> i
        lsbs_a = a % (2**i)
        lsbs_b = b % (2**i)
        bit_a = msbs_a & 1
        bit_b = msbs_b & 1
        lsbs_count_a = (2**i) - lsbs_a
        lsbs_count_b = lsbs_b + 1

        if bit_a == 0 and bit_b == 0:
            bits[i] = 0
            continue

        if bit_a == 1 and bit_b == 1:
            bits[i] = 1 if (lsbs_count_a + lsbs_count_b) % 2 else 0
            continue

        if bit_a:
            bits[i] = 1 if lsbs_count_a % 2 else 0
            continue

        if bit_b:
            bits[i] = 1 if lsbs_count_b % 2 else 0
            continue

    if a % 2:
        odd_count = ceil((b - a + 1) / 2)
    else:
        odd_count = (b - a + 1) // 2
    bits[0] = odd_count % 2

    ans = 0
    for i in bits:
        if bits[i]:
            ans += 2 ** i
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
###############################################################################

from bisect import bisect_left as binl
from math import log10, log2

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


###############################################################################


def main():
    a, b = intin()
    bits = {}

    if not b:
        print(0)
        return 0

    for i in range(int(log2(b)) + 1):
        msbs_a = a >> i
        msbs_b = b >> i
        lsbs_a = a % (2**i)
        lsbs_b = b % (2**i)
        bit_a = msbs_a & 1
        bit_b = msbs_b & 1
        lsbs_count_a = (2**i) - lsbs_a
        lsbs_count_b = lsbs_b + 1

        if bit_a == 0 and bit_b == 0:
            bits[i] = 0
            continue

        if bit_a == 1 and bit_b == 1:
            bits[i] = 1 if (lsbs_count_a + lsbs_count_b) % 2 else 0
            continue

        if bit_a:
            bits[i] = 1 if lsbs_count_a % 2 else 0
            continue

        if bit_b:
            bits[i] = 1 if lsbs_count_b % 2 else 0
            continue

    if a % 2:
        if (b - a + 1) % 2:
            odd_count = (b - a + 1) // 2 + 1
        else:
            odd_count = (b - a + 1) // 2
    else:
        odd_count = (b - a + 1) // 2
    bits[0] = odd_count % 2

    ans = 0
    for i in bits:
        if bits[i]:
            ans += 2 ** i
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
###############################################################################

from bisect import bisect_left as binl
from math import log10, log2

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def ceil(x):
    if x // 2 == x:
        return x
    return int(x) + 1


###############################################################################


def main():
    a, b = intin()
    bits = {}

    for i in range(int(log2(b)) + 1):
        msbs_a = a >> i
        msbs_b = b >> i
        lsbs_a = a % (2**i)
        lsbs_b = b % (2**i)
        bit_a = msbs_a & 1
        bit_b = msbs_b & 1
        lsbs_count_a = (2**i) - lsbs_a
        lsbs_count_b = lsbs_b + 1

        if bit_a == 0 and bit_b == 0:
            bits[i] = 0
            continue

        if bit_a == 1 and bit_b == 1:
            bits[i] = 1 if (lsbs_count_a + lsbs_count_b) % 2 else 0
            continue

        if bit_a:
            bits[i] = 1 if lsbs_count_a % 2 else 0
            continue

        if bit_b:
            bits[i] = 1 if lsbs_count_b % 2 else 0
            continue

    if a % 2:
        odd_count = ceil((b - a + 1) / 2)
    else:
        odd_count = (b - a + 1) // 2
    bits[0] = odd_count % 2

    ans = 0
    for i in bits:
        if bits[i]:
            ans += 2 ** i
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
###############################################################################

from bisect import bisect_left as binl
from math import log10, log2, ceil

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


###############################################################################


def main():
    a, b = intin()
    bits = {}

    for i in range(int(log2(b)) + 1):
        msbs_a = a >> i
        msbs_b = b >> i
        lsbs_a = a % (2**i)
        lsbs_b = b % (2**i)
        bit_a = msbs_a & 1
        bit_b = msbs_b & 1
        lsbs_count_a = (2**i) - lsbs_a
        lsbs_count_b = lsbs_b + 1

        if bit_a == 0 and bit_b == 0:
            bits[i] = 0
            continue

        if bit_a == 1 and bit_b == 1:
            bits[i] = 1 if (lsbs_count_a + lsbs_count_b) % 2 else 0
            continue

        if bit_a:
            bits[i] = 1 if lsbs_count_a % 2 else 0
            continue

        if bit_b:
            bits[i] = 1 if lsbs_count_b % 2 else 0
            continue

    if a % 2:
        odd_count = ceil((b - a + 1) / 2)
    else:
        odd_count = (b - a + 1) // 2
    bits[0] = odd_count % 2

    ans = 0
    for i in bits:
        if bits[i]:
            ans += 2 ** i
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
###############################################################################

from bisect import bisect_left as binl
from math import log10, log2, ceil

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


###############################################################################


def main():
    a, b = intin()
    bits = {}

    for i in range(int(log2(b)) + 1):
        msbs_a = a >> i
        msbs_b = b >> i
        lsbs_a = a % (2**i)
        lsbs_b = b % (2**i)
        bit_a = msbs_a & 1
        bit_b = msbs_b & 1
        lsbs_count_a = (2**i) - lsbs_a
        lsbs_count_b = lsbs_b + 1

        if bit_a == 0 and bit_b == 0:
            bits[i] = 0
            continue

        if bit_a == 1 and bit_b == 1:
            bits[i] = 1 if (lsbs_count_a + lsbs_count_b) % 2 else 0
            continue

        if bit_a:
            bits[i] = 1 if lsbs_count_a % 2 else 0
            continue

        if bit_b:
            bits[i] = 1 if lsbs_count_b % 2 else 0
            continue

    if a % 2:
        odd_count = ceil((b - a + 1) / 2)
    else:
        odd_count = (b - a + 1) // 2
    bits[0] = odd_count % 2

    ans = 0
    for i in bits:
        if bits[i]:
            ans += 2 ** i
    print(ans)


if __name__ == '__main__':
    main()