Hint: Use A/mid instead of mid*mid


#1

Update your condition like this to avoid integer overflow.