This won't be a complete solution, but really what I learnt while I did it.
EDGE CASES ARE IMPORTANT
so i figured out that the number must be even, but kept getting wrong answer for test case 5. That was when I googled and realized that if it is 2, then the divided parts are not even. Silly me.
I know this is useless, but if some one on the same level as me needs it, here you go. Check Edge cases.