Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):

    BM = [[] for _ in range(20)]
    for j, a in enumerate(A):
        n = a
        for i in range(20, -1, -1):
            f = 2**i
            if n >= f:
                n -= f
                BM[i].append(j)

    error_print('-----')

    ans = N
    for i in range(0, N):
        min_r = sys.maxsize
        for bm in BM:
            ri = bisect.bisect_left(bm, i)
            if len(bm) == 0 or len(bm) == ri or len(bm) == ri + 1:
                r = N - 1
            else:
                r = bm[ri + 1] - 1
            min_r = min_r if min_r < r else r
        ans += min_r - i
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import time
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    S = 0
    X = 0
    r = 0
    for l in range(N):
        while r != N and S + A[r] == X ^ A[r]:
            S += A[r]
            X ^= A[r]
            r += 1
        ans += r - l
        S -= A[l]
        X ^= A[l]

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):

    BM = [[] for _ in range(20)]
    for j, a in enumerate(A):
        n = a
        for i in range(20, -1, -1):
            f = 2**i
            if n >= f:
                n -= f
                BM[i].append(j)

    error_print('-----')

    ans = N
    for i in range(0, N):
        min_r = sys.maxsize
        for bm in BM:
            ri = bisect.bisect_left(bm, i)
            if len(bm) == 0 or len(bm) == ri or len(bm) == ri + 1:
                r = N - 1
            else:
                r = bm[ri + 1] - 1
            min_r = min_r if min_r < r else r
        ans += min_r - i
    return ans


def main():
    N = read_int()
    A = read_int_n()
    N = int(2 * 1e+5)
    A = [random.randint(0, 2**20 - 1) for _ in range(N)]
    print(slv(N, A))


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import time
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    S = 0
    X = 0
    r = 0
    for l in range(N):
        while r != N and S + A[r] == X ^ A[r]:
            S += A[r]
            X ^= A[r]
            r += 1
        ans += r - l
        S -= A[l]
        X ^= A[l]

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):

    BM = [[] for _ in range(20)]
    for j, a in enumerate(A):
        n = a
        for i in range(20, -1, -1):
            f = 2**i
            if n >= f:
                n -= f
                BM[i].append(j)

    error_print('-----')

    ans = N
    for i in range(0, N):
        min_r = sys.maxsize
        for bm in BM:
            c = 0
            r = sys.maxsize
            for b in bm:
                if b >= i:
                    c += 1
                if c > 1:
                    r = b - 1
                    break
            else:
                r = N - 1
            min_r = min_r if min_r < r else r
        ans += min_r - i
    return ans


def main():
    N = read_int()
    A = read_int_n()
    # N = 2 * 100000
    # A = [0] * N
    print(slv(N, A))


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import time
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    S = 0
    X = 0
    r = 0
    for l in range(N):
        while r != N and S + A[r] == X ^ A[r]:
            S += A[r]
            X ^= A[r]
            r += 1
        ans += r - l
        S -= A[l]
        X ^= A[l]

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    def bit(n):
        b = [0] * 20

        for i in range(20, -1, -1):
            f = 2**i
            if n >= f:
                n -= f
                b[i] = 1

        return b

    # B = []
    BM = [[] for _ in range(20)]
    for j, a in enumerate(A):
        for i, b in enumerate(bit(a)):
            if b == 1:
                BM[i].append(j)

    error_print('-----')

    ans = N
    for i in range(0, N):
        min_r = sys.maxsize
        for bm in BM:
            c = 0
            r = sys.maxsize
            for b in bm:
                if b >= i:
                    c += 1
                if c > 1:
                    r = b - 1
                    break
            else:
                r = N - 1
            min_r = min_r if min_r < r else r
        ans += min_r - i
    return ans


def main():
    N = read_int()
    A = read_int_n()
    # N = 2 * 100000
    # A = [0] * N
    print(slv(N, A))


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import time
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    S = 0
    X = 0
    r = 0
    for l in range(N):
        while r != N and S + A[r] == X ^ A[r]:
            S += A[r]
            X ^= A[r]
            r += 1
        ans += r - l
        S -= A[l]
        X ^= A[l]

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    def bit(n):
        b = [0] * 21

        for i in range(20, -1, -1):
            f = 2**i
            if n >= f:
                n -= f
                b[i] = 1

        return b

    B = []
    for a in A:
        B.append(bit(a))

    # for b in B:
    #     print(b)
    # print('--------')

    C = [[0] * 21]
    for i in range(0, N):
        C.append([c + b for c, b in zip(B[i], C[i])])

    BM = [[] for _ in range(21)]
    for j, bs in enumerate(B):
        for i, b in enumerate(bs):
            if b == 1:
                BM[i].append(j)

    ans = N
    for i in range(0, N):
        min_r = sys.maxsize
        for bm in BM:
            c = 0
            r = sys.maxsize
            for b in bm:
                if b >= i:
                    c += 1
                if c > 1:
                    r = b - 1
                    break
            else:
                r = N - 1
            min_r = min(min_r, r)
        ans += min_r - i if min_r > i else 0
    return ans


def main():
    N = read_int()
    A = read_int_n()
    # N = 2 * 100000
    # A = [0] * N
    print(slv(N, A))


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import time
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    S = 0
    X = 0
    r = 0
    for l in range(N):
        while r != N and S + A[r] == X ^ A[r]:
            S += A[r]
            X ^= A[r]
            r += 1
        ans += r - l
        S -= A[l]
        X ^= A[l]

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    def bit(n):
        b = []
        i = 1
        while i < n:
            i *= 2

        while n:
            if n >= i:
                n -= i
                b.append(i)

            i //= 2
            if i == 0:
                i = 1
        return b

    B = []
    for a in A:
        B.append(bit(a))

    # print('---')
    ans = N
    for i in range(N):
        # print(i)
        S = set(B[i])
        s = len(B[i])
        for j in range(i + 1, N):
            S |= set(B[j])
            s += len(B[j])
            if len(S) != s:
                break
            else:
                ans += 1
        # ans += (j - i) + 1

        # print(B)
    return ans


def main():
    N = read_int()
    A = read_int_n()
    # N = 2 * 100000
    # A = [0] * N
    print(slv(N, A))


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import time
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    S = 0
    X = 0
    r = 0
    for l in range(N):
        while r != N and S + A[r] == X ^ A[r]:
            S += A[r]
            X ^= A[r]
            r += 1
        ans += r - l
        S -= A[l]
        X ^= A[l]

    return ans


def main():
    N = read_int()
    A = read_int_n()

    print(slv(N, A))


if __name__ == '__main__':
    main()