I don’t know why i am getting persistent TLE. Here is the link to my solution-http://ideone.com/27IIh7