Getting RE for 8 9 and 10th test cases

Que- Optimal Game Strategy II (dp)
my code - https://ide.codingblocks.com/s/237303

how to optimized this?

@Akdas yourcode with this logic is causing integer overflow for bigger cases it only passes test case with small value of n.

what is the expected complexity for this problem?

i guess it can be solved in N^2.

I’ve solved in N^2. also used long long.but not getting AC.

pls help it’s been two days.

@Akdas look at this code it passes all test case https://ide.codingblocks.com/s/238808

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.