#P7296. Mildred's Cow Alphabet Song

    ID: 20495 Type: Default 1000ms 256MiB

Mildred's Cow Alphabet Song

Mildred's Cow Alphabet Song

Mildred is humming her favorite cow alphabet song in her own cow language, which consists of all 26 letters a to z arranged in a specific order. Although cows may arrange these letters in an order different from the familiar abcdefghijklmnopqrstuvwxyz, for this problem assume the cow alphabet is defined as
( P = \text{'abcdefghijklmnopqrstuvwxyz'} ).

Farmer Nhoj overhears a sequence of letters as Mildred sings, but he may have missed some letters. Given the string ( S ) of letters that he remembers, determine the minimum number of complete renditions of the cow alphabet song that Mildred must have sung.

The approach is to simulate the process: for each character in ( S ), if its position in ( P ) is not greater than the position of the previous character (i.e., if ( i(\text{cur}) \leq i(\text{prev}) )), then a new rendition must have started. Finally, output the count of renditions.

inputFormat

A single line containing a non-empty string ( S ) of lowercase letters.
(1 \leq |S| \leq 10^5).

outputFormat

Output a single integer representing the minimum number of complete renditions of the cow alphabet song Mildred must have sung so that Farmer Nhoj could have heard the given sequence.

sample

abcdefghijklmnopqrstuvwxyz
1