As editorial says the dp depends last 22 states hence the period is at max 2^22 states. Start simulating the game till you find a state which already has occured. Now you have a cycle which you can use to skip repetative states.
hey there, have this one worked for you? i tried it out for my theessayservice assignment but seems like there's an error or probably i made one. don't know for sure but still i feel i'm missing something