Why am I getting TLE even when constraints are small.

Problem: Link

Code: Link

I was solving this problem on codeforces. Since constraints were small I decided to go with brute force. But it shows TLE, what I don’t understand is that why is it returning TLE. I can understand MLE, WA, Compilation error. But my code complexity is not that large that n=50 will return TLE. Please do tell me why is this happening

See this accepted solution. Just modified a little bit.