Sample Explanation
In Sample Case #1, there are 5 tiles that have a different color between the current and the desired states of the floor. Since each operation can change at most 2 tiles, at least 3 operations, costing 3 coins, are needed. One way to do it with exactly 3 coins is:
- Swap the leftmost two tiles in the top row.
- Swap the rightmost two tiles in the top row.
- Flip the bottom right corner tile.
The picture below illustrates the states the floor goes through. The highlighted tile or tiles in each state are the ones being changed by the operation.

In Sample Case #2, there are 6 tiles that need changing. However, since only swaps can change two tiles at a time, solving it with 3 operations would require all of them to be swaps. There is no way to involve all 6 tiles in a single swap each, so we need at least 4 operations. One way to use exactly 4 operations is:
- Swap the topmost two tiles in the middle column.
- Flip the top right corner tile.
- Swap the bottommost two tiles in the rightmost column.
- Flip the middle tile of the leftmost column.
The picture below illustrates the states the floor goes through.

Sample Test Set 2 fits the limits of Test Set 2. It will not be run against your submitted solutions.
In the Sample Case for Test Set 2, flips are so expensive that we want to avoid them at all costs. We need at least one since our desired floor state has more magenta tiles than the current one, and swaps do not change that amount. We can do it optimally with just one flip like this:
- Swap the leftmost two tiles.
- Flip the rightmost tile.
- Swap the second and third tiles from the left.
- Swap the third and fourth tiles from the left.
The picture below illustrates all the states the floor goes through.

Limits
Test Set 1 (11 Pts, Visible Verdict)
Test Set 2 (23 Pts, Hidden Verdict)