// 2023 IUSB Programming Competition // Round 1 Problem 6 // Alphabetical Order // Solution by Liguo Yu import java.util.Scanner; public class round1_p6 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String user_input = input.nextLine(); char[] letters = new char[10]; for(int i=0; i<10; i++) { letters[i] =user_input.charAt(i); } int longest = longestOrder(letters, 10); System.out.println(10-longest); } static int longestOrder(char array[], int n) { int list[] = new int[n]; // store the longest increasing oder starting from evey index for (int i = 0; i < n; i++) { list[i] = 1; // initialize to 1 } for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { // update longest increasing order from position j by comparing its value with // values ahead of it and their longest increasing order if (array[i] > array[j] && list[i] < list[j] + 1) { list[i] = list[j] + 1; } } } int max = 1; // find the the longest longest increasing oder starting from all indecies for (int i = 0; i < n; i++) { if (max < list[i]) max = list[i]; } return max; } }