Yes, the code is not properly indented. Although, I went to your profile, and grabbed your code [ I hope you don’t mind, just to help you debug it]. Everything is fine, your code doesn’t need any optimization. The only problem is you are declaring variables of long long but while taking inputs and printing them you are taking them as int(%d) and not long long int(%lld).
Here is your code with TLE: TLE
Here is your AC code by making appropriate changes %d->%lld :AC