Where have I made mistake?

I am trying to solve this problem. I am checking from a given state, which subsets we can go to and finding sprague-grundy function. When I am printing the functions, I am getting wrong answer. It is correct for first sample test, but for the second one, it is incorrect.

My solution

p.s. I changed the last few lines in solve function (for variable ans), but I think last one wasn’t incorrect as well

Never mind. I got it. The function checking for sorting was checking in reverse order. So reverse-sorted arrays were considered sorted.

//