测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A8497. Letter

编程题 普及/提高-

题目描述

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.

输入格式

The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed $10^{5}$ .

输出格式

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

输入输出样例

输入 #1
PRuvetSTAaYA
输出 #1
5
输入 #2
OYPROSTIYAOPECHATALSYAPRIVETSTASYA
输出 #2
0
输入 #3
helloworld
输出 #3
0
上一题 去做题 下一题