I am unable to get what is wrong in my code or logic for this question. my approach is that for the given ‘b’ in the sequence I am calculating the number of ‘a’ before that and once I am done with that I use the sum of AP formula for each ‘b’ in the sequence.any help will be appreciated.

here is my solution link: https://www.codechef.com/viewsolution/14572124