import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int list[] = new int[N]; boolean flag[] = new boolean[N]; HashMap> pathMap = new HashMap<>(); Comparator comp = new Comparator() { @Override public int compare(Integer o1, Integer o2) { return o2.compareTo(o1); } }; TreeSet checkList = new TreeSet(comp); for(int i=0; i array = pathMap.get(a); if( array == null) { array = new ArrayList<>(); array.add(i); pathMap.put(a, array); } else { array.add(i); pathMap.put(a, array); } checkList.add(a); } scan.close(); for(int t : checkList) { //System.out.println("t : " + t); ArrayList array = pathMap.get(t); if(array == null) continue; if(array.size() == 1) { int index=array.get(0); if(flag[index]==false) { list[index] = t; flag[index] = true; } }else if(array.size() >= 2) { int from = array.get(0); int to = array.get(array.size()-1); for(int i=from; i<=to; i++) { if(flag[i]) { break; } else { list[i] = t; flag[i] = true; } } } } for(int i=0; i