跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2845. Letter

    ID: 2851 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>动态规划基础难度共享题库Codeforces英文题面题目来源题面语言

Letter

题目描述

C. Letter
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
Input
PRuvetSTAaYA
Output
5
Input
OYPROSTIYAOPECHATALSYAPRIVETSTASYA
Output
0
Input
helloworld
Output
0

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 2516 题。保留原作者与原赛事署名。