Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ds_list = []
    for k in range(20):
        ds = [-1] * N
        ds_list.append(ds)
        half = 2 ** k
        divider = half * 2
        last = -1
        for i in range(N):
            if half <= A[i] % divider:
                ds[i] = last = i
            else:
                ds[i] = last


    cn = 0
    for r in range(N - 1, -1, -1):
        if r == 0:
            cn += 1
            break

        l = 0
        for k in range(20):
            p = ds_list[k][r]
            if p <= 0:
                continue
            else:
                l = max(l, ds_list[k][p - 1] + 1)
        cn += r - l + 1


    print(cn)


if __name__ == '__main__':
    main()



Fixed submission:
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ds_list = []
    for k in range(20):
        ds = [-1] * N
        ds_list.append(ds)
        half = 2 ** k
        divider = half * 2
        last = -1
        for i in range(N):
            if half <= A[i] % divider:
                ds[i] = last = i
            else:
                ds[i] = last


    cn = 0
    for r in range(N - 1, -1, -1):
        if r == 0:
            cn += 1
            break

        lp = -1
        for k in range(20):
            p = ds_list[k][r]
            if p <= 0:
                continue
            else:
                lp = max(lp, ds_list[k][p - 1])
        cn += r - lp


    print(cn)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ds_list = []
    for k in range(20):
        ds = [-1] * N
        ds_list.append(ds)
        half = 2 ** k
        divider = half * 2
        d = -1
        for i in range(N):
            if half <= A[i] % divider:
                ds[i] = d = 0
            elif 0 <= d:
                d += 1
                ds[i] = d

    cn = 0
    for r in range(N - 1, -1, -1):
        if r == 0:
            cn += 1
            break

        l = 0
        for k in range(20):
            d = ds_list[k][r]
            if d == -1:
                continue
            if d == 0:
                if ds_list[k][r - 1] == -1:
                    continue
                l = max(l, r - ds_list[k][r - 1])
            else:
                if d == r or ds_list[k][r - d - 1] == -1:
                    continue
                l = max(l, r - d - ds_list[k][r - d - 1])
        cn += r - l + 1



    print(cn)


if __name__ == '__main__':
    main()



Fixed submission:
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ds_list = []
    for k in range(20):
        ds = [-1] * N
        ds_list.append(ds)
        half = 2 ** k
        divider = half * 2
        last = -1
        for i in range(N):
            if half <= A[i] % divider:
                ds[i] = last = i
            else:
                ds[i] = last


    cn = 0
    for r in range(N - 1, -1, -1):
        if r == 0:
            cn += 1
            break

        lp = -1
        for k in range(20):
            p = ds_list[k][r]
            if p <= 0:
                continue
            else:
                lp = max(lp, ds_list[k][p - 1])
        cn += r - lp


    print(cn)


if __name__ == '__main__':
    main()