IBMOA #24
Find Minimum Operations
Estimated MediumJudge-ready
Given a non-empty string containing only a, b and c, you may insert characters at any position. Find the minimum number of insertions needed to turn it into a concatenation of one or more abc strings.
Input
One line containing the string, 1≤length≤100000.
Output
Output one integer, the answer.
Example 1
Input:
b
Output:
2
Example 2
Input:
aaa
Output:
6
Example 3
Input:
abcabc
Output:
0
Example notes
The examples give 2, 6 and 0 respectively.
Editorial
Loading solution…