#include <bits/stdc++.h>
using namespace std;
void READ(vector<long long> &v, long long n) {
  long long a;
  for (long long i = 0; i < n; i = i + 1) {
    cin >> a;
    v.push_back(a);
  }
}
void PRINT(vector<long long> &v, long long a = 0) {
  for (long long i = a; i < v.size(); i = i + 1) {
    cout << v[i] << " ";
  }
  cout << "\n";
}
double logy(long long n, long long b) {
  if (b == 0) {
    return (-1);
  }
  if (n == 1) {
    return (0);
  }
  return ((double)log10(n) / log10(b));
}
long long power(long long k, long long n, long long m = 1000000007) {
  long long res = 1;
  while (n) {
    if (n % 2 != 0) {
      res = (res * k) % m;
    }
    k = (k * k) % m;
    n = n / 2;
  }
  return (res);
}
double power(double k, long long n) {
  double res = 1;
  while (n) {
    if (n % 2 != 0) {
      res = (res * k);
    }
    k = (k * k);
    n = n / 2;
  }
  return (res);
}
double distance(pair<long long, long long> a, pair<long long, long long> b) {
  return ((double)(sqrt((a.first - b.first) * (a.first - b.first) +
                        (a.second - b.second) * (a.second - b.second))));
}
const long long dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const long long dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vector<pair<long long, long long> > dr;
void call() {
  dr.push_back(make_pair(1, 0));
  dr.push_back(make_pair(-1, 0));
  dr.push_back(make_pair(0, 1));
  dr.push_back(make_pair(0, -1));
}
long long n, m, k, h;
bool ok = false;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout.unsetf(std::ios::floatfield);
  std::cout.precision((long long)10);
  long long a, b, c, d, i, j, t, x, y, z;
  long long p, q, r, u, w;
  char ch, chr;
  string str, st, str1, str2, str3, str4;
  cin >> str;
  n = (long long)(str).size();
  a = count((str).begin(), (str).end(), 'a');
  b = count((str).begin(), (str).end(), 'b');
  if (a == n || b == n) {
    cout << n;
    exit(0);
  }
  vector<long long> v(n, 0), v1(n, 0);
  a = 0;
  b = 0;
  for (i = 0; i < n; i++) {
    if (str[i] == 'a') {
      a++;
      v[i] = a;
      v1[i] = b;
      continue;
    }
    j = i;
    while (j < n && str[j] == str[i]) {
      b++;
      v[j] = a;
      v1[j] = b;
      j++;
    }
    i = j - 1;
  }
  x = -1e18;
  for (i = 0; i < n; i++) {
    a = 0;
    b = 0;
    if (i) {
      a = v[i - 1];
      b = v1[i - 1];
    }
    for (j = n - 1; j >= i; j--) {
      c = v[n - 1] - v[j];
      y = v1[j] - b;
      x = max(a + c + y, x);
    }
  }
  cout << x;
}
