Help with the code logic

3 out of 6 test cases are passing. Can you give me hint where I am lagging behind

can somebody reply ?

Look out for integer overflows.use long long int everywhere

All test cases has passed. Thanks a lot.