import java.util.Scanner; import java.util.ArrayList; import java.util.InputMismatchException; public class JengaSort { static Scanner scanner = new Scanner(System.in); public static void main(String[] args){ int N = Input(1 , 100000); ArrayList High = new ArrayList<>(); for(int i = 0 ; i < N ; i++){ High.add(Input(1,N)); } int Result = Processing(N,High); System.out.println(Result); } public static int Input(int Min , int Max){ int Number = scanner.nextInt(); try{ if(Number < Min || Number > Max){ System.out.println(Min + "以上" + Max + "以下で入力してください"); System.exit(0); } }catch(InputMismatchException e){ System.out.println("数字を入力してください"); System.exit(0); }catch(Exception E){ System.out.println("予期せぬエラーです"); System.exit(0); } return Number; } public static int Processing(int N , ArrayList High){ int Count = 0; for(int i = 0 ; i < N ; i++){ for(int j = i + 1 ; j < High.size() ; j++){ if(High.get(i) > High.get(j)){ Count++; High.remove(j); j--; } } } return Count; } }