# How can I make this code more efficient?(SPAMCLAS)

import sys

def query(input, n, weight, bias):
ans = input

for layern in range(n):
ans = ans * weight[layern] + bias[layern]
return ans

[n, minX, maxX] = read().split(' ')

n = int(n)
minX = int(minX)
maxX = int(maxX)
weights = []
biases = []
for j in range(n):
weights.append(int(a[0]))
biases.append(int(a[1]))

spammers = 0
nonspammers = 0
for i in range(minX, maxX+1):

y = query(i, n, weights, biases)
if y % 2 == 0:

nonspammers += 1
else:

spammers+=1

return[nonspammers, spammers]
for i in range(T):

This is for the Problem SPAMCLAS.(Python 3.5)
I am getting an overtime error.
How can I optimize this code?

According to the constraints given, 1 <= minX, maxX <= 1e9 and 1 <= N <= 1e5.

Your solution has complexity O(T.(maxX - minX).N) whose value is around 1e(1 + 9 + 5) or 1e15; much much more than 1e8.

Hence there is absolutely no chance for this algorithm to complete within the time limitâ€¦

Check the editorial here if you face problem.

Thank you, I am not able to understand the editorial solution.
If possible, please can you explain me.