What is wrong with this code?

@sharad1103 hey sharad I think bhaiya already covered a efficient approach. so can you please tell me did your code giving right output for the sample one if yes then use long long int for pass the evaluation.