import heapq
def solution(A):
circle = []
for i, a in enumerate(A):
circle += [(i-a, False), (i+a, True)] # start, end
heapq.heapify(circle)
active_circle = 0
intersection = 0
while circle :
point, isEnd = heapq.heappop(circle)
if not isEnd:
intersection +=active_circle
active_circle +=1
else :
active_circle -= 1
if intersection > 10E6 :
return -1
return intersection