My test cases are failed.But for custom input it is working fine

take into consideration the long constraints which are failing your code
refer to this here