Condition mismatched

in this particular problem, I want to know whether the students with purchased tokens are considered or not, and also my code is failing at some test cases. Help me figure it out

i have attatched my code in replies

look at the constraints, take long