Did you not receive hints over here?

Please read the problems with crossposting.

Break the problem down. Go through the logic of each loop and think about what will happen.