Help with "Arpa chooses brother free subset"

Problem link: https://www.hackerearth.com/challenge/competitive/october-easy-18/algorithm/brofree-34df073d/

My code: https://pastebin.com/pgjP15cE

My logic is explained in detail through comments in my code. I’m new to DP, so any kind of help would be appreciated :slight_smile:

//