Line them up
Source: Ukrainian Mathematical Olympiad 2021. Day 2, Problem 9.7
December 21, 2023
combinatoricsInversion
Problem Statement
The All-Ukrainian Mathematical Olympiad was attended by children from regions of Ukraine, children from each region. At the opening ceremony, they stood in one row on the stage, but not all children from the same region stood consecutively. Two neighboring children from different regions can be swapped in second. (You can only swap one pair of children per second).For which shortest time is it always possible to make sure that the children are lined up by the regions? The regions can go in any order.Proposed by Anton Trygub