using System;using System.Collections.Generic;using System.Linq;
var list = new List<List<int>>
new List<int> {1,1,2,2,2,3,3,3,3},
new List<int> {5,4,5,4,3,5,4,5,4,5,4,3,5,4,5,3,3,3,4,5,4,5,4,5,4,3,3,3,5,4},
new List<int> {2,2,11,11,11,11,6,2,2,6,6,2,2,2,2,6,11,6,11,11,2,11,2,6,6,11,2,11,6,2,6,6,6,6,6,11,2,11,11,6,6,6,11,6,2,6,2,6,6,2,11,2,2,11,11,11,11,2,6,2}
var refList = new List<List<int>>
new List<int>{2,2,3,3,3},
new List<int>{5,4,5,4,3,5,4,5,4,3,5,4,5,3,3,4,5,5,4,4,3,3,5,4},
new List<int> {2,11,11,11,11,6,2,6,6,2,2,6,11,6,11,11,2,11,6,11,2,11,6,6,6,6,6,2,11,11,6,6,6,11,6,2,6,6,11,2,11,11,11,11,2,6}
for(int i = 0; i < list.Count; i++)
R(list[i]).SequenceEqual(refList[i]).Dump();
List<int>R(List<int>l,int n=1){l=l.Where(w=>w>1).ToList();for(int i=0,t=0;i<l.Count;i++){if(l[i]==n&&++t==n){l[i]=0;t=0;}}return !l.Any()||n>l.Max()?l:R(l,++n);}