Help with a problem

I am not able to understand this problem particularly why the answer for second test case is 21.
I wrote a bruteforce and dp solution but both are giving 66 as output.
https://ideone.com/Ps8ZAX //bruteforce
https://ideone.com/0Ar8em //dp