monocarp arrange n colored marble row the color ith marble a_i Monocarp like order thing want rearrange marble way marble color form contiguo segment segment color in word Monocarp want rearrange marble color j leftmost marble color j lth row rightmost marble color position r row marble l r color jTo achieve goal Monocarp follow operation number time choose neighbouring marble swap themyou calculate minimum number operation Monocarp perform rearrange marble note order segment marble have equal color matter require color marble color form exactly contiguous segment