defsleep_sort(a):ifnot a:return
clock =[[]for _ inrange(max(a)+1)]for value in a:
clock[value].append(value)
i =0for tick inrange(len(clock)):for waking in clock[tick]:
a[i]= waking
i +=1
functionsleepSort(a){if(a.length ===0)return;const top =Math.max(...a);const clock =Array.from({ length: top +1},()=>[]);for(const value of a) clock[value].push(value);let at =0;for(let tick =0; tick <= top; tick++){for(const waking of clock[tick]) a[at++]= waking;}}
voidsleep_sort(int a[],int n){int top =0;for(int i =0; i < n; i++){if(a[i]> top) top = a[i];}int* first =malloc(sizeof(int)*(top +1));int* next =malloc(sizeof(int)*(n +1));for(int tick =0; tick <= top; tick++) first[tick]=-1;for(int i =0; i < n; i++){
next[i]= first[a[i]];
first[a[i]]= i;}int at =0;for(int tick =0; tick <= top; tick++){for(int s = first[tick]; s >=0; s = next[s]) a[at++]= tick;}free(first);free(next);}
voidsleep_sort(std::vector<int>& a){if(a.empty())return;int top =*std::max_element(a.begin(), a.end());
std::vector<std::vector<int>>clock(top +1);for(int value : a) clock[value].push_back(value);
size_t at =0;for(int tick =0; tick <= top; tick++){for(int waking : clock[tick]) a[at++]= waking;}}
staticvoidSleepSort(int[] a){if(a.Length==0)return;int top = a.Max();var clock =newList<int>[top +1];for(int tick =0; tick <= top; tick++) clock[tick]=newList<int>();foreach(int value in a) clock[value].Add(value);int at =0;for(int tick =0; tick <= top; tick++){foreach(int waking in clock[tick]) a[at++]= waking;}}
staticvoidsleepSort(int[] a){if(a.length ==0)return;int top =Arrays.stream(a).max().getAsInt();List<List<Integer>> clock =newArrayList<>();for(int tick =0; tick <= top; tick++) clock.add(newArrayList<>());for(int value : a) clock.get(value).add(value);int at =0;for(int tick =0; tick <= top; tick++){for(int waking : clock.get(tick)) a[at++]= waking;}}