#include <iostream>

using namespace std;

int main()
{
    string T;
    cin >> T;
    int n1 = 0, n2 = 0;
    char a, b;
    int bra = 0, brb = 0;
    bool postoji = false;
    for(int i = 0; i < T.size(); i++) {
        if(bra == 0) {
            a = T[i];
            bra++;
        }else if(T[i] == a) {
            bra++;
        }else if(brb == 0) {
            b = T[i];
            brb++;
        }else if(T[i] == b) {
            brb++;
        }
    }
    if(brb > bra) {
        char pom = b;
        b = a;
        a = pom;
    }
    for(int i = 0; i < T.size(); i++) {
        if(postoji && T[i] == b) {
            n2 = i;
        }else if(T[i] == b) {
            n1 = i;
            postoji = true;
        }
    }
    if(n2-n1 >= T.size()/2){
        int pom = n1;
        n1 = T.size() - n2 - 1;
        n2 = T.size() - pom - 1;
    }
    int rez = (T.size()-n2)-n1;
    if(rez > 0) {
        cout << rez;
    }else {
        cout << -rez;
    }
}