/// 4:34 ujutru, ne znam sta sam ovde uopste radio
#include <bits/stdc++.h>
using namespace std;

string n;
int charsUsed[10];
int prevCharN2, prevCharN1, currCharN;
char prevChar2, prevChar1, currChar;
int changes;

int main()
{
    cin >> n;
    currChar = n[0];
    charsUsed[n[0]-48] = 1;
    currCharN = 1;
    for (int i = 1; i < n.size(); ++i)
    {
        if (n[i] != currChar || i == n.size()-1)
        {
            ++charsUsed[n[i]-48];
            if (n[i] != currChar && i == n.size()-1 && charsUsed[n[i]-48] > 1)
            {
                ++changes;
                continue;
            }
            if (charsUsed[prevChar1-48] > 1)
            {
                if (charsUsed[currChar-48] > 1)
                {
                    charsUsed[currChar-48]--;
                    charsUsed[prevChar1-48]--;
                    changes+=currCharN+prevCharN1;
                    currChar = n[i];
                    currCharN++;
                    prevChar1 = prevChar2;
                    prevCharN1 += prevCharN2;
                    prevChar2 = 0;
                    prevCharN2 = 0;
                    continue;
                }
                else
                {
                    charsUsed[prevChar1-48]--;
                    changes+=prevCharN1;
                    prevChar1 = currChar;
                    prevCharN1 += currCharN;
                    currChar = n[i];
                    currCharN++;
                    continue;
                }
            }
            else
            {
                if (charsUsed[currChar-48] > 1)
                {
                    charsUsed[currChar-48]--;
                    changes+=currCharN;
                    currChar = n[i];
                    currCharN++;
                    continue;
                }
            }

            prevChar2 = prevChar1;
            prevCharN2 = prevCharN1;
            prevChar1 = currChar;
            prevCharN1 = currCharN;
            currCharN = 1;
            currChar = n[i];
        }
        else
        {
            ++currCharN;
        }
    }
    printf("%d\n", changes);
	return 0;
}