Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
#各bit 累積和テーブル作成
bit =[[0 for i in range(20)] for _ in range(N+1)]
for j in range(N):
    for i in range(20):
        bit[j+1][i] = (L[j] >> i) & 1
#accumulate
for j in range(1,len(L)):
    for i in range(20):
        bit[j+1][i] += bit[j][i]
#作成終了

#1がダブって立ってたらアウト
def check(start,x):
    #bit20桁チェック
    for i in range(20):
        if bit[x][i] - bit[start][i] >= 2:
            return False
    return True

#bisect( [x,y) 半開区間で探索)
def bisect(start,x,y):
    if y - x == 1: return x
    mid = (x + y) // 2
    if check(start,mid) == False:
        return bisect(start,x,mid)
    else:
        return bisect(start,mid,y)

cnt = 0
#今見てるとこが右からn番目でここより右にある物の中からいい感じ(check()の境界)のところを二分で探す
for n in range(N):
    #OKな個数を足し込む
    cnt += bisect(n, n, N+1) - n
print(cnt)



Fixed submission:
N = int(input())
L = list(map(int,input().split()))
cand = []
bit =[[0 for i in range(20)] for _ in range(N)]
for j in range(len(L)):
    for i in range(20):
        bit[j][i] = (L[j] >> i) & 1
for j in range(1,len(L)):
    for i in range(20):
        bit[j][i] += bit[j-1][i]
bit = [[0 for i in range(20)]] + bit

#bisect( [x,y) )

def check(start,x):
    for i in range(20):
        if bit[x][i] - bit[start][i] >= 2:
            return False
    return True


def bisect(start,x,y):
    if y - x == 1: return x
    mid = (x + y) // 2
    if check(start,mid) == False:
        return bisect(start,x,mid)
    else:
        return bisect(start,mid,y)

cnt = 0
for n in range(N):
    cnt += bisect(n, n, N+1) - n
 #   print(bisect(n,n,N+1),n)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
cand = []
bit =[[0 for i in range(20)] for _ in range(N)]
for j in range(len(L)):
    for i in range(20):
        bit[j][i] = (L[j] >> i) & 1
for j in range(1,len(L)):
    for i in range(20):
        bit[j][i] += bit[j-1][i]
bit = [[0 for i in range(20)]] + bit

#bisect( [x,y) )

def check(start,x):
    for i in range(20):
        if bit[x][i] - bit[start][i] >= 2:
            return False
    return True


def bisect(start,x,y):
    if y - x == 1: return x
    mid = (x + y) // 2
    if check(start,mid) == False:
        return bisect(start,x,mid)
    else:
        return bisect(start,mid,y)

cnt = 0
for n in range(N):
    cnt += bisect(n, n, N+1) - n
 #   print(bisect(n,n,N+1),n)
print(cnt)



Fixed submission:
N = int(input())
L = list(map(int,input().split()))
cand = []
bit =[[0 for i in range(20)] for _ in range(N)]
for j in range(len(L)):
    for i in range(20):
        bit[j][i] = (L[j] >> i) & 1
for j in range(1,len(L)):
    for i in range(20):
        bit[j][i] += bit[j-1][i]
bit = [[0 for i in range(20)]] + bit

#bisect( [x,y) )

def check(start,x):
    for i in range(20):
        if bit[x][i] - bit[start][i] >= 2:
            return False
    return True


def bisect(start,x,y):
    if y - x == 1: return x
    mid = (x + y) // 2
    if check(start,mid) == False:
        return bisect(start,x,mid)
    else:
        return bisect(start,mid,y)

cnt = 0
for n in range(N):
    cnt += bisect(n, n, N+1) - n
 #   print(bisect(n,n,N+1),n)
print(cnt)