list_c = sorted(listc)
for i in range(len(lista[1])):
red = green = black = 0
a0i = lista[0][i]
first = bisect_left(list_c[1], a0i)
beyond = bisect_leftbisect_right(list_c[1], a0i, first)
if first < beyond:
a2i = lista[2][i]
a3i = lista[3][i]
c2i = list_c[2][i]
a8i_intended = lista[8][i] == 'intended value'
for j in range(first, beyond):
c1j = list_c[1][j]
if (c1j <= a3i or c1j >= a2i):
if lista[7][i] >= c1j and lista[6][i] <= c1j and a8i_intended:
red += c2i
if a3i >= c1j and lista[7][i] <= c1j and not a8i_intended:
red += c2i
if lista[6][i] >= c1j and a2i <= c1j and a8i_intended:
green += c2i
if lista[7][i] >= c1j and a2i <= c1j and not a8i_intended:
green += c2i
if a2i >= c1j and lista[3][i - 1] <= c1j:
black += c2i
toc = timeit.default_timer()
if i % 100 == 0:
print('processing algorithm: {}'.format(toc - tic))
print('we are at row {}'.format(i))
output[0].append(lista[1][i])
output[1].append(red)
output[2].append(green)
output[3].append(black)