#include <bits/stdc++.h>
using namespace std;
string s;
int cnt;
string check(int l, int r) {
  string b;
  for (int i = l; i <= r; ++i) b += s[i];
  return b;
}
int main() {
  string s;
  int ans[11000][4];
  cin >> s;
  int sz = s.size();
  for (int i = 0; i < sz; i++) {
    if (s[i] == 'a') {
      ans[i + 1][3] = ans[i][3] + 1;
      ans[i + 1][1] = max(ans[i][1], ans[i][2]) + 1;
      ans[i + 1][2] = ans[i][2];
    } else if (s[i] == 'b') {
      ans[i + 1][1] = ans[i][1];
      ans[i + 1][2] = max(ans[i][3], ans[i][2]) + 1;
      ans[i + 1][3] = ans[i][3];
    }
  }
  int d = max(ans[sz][2], ans[sz][2]);
  d = max(ans[sz][1], d);
  cout << d;
  return 0;
}
