You have a special machine called a LexStringWriter. It has a display that initially shows the String s, and the cursor's initial position is on the first letter of the string. The machine has three buttons: left, right, and enter. When you press left, the cursor moves one position to the left if possible. When you press right, it moves one position to the right if possible. The width of the display is exactly equal to the length of s, and the cursor can never leave the display. When you press enter, the letter shown at the current cursor position will be printed on paper, and that position on the display will be replaced with a space (' ').
Return the minimal number of button presses necessary to print all of the letters in s in alphabetically order. All occurrences of all letters in s must be printed, so if 'a' appears 3 times, for example, 'a' must be printed 3 times.