BTAR - Editorial

If you group them as (s_a1 U s_a2) and {a,b} instead, you’d still get the same cost. We can argue about pairing 1s and 3s in a similar way. And once that is done we do whatever we can with the remaining numbers. Also, any of the subsets must not contain in it a proper subset having modulo 4 equal to zero, because in that case we can take them separately and get a better cost. That’s why we can leave out ‘good’ numbers as mentioned by likecs

why is this not working

https://www.codechef.com/viewsolution/16667987