TLE with HELP MARTHA problem of Code Ensemble

Try reading this-
https://www.geeksforgeeks.org/python-input-methods-competitive-programming/
Also format your code.