Hi! I was solving problem C from Atcoder educational DP contest and it seems to me that this problem can be solved using bitmasks. If you're smarter than me and can solve this using bitmasks — share the solution in the comments(or if it is impossible to solve it in that way , explain please why it is impossible).
Link to the problem : https://atcoder.jp/contests/dp/tasks/dp_c