import java.util.*;
class Solution {
public int[] solution(int N, int[] stages) {
int[] dat = new int[N+2];
for(int tmp : stages) {
dat[tmp]++;
}
int[] answer = new int[N];
List<Node> nodeList = new ArrayList<>();
for (int i=0 ; i<N ; i++) {
nodeList.add(new Node(i+1,dat[i]));
}
for
Collections.sort(nodeList,new Comparator<Node>() {
@Override
public int compare(Node i1, Node i2) {
if(i1.value>i2.value) {
return 1;
}
else if(i1.value<i2.value) {
return -1;
}
return 0;
}
});
for(int i=0 ; i<N ; i++) {
answer[i] = nodeList.get(i).index;
}
return answer;
}
public class Node{
int index;
int value;
int nu;
public Node(int index, int value) {
this.index = index;
this.value = value;
this.nu = nu;
}
}
public static void main(String[] args) {
tester(5,new int[] {2,1,2,6,2,4,3,3},new int[] {3,4,2,1,5});
}
public static void tester(int n, int[] stages, int[] ans) {
Solution s = new Solution();
int[] myret = s.solution(n,stages);
for(int i=0 ; i<ans.length ; i++) {
if(myret[i] != ans[i]) {
System.out.println("NG!!");
return;
}
}
System.out.println("OK");
}
}