Codeforces Round 442 (Div. 2)
B
Nikita and string
Codeforces
1500
原题
← AC →
翻译中…

One day Nikita found the string containing letters "a" and "b" only.

翻译中…

Nikita thinks that string is beautiful if it can be cut into $3$ strings (possibly empty) without changing the order of the letters, where the $1$-st and the $3$-rd one contain only letters "a" and the $2$-nd contains only letters "b".

翻译中…

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

翻译中…

Input

翻译中…

The first line contains a non-empty string of length not greater than $5 000$ containing only lowercase English letters "a" and "b".

翻译中…

Output

翻译中…

Print a single integer — the maximum possible size of beautiful string Nikita can get.

翻译中…

Note

翻译中…

It the first sample the string is already beautiful.

翻译中…

In the second sample he needs to delete one of "b" to make it beautiful.

翻译中…

样例

Input #1
abba
Output #1
4
InputCopy OutputCopy
Input #2
bab
Output #2
2
InputCopy OutputCopy
题目信息
题号
877B
时间限制
2 s
内存限制
256 MB
标签
暴力
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。