WA in SPOJ problem ADAAPHID

I’m solving this spoj problem using treaps and keep getting WA. Can anyone tell me what am I doing wrong ? My Code