import java.util.*;
class Solution {
static class Stage {
int number;
double rate;
Stage(int number, double rate) {
this.number = number;
this.rate = rate;
}
}
public int[] solution(int N, int[] stages) {
int[] stageUserNumber = new int[N+1];
for (int i = 0; i <stages.length ; i++) {
if(stages[i] == N+1) {
continue;
}
stageUserNumber[stages[i]]++;
}
int total = stages.length;
List<Stage> stagesInfo = new ArrayList<>();
for (int i = 1; i <stageUserNumber.length ; i++) {
int temp = stageUserNumber[i];
if(temp == 0) {
stagesInfo.add(new Stage(i, 0));
continue;
}
stagesInfo.add(new Stage(i, (double) temp/total));
total -= temp;
}
Collections.sort(stagesInfo, (o1, o2) -> Double.compare(o2.rate,o1.rate));
return stagesInfo.stream().mapToInt(s -> s.number).toArray();
}
}