Preparando MOJI

Letter

1000ms 262144K

Description:

Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.

Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.

To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.

Input:

The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.

Output:

Print a single number — the least number of actions needed to make the message fancy.

Sample Input:

PRuvetSTAaYA

Sample Output:

5

Sample Input:

OYPROSTIYAOPECHATALSYAPRIVETSTASYA

Sample Output:

0

Sample Input:

helloworld

Sample Output:

0

Informação

Codeforces

Provedor Codeforces

Código CF180C

Tags

dp

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 08:36:43

Relacionados

Nada ainda