 # https://www.codechef.com/JAN19B/problems/HP18

I was practicing the lucky number game problem but whenever I submit my solution it results in Time Limit Exceeded. Please help.

My solution is

``````def main():
T = int(input())
A = []
ans = {}

for j in range(T):
ans.setdefault(j+1,'None')
N = input().split(" ")
a = int(N)
b = int(N)
N = int(N)
A = input().split(" ")
bwins = 0
awins = 0
cmwins = 0
i = len(A)-1
while(i>=0):
if(int(A[i]) % a == 0):
if(int(A[i])%b==0):
cmwins += 1
else:
bwins += 1
A.pop(i)
i = len(A)-1
elif(int(A[i])%b==0):
awins += 1
A.pop(i)
i = len(A)-1
else:
i-=1
if(awins == bwins):
winner = 'BOB'
elif(awins>bwins):
winner = 'ALICE'
else:
winner = 'BOB'
ans[j+1] = winner

for i in range(T):
print(ans[i+1])

if __name__=='__main__':
main()
indent preformatted text by 4 spaces``````

First of all your code is bit inside preformatted text and bit outside, which is unclear, i.e. for checking it, I’ve to first make it’s indentation correct.
Secondly, If this is the order of Code, then the problem is, you have first printed ans in range(T), then called the function, where you will be provided with the value of T, i.e. T gets a garbage value before, which if is large will yield TLE

Sorry,
I have corrected the code.
Answer is printed after the evaluation.