Middle European Mathematical Olympiad 2022 Problem T-3
Let be a positive integer. There are purple and white cows queuing in a line in some order. Tim wishes to sort the cows by colour, such that all purple cows are at the front of the line. At each step, he is only allowed to swap two adjacent groups of equally many consecutive cows. What is the minimal number of steps Tim needs to be able to fulfill his wish, regardless of the initial alignment of the cows?
Example. For instance, Tim can perform the following three swaps: