cs academy round 60 problem D

first part we can solve using meet in the middle . how to solve the second part of this question (If the solution is not unique, you want to minimize the absolute difference between the number of cards in the groups) Problem