Need Help!

need help in this question https://www.spoj.com/problems/ADAAPHID/

Getting TLE in the 15th test case.

my code is -> https://ide.geeksforgeeks.org/1OA4shNWwe

Thanks -_- !