I am trying to implement a procedure that involves coupled element counts and sorting. However, I got stucked. Is there someone that could help me to solve this task?