#include <bits/stdc++.h>
#define mci map<char, int>

using namespace std;

int main() {
	string input; cin >> input;
	int i, len = input.size();
	mci lexic;
	int l = 0, d = len - 1;
	bool counting = true;

	if (len < 3)
		cout << 1; 
	else {
		bool ab_indicator = true;
		vector<int> indexes;
		for (i = 0; i < len; i++) {
			if (!(l > d) && counting && input[l] == input[len - l - 1]) {
				l++;
				d--;
			}
			else {
				if (i <= d) {
					lexic[input[i]]++;
					counting = false;
				}
			}
			if (input[i] != 'a') {
				if (input[i] != 'b')
					ab_indicator = false;
				else
					indexes.push_back(i);
			}
		}
		if (ab_indicator == true) {
			if (indexes.size() == 1) {
				cout << abs(indexes[0] - len / 2) + 1;
			}
			else {
				int mid = len / 2;
				if (len % 2 == 0) {
					if (indexes[0] < mid && indexes[1] < mid) {
						mid--;
						cout << abs(abs(indexes[0] - mid) + abs(indexes[1] - mid)) + 2;
					}
					else if (indexes[0] >= mid && indexes[1] >= mid)
						cout << abs(abs(indexes[0] - mid) + abs(indexes[1] - mid)) + 2;
					else 
						cout << abs(abs(indexes[0] - mid) - abs(indexes[1] + 1 - mid));
				}
				else {
					if (indexes[0] == mid || indexes[1] == mid)
						cout << abs(abs(indexes[0] - mid) - abs(indexes[1] - mid));
					else {
						if (indexes[0] < mid && indexes[1] < mid)
							cout << abs(indexes[0] - mid) + abs(indexes[1] - mid) + 1;
						else if (indexes[0] > mid && indexes[1] > mid)
							cout << abs(indexes[0] - mid) + abs(indexes[1] - mid) + 1;
						else
							cout << abs(abs(indexes[0] - mid) - abs(indexes[1] - mid)) + 1;
					}
				}
			}
		}
		else {
			if (l > d)
				cout << 1;
			else {
				mci::iterator itr;
				char uneven = ' ';
				mci required;
				for (itr = lexic.begin(); itr != lexic.end(); itr++) {
					if (itr->second % 2 == 1) 
						uneven = itr->first;
					required[itr->first] = itr->second / 2;
				}
				if (len % 2 == 0) {
					while (required[input[l]] > 1) {
						l++;
						required[input[l - 1]]--;
					}
					while (required[input[d]] > 1) {
						d--;
						required[input[d + 1]]--;
					}
					cout << d - l;
				}
				else {
					required[uneven]++;
					while (required[input[l]] > 1) {
						l++;
						required[input[l - 1]]--;
					}
					while (required[input[d]] > 1) {
						d--;
						required[input[d + 1]]--;
					}
					cout << d - l;
				}
			}
		}
	}
	return EXIT_SUCCESS;
}