#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int calcSwapCount(char bc, char ec, char *str, int n)
{
int count = 0;
int begin = 0, end = n - 1;
while (begin < end)
{
if (str[begin] == bc)
begin++;
else if (str[end] == ec)
end--;
else if (str[begin] == ec && str[end] == bc)
{
count += end - begin;
begin++;
end--;
}
}
return count;
}
int main()
{
char str[51];
scanf("%s", &str);
int n = strlen(str);
printf("%d\n", min(calcSwapCount('C', 'D', str, n), calcSwapCount('D', 'C', str, n)));
return 0;
}