Google Kickstart Round G - Combination Lock {wlog(w)} Solution giving TLE

Can Somebody plz help me figure out why am i still getting TLE.
Time Complexity of my solution is w*log(w) ; 1 <= w <= 10**5
Link to My Solution ; https://ideone.com/RbfXkV

I even used sys.stdin.readline() to take input But that also did’nt Help :frowning: :pensive:.

Maybe use PyPy 2 instead of Python3. It’d get AC. My W^2 during the contest didn’t work in Python3 but passed first 2 subtasks in PyPy2.

Thanks for the reply @akshitm16 .
I tried that, But PyPy2 submission gives WA .
It Maybe because of Older version of PyPy2 .

Yup, the syntax might be little different in 2. Only thing you can do is print variables at each step and see where things go wrong and then check for the corresponding changes in 2.
Say print(3/2) will give different output in both versions.

Thanks @akshitm16 .
At First it was giving WA .
But then when i changed (2*v - n)/2 to (v - n/2) it got AC .
May be some sort of overflow in python.

I always faced this problem in every kickstart contest. Python is not suitable for kickstarts.