May God bless you..!!

I am stucked in one question of March long contest


and i found that it is much similar in approach as this question
http://www.codechef.com/problems/ABCSTR.
I read the editorial also of the ABCSTR and i followed it , but still i got the tle :frowning: :frowning: … plzz help me to solve the second question (ABCSTR) …plzzzzz!!! …
Here is the link of editorial of ABCSTR question…
http://discuss.codechef.com/questions/40359/abcstr-editorial