When bad thoughts are planted in you, then cry to God:
“Lord, my Maker and Creator. You see that my soul is in agony from bad thoughts. Have mercy on me.”
Teach yourself to root out thoughts immediately.
But when you forget and don’t root them out immediately, then offer repentance.
Work on this, so that you get a habit.
St. Silouan