Alice has a string $s$. She really likes the letter "a". She calls a string good if strictly more than half of the characters in that string are "a"s. For example "aaabb", "axaa" are good strings, and "baca", "awwwa", "" (empty string) are not.

Alice can erase some characters from her string $s$. She would like to know what is the longest string remaining after erasing some characters (possibly zero) to get a good string. It is guaranteed that the string has at least one "a" in it, so the answer always exists.


-----Input-----

The first line contains a string $s$ ($1 \leq |s| \leq 50$) consisting of lowercase English letters. It is guaranteed that there is at least one "a" in $s$.


-----Output-----

Print a single integer, the length of the longest good string that Alice can get after erasing some characters from $s$.


-----Examples-----
Input
xaxxxxa

Output
3

Input
aaabaa

Output
6



-----Note-----

In the first example, it's enough to erase any four of the "x"s. The answer is $3$ since that is the maximum number of characters that can remain.

In the second example, we don't need to erase any characters.

Difficulty: EASY

Solutions:
n = input()
a = 0
o = 0
for i in n:
	if i == 'a':
		a += 1
	else:
		o += 1
if a > int(len(n) / 2):
	print(len(n))
else:
	print(len(n) - (o - a + 1))


s = input()
count_a = s.count('a')
l = len(s)
diff = l - 2 * count_a + 1
if diff <= 0:
	diff = 0
print(l - diff)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return ll[mid]
		elif ll[mid] < val:
			ans = ll[mid]
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v
s = str(input())
c1 = 0
for i in range(len(s)):
	if s[i:i + 1] == 'a':
		c1 += 1
val = len(s) - c1
if c1 > val:
	print(len(s))
else:
	print(len(s) - (val - c1 + 1))


a = list(input())
x = a.count('a')
print(min(x * 2 - 1, len(a)))


x = input()
length_string = len(x)
list_alpha = list(x)
count_a = 0
for ele in list_alpha:
	if ele == 'a':
		count_a += 1
while count_a <= length_string - count_a:
	length_string -= 1
print(length_string)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
py2 = round(0.5)
if py2:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._buffer = BytesIO()
		self._fd = file.fileno()
		self._writable = 'x' in file.mode or 'r' not in file.mode
		if self._writable:
			self.write = self._buffer.write if py2 else lambda s: self._buffer.write(s.encode())

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self._buffer.tell()
			(self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr))
		self.newlines -= 1
		s = self._buffer.readline()
		return s if py2 else s.decode()

	def flush(self):
		if self._writable:
			os.write(self._fd, self._buffer.getvalue())
			(self._buffer.truncate(0), self._buffer.seek(0))
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
reads = lambda : [int(x) for x in input().split()]
read = lambda : int(input())
s = input()
a = s.count('a')
print(min(len(s), a * 2 - 1))


s = input()
n = len(s)
count = 0
for i in range(n):
	if s[i] == 'a':
		count += 1
other = n - count
if count > other:
	print(n)
elif count == other:
	print(n - 1)
else:
	print(2 * count - 1)


n = list(input())
length = len(n)
i = 0
count_a = n.count('a')
if count_a > 0.5 * length:
	print(len(n))
else:
	except_a = len(n) - count_a
	while not count_a > except_a:
		except_a -= 1
	print(count_a + except_a)


s = sorted(list(input()))
m = s.count('a')
for i in range(len(s)):
	g = len(s) / 2
	if m > g:
		print(len(s))
		quit()
	else:
		del s[-1]


s = input()
c = s.count('a')
print(min(len(s), 2 * c - 1))


s = sorted(list(input()))
ans = len(s) if s.count('a') > len(s) - s.count('a') else 2 * s.count('a') - 1
print(ans)


line = input()
countA = 0
count = 0
for i in line:
	if i == 'a':
		countA += 1
	else:
		count += 1
if countA > count:
	print(len(line))
else:
	while True:
		count -= 1
		if countA > count:
			print(countA + count)
			break


x = input()
c = x.count('a')
print(len(x) if c > len(x) // 2 else 2 * c - 1)


import math
s = input()
a = s.count('a')
if a > int(math.ceil(len(s) / 2)):
	print(len(s))
else:
	a *= 2
	print(a - 1)


def f(s):
	count = 0
	for c in s:
		if c == 'a':
			count += 1
	if count * 2 > len(s):
		return len(s)
	other = len(s) - count
	fill = count - 1
	return count + fill
assert f('aaxxxxx') == 3
assert f('xaxxxxa') == 3
assert f('aaabaa') == 6
assert f('xa') == 1
assert f('yyyyyya') == 1
s = input()
ans = f(s)
print(ans)


s = input()
nonA = len(s) - s.count('a')
a = s.count('a')
while a <= nonA:
	nonA -= 1
print(a + nonA)


string = input()
count_a = 0
count_ch = 0
for i in string:
	if i == 'a':
		count_a += 1
	else:
		count_ch += 1
if count_a > count_ch:
	print(len(string))
else:
	string_len = count_a + count_a - 1
	print(string_len)


inp = input()
count = 0
res = 0
lens = len(inp)
for i in inp:
	if i == 'a':
		count = count + 1
if lens % 2 == 0:
	if count <= lens / 2:
		res = count * 2 - 1
		print(res)
	else:
		print(lens)
elif count <= lens / 2 + 1:
	res = count * 2 - 1
	print(res)
else:
	print(lens)


n = input()
a = n.count('a')
b = a - 1
if a > len(n) // 2:
	print(len(n))
else:
	print(a + b)


def func(st):
	a = st.count('a')
	l = len(st)
	if a * 2 > l:
		return l
	else:
		return 2 * a - 1
st = input()
print(func(st))


k = input()
f = 0
for i in k:
	if i == 'a':
		f += 1
print(min(2 * f - 1, len(k)))


s = input()
a = len(s)
for i in range(a):
	if s.count('a') <= a // 2:
		if s[i] != 'a':
			a -= 1
print(a)


n = input()
m = len(n)
m = int(m)
o = n.count('a')
o = int(o)
if m % 2 == 0:
	if m / 2 < o:
		print(m)
	else:
		k = 2 * o - 1
		print(k)
elif (m - 1) % 2 == 0:
	if (m - 1) / 2 < o:
		print(m)
	else:
		k = 2 * o - 1
		print(k)


s = input()
a = s.count('a')
b = len(s) - a
if a > b:
	print(len(s))
else:
	x = b - a + 1
	print(len(s) - x)


s = input()
b = s.count('a')
print(max(0, min(len(s), b * 2 - 1)))


word = [char for char in input()]
word_dict = {i: word.count(i) for i in word}
i = 0
if word_dict['a'] / len(word) > 0.5:
	print(len(word))
else:
	while word_dict['a'] / (len(word) - i) <= 0.5:
		i += 1
	print(len(word) - i)


string = input()
l = len(string)
a = string.count('a')
if 2 * a > l:
	print(l)
else:
	b = l - 2 * a + 1
	ans = l - b
	print(ans)


nado = 0
nen = 0
otv = 0
a = input()
for i in a:
	if i == 'a':
		nado += 1
	else:
		nen += 1
print(len(a) - max(0, nen - nado + 1))


s = str(input())
cntA = 0
cntR = 0
for i in s:
	if i == 'a':
		cntA += 1
	else:
		cntR += 1
diff = cntR - (cntA - 1)
if diff < 0:
	diff = 0
print(len(s) - diff)


s = input()
n_a = 0
for c in s:
	if c == 'a':
		n_a += 1
print(min(2 * n_a - 1, len(s)))


inp = input()
na = 0
l = len(inp)
for i in range(l):
	if inp[i] == 'a':
		na = na + 1
if na > l // 2:
	print(l)
else:
	print(na * 2 - 1)


s = str(input())
n = len(s)
cnt = s.count('a')
if cnt > n // 2:
	print(n)
else:
	print(2 * cnt - 1)


w = input()
ca = 0
a = len(w)
for e in w:
	if e == 'a':
		ca += 1
if 2 * ca > a:
	print(a)
else:
	print(2 * ca - 1)


x = input()
y = x.count('a')
z = len(x) - y
i = 0
while z >= y:
	i += 1
	z -= 1
print(len(x) - i)


from collections import Counter
s = input()
num_a = Counter(s)['a']
print(len(s) if num_a > len(s) / 2 else num_a * 2 - 1)


s = input()
l = len(s)
k = l / 2
p = s.count('a')
if p > k:
	print(l)
else:
	print(2 * p - 1)


s = input()
b = s
c = []
d = []
for item in b:
	if item == 'a':
		c.append(item)
	else:
		d.append(item)
if len(c) > len(d):
	print(len(c) + len(d))
else:
	while len(c) <= len(d):
		d.pop()
	print(len(c) + len(d))


s = input()
l = len(s)
a = s.count('a')
while a <= l / 2:
	l = l - 1
print(l)


s = input()
x = len(s)
count = 0
for i in s:
	if i == 'a':
		count += 1
y = x // 2
if count > y:
	print(len(s))
elif count <= y:
	while count <= y:
		y -= 1
	print(count + y)


from collections import Counter
s = list(input().lower())
c = Counter(s)
if 'a' not in s != 0:
	print(0)
else:
	n = c['a']
	if len(s) < 2 * n:
		print(len(s))
	else:
		print(2 * n - 1)


str = input()
len = len(str)
a = 0
for i in range(len):
	if str[i] == 'a':
		a += 1
print(min(2 * a - 1, len))


def good_string():
	s = input().lower()
	len_s = len(s)
	num_of_a = s.count('a')
	result = num_of_a * 2 - 1
	if not s.strip():
		return 0
	elif result < len_s:
		return result
	elif len_s < result:
		return len_s
	elif len_s == result:
		return len_s
print(good_string())


s = input()
ans = min(2 * s.count('a') - 1, len(s))
print(ans)


a = input()
b = len(a)
x = 0
for i in range(0, b):
	if a[i] == 'a':
		x = x + 1
x = x * 2 - 1
if b < x:
	print(b)
else:
	print(x)


import sys
string = input()
length = len(string)
numberAs = string.count('a')
if numberAs > length / 2:
	print(str(length))
else:
	print(str(numberAs * 2 - 1))


s = input()
n = len(s)
a = 0
for i in range(n):
	if s[i] == 'a':
		a += 1
if a > n / 2:
	print(n)
else:
	print(2 * a - 1)


s = input()
len = len(s)
c = s.count('a')
n = len - c
count = 0
if c > len // 2:
	print(len)
else:
	print(2 * c - 1)


s = input()
n = len(s)
cnt = 0
for c in s:
	if c == 'a':
		cnt += 1
k = (n + 2) // 2
if cnt >= k:
	print(n)
else:
	print(cnt + cnt - 1)


s = input()
count = 0
l = len(s)
for i in s:
	if i == 'a':
		count += 1
if count > l / 2:
	print(l)
else:
	print(count * 2 - 1)


n = input()
print(min(n.count('a') * 2 - 1, len(n)))


s = input()
c = s.count('a')
if c > len(s) // 2:
	print(len(s))
else:
	print(2 * c - 1)


s = input()
l = len(s)
l2 = int(len(s) / 2)
g = s.count('a')
if g > l2:
	print(l)
else:
	a = g + g - 1
	print(a)


myString = input()
numberOfAs = myString.count('a')
if len(myString) < 2 * numberOfAs:
	print(len(myString))
else:
	print(2 * numberOfAs - 1)


s = input()
k = s.count('a')
print(min(max(k + k - 1, 0), len(s)))


s = input()
a = 0
for i in range(len(s)):
	if s[i] == 'a':
		a += 1
M = min(2 * a - 1, len(s))
print(M)


s = input()
t = len(s)
count1 = 0
for i in range(t):
	if s[i] == 'a':
		count1 += 1
b = t - count1
c = b - count1 + 1
if count1 > t - count1:
	print(t)
else:
	print(t - c)


L = input()
C = 0
K = 0
for i in range(len(L)):
	if L[i] == 'a':
		C += 1
	else:
		K += 1
if C > K:
	print(len(L))
else:
	print(len(L) - (K - C + 1))


s = input()
s = list(s)
a = 0
b = 0
x = 0
for i in range(len(s)):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
while a <= b:
	del s[0]
	b -= 1
	x += 1
print(len(s))


def bublesort(a):
	n = len(a)
	fl1 = False
	while not fl1:
		fl1 = True
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
				fl1 = False

def isgood(a):
	k = 0
	for x in a:
		if x == 'a':
			k += 1
	return k > len(a) // 2

def dell(a):
	k = 0
	for x in a:
		if x != 'a':
			return a[:k] + a[k + 1:]
		k += 1
a = input()
while not isgood(a):
	a = dell(a)
print(len(a))


g = input()
n = len(g)
x = g.count('a')
print(max(0, min(x * 2 - 1, n)))


k = input()
n = len(k)
a = 0
for i in k:
	if i == 'a':
		a += 1
if a > n // 2:
	print(n)
else:
	print(a * 2 - 1)


x = list(input())
a = []
k = 0
for i in range(len(x)):
	if x[i] == 'a':
		k += 1
if k > len(x) // 2:
	print(len(x))
else:
	print(k * 2 - 1)


x = input()
ar = []
for i in x:
	ar.append(i)
f = ar.count('a')
if f <= len(ar) // 2:
	s = f * 2 - 1
else:
	s = len(ar)
print(s)


n = list(input())
n.sort()
k = n.count('a')
while k <= len(n) // 2:
	del n[len(n) - 1]
print(len(n))


d = input()
a = d.count('a')
o = len(d)
if a > o - a:
	print(o)
else:
	s = o - (o - a - a + 1)
	print(s)


s = str(input())
l = len(s)
k = int(l / 2)
count = 0
sum = 0
for i in range(0, l, 1):
	if s[i] == 'a':
		count += 1
d = 2 * count
sum = min(l, d - 1)
print(sum)


s = input()
ans = 0
for i in s:
	ans += i == 'a'
print(min(len(s), 2 * ans - 1))


s = input()
c1 = 0
for i in s:
	if i == 'a':
		c1 += 1
if c1 > len(s) // 2:
	print(len(s))
else:
	print(2 * c1 - 1)


n = input()
if n.count('a') <= len(n) - n.count('a'):
	x = n.count('a')
	while x <= len(n) - x:
		n = n[1:]
	print(len(n))
else:
	print(len(n))


s = input()
num_of_as = s.count('a')
if num_of_as <= len(s) - num_of_as:
	print(num_of_as * 2 - 1)
else:
	print(len(s))


line = input()
print(min(len(line), 2 * line.count('a') - 1))


inp = input()
c = 0
for i in inp:
	if i == 'a':
		c += 1
print(min(len(inp), c * 2 - 1))


s = input()
l = len(s)
if l <= 1:
	print('1')
else:
	t = s.count('a')
	if t <= l // 2:
		print(t + t - 1)
	else:
		print(l)


def main():
	s = input()
	a = 0
	for i in s:
		if i == 'a':
			a += 1
	l = len(s)
	if a > l // 2:
		print(l)
		return
	for i in s:
		if i != a:
			l -= 1
			if a > l // 2:
				print(l)
				return
main()


s = input()
a = s.count('a')
n_a = len(s) - a
print(len(s) - max(n_a - a + 1, 0))


s = str(input())
s1 = sorted(s)
ac1 = 0
for i in s:
	if i == 'a':
		ac1 += 1
leng = len(s1) / 2
if ac1 > leng:
	print(len(s1))
else:
	while ac1 <= leng:
		s1.pop(-1)
		leng = len(s1) / 2
	print(len(s1))


s = list(input())
a = s.count('a')
x = len(s) - a
if a > x:
	print(len(s))
else:
	print(a * 2 - 1)


n = input()
t = n.count('a')
if t > len(n) // 2:
	print(len(n))
elif t <= len(n) // 2:
	print(2 * t - 1)


s = input()
print(min(len(s), len(s.split('a')) * 2 - 3))


a = input()
if 2 * a.count('a') > len(a):
	print(len(a))
else:
	print(2 * a.count('a') - 1)


str = input()
fl = int(len(str) / 2)
count_of_a = 0
count_of_other = 0
count = 0
for i in str:
	if i == 'a':
		count_of_a = count_of_a + 1
	else:
		count_of_other = count_of_other + 1
if count_of_a > fl:
	print(len(str))
else:
	while count_of_other >= count_of_a:
		count_of_other = count_of_other - 1
		count = count + 1
	print(len(str) - count)


s = input()
a = len(list(filter(lambda x: x == 'a', s)))
k = len(list(filter(lambda x: x != 'a', s)))
while k >= a:
	k -= 1
print(a + k)


import sys
s = str(input())
count_a = 0
count_other = 0
for c in list(s):
	if c == 'a':
		count_a += 1
	else:
		count_other += 1
while count_a <= count_other:
	count_other -= 1
print(count_a + count_other)


t = input()
j = t.count('a')
if j > len(t) - j:
	print(len(t))
else:
	print(2 * j - 1)


s = input()
ans = 0
for i in range(len(s)):
	if s[i] == 'a':
		ans += 1
print(min(ans + ans - 1, len(s)))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
from copy import deepcopy
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
s = data()
a = s.count('a')
answer = 0
n = len(s)
while a <= n // 2:
	n -= 1
out(n)


s = input()
a_count = s.count('a')
non_a_max_count = a_count - 1
total_max_count = a_count + non_a_max_count
if total_max_count > len(s):
	print(len(s))
else:
	print(total_max_count)


n = str(input())
c = n.count('a')
if c * 2 - 1 < len(n):
	print(c * 2 - 1)
else:
	print(len(n))


string = input()
length = len(string)
acount = string.count('a')
if acount > length / 2:
	print(length)
else:
	print(acount + (acount - 1))


s = input()
caunt = s.count('a')
sol = len(s)
while caunt <= sol - caunt:
	sol -= 1
print(sol)


str = input()
global ctr
ctr = 0
for i in range(len(str)):
	if str[i] == 'a':
		ctr += 1
if ctr <= len(str) // 2:
	print(2 * ctr - 1)
else:
	print(len(str))


s = input()
count = 0
for i in range(0, len(s)):
	if s[i] == 'a':
		count = count + 1
rem = len(s) - count
if rem < count:
	print(len(s))
else:
	print(len(s) - (rem - count + 1))


s = input()
if s.count('a') > len(s) / 2:
	print(len(s))
elif s.count('a') % 2 == 0:
	print(s.count('a') * 2 - 1)
else:
	print(s.count('a') * 2 - 1)


import sys
from collections import defaultdict, deque
from math import sqrt

def input():
	return sys.stdin.readline()[:-1]
s = input()
n = len(s)
m = s.count('a')
print(min(n, m * 2 - 1))


s = input()
n = len(s)
m = s.count('a')
if m > n // 2:
	print(n)
else:
	print(m + m - 1)


k = str(input())
a = k.count('a')
jk = len(k)
jx = jk - a
if a > jx:
	print(jk)
else:
	while jx >= a:
		jx -= 1
	print(jx + a)


i = input()
ac = 0
oc = 0
for l in i:
	if l == 'a':
		ac = ac + 1
	else:
		oc = oc + 1
if ac > oc:
	print(len(i))
else:
	print(len(i) - 1 - (oc - ac))


s = input()
length = len(s)
count = 0
for i in range(0, length):
	if s[i] == 'a':
		count = count + 1
g = length - count
if g >= count:
	leng = length - (g - count + 1)
	print(leng)
else:
	print(length)


s = list(input())
l = len(s)
c = s.count('a')
if c > l // 2:
	print(l)
else:
	print(c + (c - 1))


str = input()
l = len(str)
c = 0
for i in str:
	if i == 'a':
		c = c + 1
if c > int(l / 2 + 1):
	print(l)
else:
	print(2 * c - 1)


def dkwpwn(string):
	while string.count('a') <= len(string) / 2:
		for i in string:
			if i != 'a':
				string.remove(i)
				break
	return len(string)
string = list(input())
print(dkwpwn(string))


s = input()
s = list(s)
n = len(s)
k = s.count('a')
p = n - k
if k <= p:
	x = k + k - 1
	print(x)
else:
	print(n)


a = input('')
a_cnt = 0
tot_cnt = 0
for c in a:
	if c == 'a':
		a_cnt += 1
	tot_cnt += 1
temp = a_cnt * 2
if temp > tot_cnt:
	print(tot_cnt)
else:
	print(temp - 1)


s = input()
x = s.count('a')
print(min(len(s), 2 * x - 1))


word = input()
a_count = 0
for letter in word:
	if letter == 'a':
		a_count += 1
not_a = len(word) - a_count
to_remove = not_a - a_count + 1 if not_a >= a_count else 0
print(len(word) - to_remove)


s = input()
n = len(s)
x = s.count('a')
ans = min(n, 2 * x - 1)
print(ans)


q = input()
w = list(q)
e = 0
for i in range(0, len(w)):
	if w[i] == 'a':
		e += 1
if e > len(w) / 2:
	print(len(w))
if e <= len(w) / 2:
	print(2 * e - 1)


s = input()
l = len(s)
c = 0
for i in range(l):
	if s[i] == 'a':
		c += 1
if c > l / 2:
	print(l)
else:
	print(2 * c - 1)


a = input()
c = a.count('a')
if c > len(a) / 2:
	print(len(a))
elif c == len(a) / 2:
	print(len(a) - 1)
else:
	print(2 * c - 1)


arr = input()
a = arr.count('a')
tot = len(arr)
rem = tot - a
while a <= rem:
	rem -= 1
print(a + rem)


a = input()
len = len(a)
ans = 0
for i in range(0, len):
	if a[i] == 'a':
		ans += 1
if ans + ans <= len:
	ans = ans + ans - 1
else:
	ans = len
print(ans)


def split(word):
	return [char for char in word]
string = input()
string = split(string)
a = 0
for i in string:
	if i == 'a':
		a += 1
if a >= len(string) // 2 + 1:
	print(len(string))
else:
	print(a * 2 - 1)


def smaller(x, y):
	if x < y:
		return x
	return y
S = input()
acnt = 0
for i in range(0, len(S)):
	if S[i] == 'a':
		acnt += 1
print(smaller(2 * acnt - 1, len(S)))


str = input()
border = len(str) // 2
a = str.count('a')
if a > border:
	print(len(str))
else:
	print(a * 2 - 1)


s = input()
count = 0
for s1 in s:
	if s1 == 'a':
		count = count + 1
if count > len(s) / 2:
	print(len(s))
else:
	print(count * 2 - 1)


import sys
import math
import bisect

def main():
	a = 0
	b = 0
	for c in input():
		if c == 'a':
			a += 1
		else:
			b += 1
	while a <= b:
		b -= 1
	print(a + b)
main()


import math
s = input()
print(min(len(s), 2 * s.count('a') - 1))


s = input()
count = 0
for i in s:
	if i == 'a':
		count += 1
maxlength = count * 2 - 1
print(min(maxlength, len(s)))


s = input().strip()
counter = {}
for c in s:
	if c not in counter:
		counter[c] = 1
	else:
		counter[c] += 1
length = len(s)
if counter['a'] > length / 2:
	print(length)
else:
	print(counter['a'] * 2 - 1)


import sys
line = sys.stdin.readline().strip()
n = 0
for number in line:
	if number == 'a':
		n += 1
if len(line) < 2 * n:
	print(len(line))
else:
	print(2 * n - 1)


n = input()
l = len(n) // 2
p = n.count('a')
if p > l:
	print(len(n))
else:
	print(2 * p - 1)


def program(n):
	ases = n.count('a')
	length = len(n)
	if ases > round(length / 2):
		return length
	length -= ases
	return length - (length - (ases - 1)) + ases
n = input()
print(program(n))


s = input().lower()
count = 0
for i in range(len(s)):
	if s[i] == 'a':
		count += 1
num = len(s) / 2
if count > num:
	print(len(s))
else:
	print(2 * count - 1)


import math
s = str(input())
sum = 0
for i in range(len(s)):
	if s[i] == 'a':
		sum += 1
sum = sum * 2 - 1
if sum <= len(s):
	print(sum)
else:
	print(len(s))


s = input()
ca = s.count('a')
cv = len(s)
while True:
	if ca >= cv // 2 + 1:
		print(cv)
		exit()
	else:
		cv -= 1
		continue


s = input()
a = s.count('a')
b = len(s)
if a > b / 2:
	print(b)
else:
	print(2 * a - 1)


import math
string = input()
l = len(string)
a = string.count('a')
if a > math.ceil(l / 2):
	print(l)
else:
	print(2 * a - 1)


s = input()
print(len(s) if s.count('a') > int(len(s) / 2) else (s.count('a') - 1) * 2 + 1)


s = input()
n = 0
for ch in s:
	if ch == 'a':
		n += 1
m = len(s) - n
if m < n:
	print(len(s))
else:
	print(n + n - 1)


s = input()
c = s.count('a')
ln = len(s) - c
if c > ln:
	print(len(s))
else:
	print(c + c - 1)


S = input()
A = 0
B = 0
for s in S:
	if s == 'a':
		A += 1
	else:
		B += 1
print(min(A * 2 - 1, A + B))


def count_occurrences(word, sentence):
	return sentence.count(word)
st = input()
na = count_occurrences('a', st)
if 2 * na > len(st):
	print(len(st))
elif len(st) > 2 * na - 1:
	print(2 * na - 1)


s = input()
wyn = 0
for i in s:
	if i == 'a':
		wyn += 1
print(min(len(s), 2 * wyn - 1))


s = input()
st = list(s)
siz = len(st)
lock = 0
cnt = 0
for i in range(siz):
	if st[i] == 'a':
		cnt += 1
val = 0
if cnt > siz / 2:
	print(siz)
else:
	rest = siz - cnt
	while rest >= cnt:
		rest -= 1
		val += 1
	print(siz - val)


x = input()
n = x.count('a')
if len(x) / 2 >= n:
	print(n * 2 - 1)
else:
	print(len(x))


s = input()
a = len([1 for i in s if i == 'a'])
nota = len(s) - a
print(len(s) - (nota - a) - 1 if a < nota else nota + a if a > nota else len(s) - 1)


a_count = 0
length = 0
for i in input():
	if i == 'a':
		a_count += 1
	length += 1
if 2 * a_count > length:
	print(length)
else:
	print(2 * a_count - 1)


from collections import Counter
s = input()
c = Counter(s)
print(min(len(s), 2 * c['a'] - 1))


def fun():
	s = input()
	a_count = s.count('a')
	if a_count > len(s) // 2:
		print(len(s))
	else:
		print(2 * a_count - 1)
fun()


while 1:
	try:
		x = input()
	except:
		break
	a = x.count('a')
	if a * 2 > len(x):
		print(len(x))
	else:
		print(a * 2 - 1)


z = input()
q = len(z)
k = z.count('a')
if k > q // 2:
	print(q)
else:
	print(2 * k - 1)


data = input()
a_count = 0
for i in data:
	if i == 'a':
		a_count += 1
if a_count > len(data) // 2 + 1:
	print(len(data))
elif a_count == 1:
	print(1)
else:
	print(a_count * 2 - 1)


s = input()
ct = 0
for i in s:
	if i == 'a':
		ct += 1
l = len(s)
ans = min(l, 2 * ct - 1)
print(ans)


s = input()
s = str(s)
i = 0
count_of_a = 0
count_of_x = 0
s = list(s)
while i < len(s):
	if s[i] == 'a':
		count_of_a += 1
	else:
		count_of_x += 1
	i += 1
i = 0
if count_of_a > count_of_x:
	print(len(s))
else:
	print(count_of_a + (count_of_a - 1))


def main():
	s = input()
	n = len(s)
	a = s.count('a')
	print(min(a + a - 1, n))
	return 0
main()


n = input()
s = n.count('a')
w = len(n) - s
if s > w:
	print(len(n))
else:
	for i in range(w):
		k = w - 1
		w = k
		if k < s:
			print(k + s)
			break


s = input()
t = s.count('a')
u = len(s) - t
if t > u:
	print(t + u)
else:
	print(2 * t - 1)


s = input()
a_cnt = s.count('a')
print(min(2 * a_cnt - 1, len(s)))


s = input()
count1 = 0
count2 = 0
for i in range(len(s)):
	if s[i] == 'a':
		count1 += 1
	else:
		count2 += 1
if count2 >= count1:
	print(2 * count1 - 1)
else:
	print(count1 + count2)


string_input = input()
count_a = string_input.count('a')
count_not_a = len(string_input) - count_a
if count_a > count_not_a:
	print(len(string_input))
elif count_a == count_not_a:
	print(len(string_input) - 1)
else:
	minus = count_a - 1
	print(count_a + minus)


s = input()
a_count = s.count('a')
print(min(len(s), 2 * a_count - 1))


s = input()
count_a = 0
char_list = []
for item in s:
	char_list.append(item)
	if item == 'a':
		count_a += 1
char_list.sort()
while count_a <= len(char_list) / 2:
	char_list.pop(-1)
print(len(char_list))


string = input()
a_num = string.count('a')
print(len(string) if a_num > (len(string) + 1) // 2 else a_num * 2 - 1)


g = input()
h = len(g)
a = 0
for x in range(h):
	if g[x] == 'a':
		a += 1
if a > h // 2:
	print(h)
else:
	print(2 * a - 1)


y = list(str(input()))
z = 2 * y.count('a') - 1
if z > len(y):
	print(len(y))
else:
	print(z)


a = input()
nado = a.count('a')
print(min(len(a), 2 * nado - 1))


str = input()
count = 0
for i in range(len(str)):
	if str[i] == 'a':
		count += 1
if count > len(str) // 2:
	print(len(str))
else:
	print(2 * count - 1)


s = input()
a = len(s)
good = 0
bad = 0
for char in s:
	if char == 'a':
		good += 1
	else:
		bad += 1
if good > bad:
	print(a)
else:
	while bad >= good:
		a -= 1
		bad -= 1
	print(a)


s = input('')
length = len(s)
quantity = s.count('a')
if quantity > length / 2:
	print(length)
else:
	print(2 * quantity - 1)


z = str(input())
count = 0
counti = 0
status = False
for i in range(len(z)):
	if z[i] == 'a':
		count += 1
	else:
		counti += 1
		status = True
if status:
	if counti >= count:
		print(count + count - 1)
	else:
		print(count + counti)
else:
	print(count)


s = input()
i = 0
j = 0
l = len(s)
for e in s:
	if e == 'a':
		j += 1
if j > l / 2:
	print(l)
else:
	while j <= l / 2:
		l -= 1
	print(l)


s = input()
num_a = s.count('a')
len_s = len(s)
if num_a > len_s / 2:
	print(len_s)
else:
	print(num_a * 2 - 1)


import sys

def solve():
	stri = input()
	count_a = stri.count('a')
	if count_a > len(stri) // 2:
		return len(stri)
	else:
		return 2 * count_a - 1
ans = solve()
print(ans)


from math import ceil as ceil
string = list((char for char in input()))
z = string.count('a')
length = len(string)
minimum = ceil(length / 2)
if z > minimum:
	print(length)
else:
	print(2 * z - 1)


s = input()
a = s.count('a')
if len(s) // 2 < a:
	print(len(s))
else:
	z = len(s)
	while z // 2 >= a:
		z = z - 1
	print(z)


s = input()
good_coff = len(s) // 2 + 1
count = s.count('a')
if count > len(s) // 2 + 1:
	print(len(s))
else:
	print(count * 2 - 1)


k = input()
import math
if math.ceil(len(k) / 2) >= k.count('a'):
	print(2 * k.count('a') - 1)
else:
	print(len(k))


string = str(input())
ac = 0
n = len(string)
for i in range(n):
	if string[i] == 'a':
		ac += 1
while ac <= n / 2:
	n -= 1
print(n)


s = input()
a = len(s)
j = 0
for i in s:
	if i == 'a':
		j += 1
if j < int(a / 2) + 1:
	print(2 * j - 1)
else:
	print(a)


n = input()
a = 0
t = 0
for x in n:
	if x == 'a':
		a += 1
if a > len(n) / 2:
	t = len(n)
else:
	t = a * 2 - 1
print(t)


import sys
str = sys.stdin.readline().rstrip()
count = 0
for char in str:
	if char == 'a':
		count += 1
if count * 2 - 1 >= len(str):
	print(len(str))
else:
	print(count * 2 - 1)


s = input()
if s.count('a') > len(s) / 2:
	print(len(s))
else:
	while s.count('a') <= len(s) / 2:
		x = 0
		while s[x] == 'a':
			x += 1
		s = s[:x] + s[x + 1:]
	print(len(s))


s = sorted(input())
while s.count('a') <= len(s) / 2:
	del s[-1]
print(len(s))


s = input()
a = s.count('a')
other = len(s) - a
if a > other:
	print(len(s))
else:
	print(a * 2 - 1)


s = input()
a_count = s.count('a')
print(len(s) if len(s) // 2 < a_count else 2 * a_count - 1)


s = input()
c = 0
l = len(s)
for i in range(l):
	if s[i] == 'a':
		c += 1
z = min(l, 2 * c - 1)
print(z)


s = input()
ca = s.count('a')
cv = len(s)
if ca >= cv // 2 + 1:
	print(cv)
else:
	print(ca * 2 - 1)


s = input()
c = 0
for i in s:
	if i == 'a':
		c = c + 1
	else:
		c = c - 1
if c > 0:
	print(len(s))
else:
	print(len(s) + c - 1)


string = input('')
counter = 0
for letter in string:
	if letter == 'a':
		counter += 1
if counter > len(string) / 2:
	print(len(string))
else:
	print(counter * 2 - 1)


a = input()
lst = []
count = 0
count1 = 0
count2 = 0
for i in a:
	lst += i
for i in lst:
	if i == 'a':
		count1 += 1
	if i != 'a':
		count2 += 1
if count1 > count2:
	print(len(lst))
else:
	print(2 * count1 - 1)


l = list(input())
cou = l.count('a')
if len(l) // 2 < cou:
	print(len(l))
else:
	print(2 * cou - 1)


import math
import sys
import re

def func(s):
	l = len(s)
	if s.count('a') >= int(l / 2) + 1:
		return l
	while s.count('a') < int(l / 2) + 1:
		l = l - 1
	return l
s = input()
print(func(s))


n = input()
l = list(n)
x = l.count('a')
if x > len(l) // 2:
	print(len(l))
else:
	print(2 * x - 1)


st = input()
cnt = dict()
suma = 0
sum = 0
for i in st:
	if i == 'a':
		suma += 1
	else:
		sum += 1
x = len(st)
while suma <= sum:
	x -= 1
	sum -= 1
print(x)


s = input()
na = 0
na = s.count('a')
if len(s) / 2 < na:
	print(len(s))
else:
	print(na + (na - 1))


s = input()
count_a = s.count('a')
remain_s = s.replace('a', '')
remain_len_s = len(remain_s)
if count_a > remain_len_s:
	print(len(s))
elif count_a <= remain_len_s:
	print(len(s) - (remain_len_s - count_a) - 1)


s = input()
z = s.count('a')
r = len(s) - z
print(z + min(z - 1, r))


s = input()
a = 0
for i in s:
	if i == 'a':
		a += 1
if a > len(s) - a:
	print(len(s))
else:
	x = len(s) - a
	while x >= a:
		x -= 1
	print(x + a)


string = input()
while string.count('a') <= len(string) - string.count('a'):
	new_string = ''
	b = False
	for i in string:
		if i != 'a':
			if b:
				new_string += i
			b = True
		else:
			new_string += i
	string = new_string
print(len(string))


def solve(s):
	num_a = 0
	non_a = 0
	for c in s:
		if c != 'a':
			non_a += 1
		else:
			num_a += 1
	return len(s) if num_a > non_a else len(s) - (abs(num_a - non_a) + 1)
s = input()
print(solve(s))


s = input()
count = s.count('a')
leng = len(s)
new_s = s
if count > leng / 2:
	print(leng)
else:
	i = 0
	while count <= leng / 2:
		if not s[i] is 'a':
			s = s[0:i] + s[i + 1:]
			leng = len(s)
		else:
			i += 1
	print(leng)


s = input()
L = len(s)
A = s.count('a')
nA = L - A
D = nA - A + 1
res = L - D
if A <= nA:
	print(res)
else:
	print(L)


arr = input()
print(min(len(arr), arr.count('a') * 2 - 1))


word = input()
a = word.count('a')
print(min(len(word), 2 * a - 1))


from sys import stdin
from collections import defaultdict as dd
s = stdin.readline().rstrip()
d = dd(int)
for i in s:
	d[i] += 1
print(min(len(s), 2 * d['a'] - 1))


word = list(input())
num_a = 0
num_non_a = 0
for j in word:
	if j == 'a':
		num_a += 1
	else:
		num_non_a += 1
while num_non_a >= num_a:
	num_a = 0
	num_non_a = 0
	for i in word:
		if i != 'a':
			word.remove(i)
			break
	for j in word:
		if j == 'a':
			num_a += 1
		else:
			num_non_a += 1
print(len(word))


s = input()
l = len(s)
count_a = 0
for i in range(l):
	if s[i] == 'a':
		count_a += 1
if count_a > l / 2.0:
	print(l)
elif count_a == 0:
	print(count_a)
else:
	print(2 * count_a - 1)


s = input().strip()
k = 0
d = len(s)
for i in range(d):
	if s[i] == 'a':
		k += 1
if k > d // 2 or k > d // 2 + 1:
	print(d)
else:
	print(2 * k - 1)


s = input()
a = s.count('a')
if a > len(s) // 2 + 1:
	print(len(s))
else:
	required_len = 2 * a - 1
	print(required_len)


s = input()
inp = []
for item in s:
	inp += item
num_a = 0
inp.sort()
for item in inp:
	if item != 'a':
		break
	else:
		num_a += 1
while num_a <= 0.5 * len(inp):
	del inp[-1]
print(len(inp))


string = input()
length = len(string)
a = string.count('a')
if a <= length // 2:
	length = a * 2 - 1
print(length)


s = input()
a = 0
b = 0
for char in s:
	if char == 'a':
		a += 1
	else:
		b += 1
print(a + (b if b < a else a - 1))


n = input()
i = 0
for e in n:
	if e == 'a':
		i += 1
if len(n) / 2 > i and len(n) - i != 2:
	print(2 * i - 1)
elif len(n) - i == 2:
	print(i)
elif len(n) / 2 == i:
	print(len(n) - 1)
else:
	print(len(n))


x = input()
ac = x.count('a')
oc = len(x) - ac
if ac > oc:
	print(ac + oc)
elif ac == oc:
	oc -= 1
	print(ac + oc)
else:
	k = oc - ac
	print(oc + ac - k - 1)


string = str(input())
a = string.count('a')
if a > len(string) / 2:
	print(len(string))
else:
	print(2 * a - 1)


x = str(input())
c = 0
for i in range(len(x)):
	if x[i] == 'a':
		c = c + 1
if c > len(x) / 2 + 1:
	print(len(x))
else:
	print(c * 2 - 1)


yes = 0
no = 0
g = int()
letters = input()
L = list(letters)
for i in range(len(L)):
	if L[i] == 'a':
		yes += 1
	else:
		no += 1
for j in range(len(L)):
	if yes > no:
		g = yes + no
		break
	else:
		no -= 1
print(g)


inp = [x for x in input()]
(nota, c) = ([x for x in inp if x != 'a'], -1)
while inp.count('a') <= len(inp) / 2:
	c += 1
	inp.remove(nota[c])
print(len(inp))


s = str(input())
a = s.count('a')
if a > len(s) - a:
	print(len(s))
else:
	print(a + a - 1)


s = input()
num = s.count('a')
print(min(len(s), 2 * num - 1))


def love(s):
	s = list(s)
	while True:
		if s.count('a') > len(s) / 2:
			return len(s)
		for i in s:
			if i != 'a':
				s.remove(i)
				break
s = input()
print(love(s))


s = input().strip()
from collections import Counter
dict_s = Counter(s)
if len(s) < 2 * dict_s['a']:
	print(len(s))
else:
	print(2 * dict_s['a'] - 1)


def count(arr):
	m = 0
	for i in range(len(arr)):
		if arr[i] == 'a':
			m = m + 1
	return m
arr = input()
m = count(arr)
c = len(arr)
if m > c / 2:
	print(c)
else:
	d = 2 * m - 1
	l = c - d
	print(c - l)


z = input()
a = list(z)
while a.count('a') <= len(a) // 2:
	for i in a:
		if a.count('a') <= len(a) // 2:
			if i != 'a':
				a.remove(i)
print(len(a))


s = input()
m = 0
k = 0
c = 0
b = len(s)
for x in s:
	if x == 'a':
		m = m + 1
	else:
		k = k + 1
if m > k:
	print(b)
elif m == k:
	m = b - 1
	print(m)
else:
	m = m * 2 - 1
	print(m)


s = input()
x = s.count('a')
y = len(s)
while x / y <= 0.5:
	y -= 1
print(y)


import sys
data = sys.stdin.readlines()[0][:-1]
ct = data.count('a')
otLetNum = len(data) - ct
if otLetNum >= ct:
	sys.stdout.write(str(len(data) - (otLetNum - ct + 1)))
else:
	sys.stdout.write(str(len(data)))


strs = input()
size = len(strs)
a = sum([1 for e in strs if e == 'a'])
if a > size // 2:
	print(size)
else:
	print(2 * a - 1)


from collections import deque

def foo(s):
	if 2 * s.count('a') - 1 < len(s):
		print(2 * s.count('a') - 1)
	else:
		print(len(s))
first = input()
foo(first)


string = str(input())
print(min(len(string), string.count('a') * 2 - 1))


def amount(s):
	j = 0
	k = 0
	while True:
		a = s.find('a', j, len(s) + 1)
		if a != -1:
			k += 1
			j = a + 1
		else:
			return k
			break
s = input()
m = amount(s)
k = len(s) - m
if k > m - 1:
	k = m - 1
print(k + m)


s = list(input())
z = ''
for i in range(len(s)):
	if s[i] != 'a':
		z += s[i]
k = 0
z = list(z)
a = s.count('a')
while True:
	l = len(s)
	if a > l // 2:
		print(l)
		break
	else:
		s.remove(z[k])
		k = k + 1


str = []
c = 0
k = 0
str = input()
n = len(str)
for i in range(n):
	if str[i] == 'a':
		c = c + 1
d = c - n / 2
k = -d * 2 + 1
j = n - k
if d > 0:
	print(int(n))
else:
	print(int(j))


n = input()
l = len(n)
c = n.count('a')
c = 2 * c - 1
if c > l:
	print(l)
else:
	print(c)


S = list(input())
a = 0
o = 0
for i in S:
	if i == 'a':
		a += 1
	else:
		o += 1
if a > o:
	print(len(S))
else:
	print(2 * a - 1)


lst = [x for x in input()]
l = len(lst)
count = 0
for x in lst:
	if x == 'a':
		count += 1
ans = 2 * count - 1
if ans > l:
	print(l)
else:
	print(ans)


S = input()
numA = sum((1 for c in S if c == 'a'))
maxL = 2 * numA - 1
print(min(maxL, len(S)))


s = input().lower()
ac = s.count('a')
if ac > len(s) / 2:
	print(len(s))
else:
	print(ac * 2 - 1)


import sys
s = sys.stdin.readline().rstrip()
a_count = s.count('a')
length = len(s)
if a_count > length / 2:
	print(length)
else:
	ratio = a_count / length
	while ratio <= 0.5:
		length -= 1
		ratio = a_count / length
	print(str(length))


s = input()
cnt = s.count('a')
print(min(2 * cnt - 1, len(s)))


class Solution:

	def solve(self, string):
		numOfAs = 0
		for ch in string:
			if ch == 'a' or ch == 'A':
				numOfAs += 1
		isGood = numOfAs > len(string) / 2
		if isGood:
			return len(string)
		else:
			return numOfAs * 2 - 1
sol = Solution()
string = input().strip()
print(sol.solve(string))


s = tuple(input())
a = s.count('a')
if 2 * a > len(s):
	print(len(s))
else:
	print(2 * a - 1)


s = input()
l = len(s)
occ_a = s.lower().count('a')
if occ_a > l - occ_a:
	print(l)
else:
	print(2 * occ_a - 1)


import math
st = input()
re = st.count('a')
if re > math.ceil(len(st) / 2):
	print(len(st))
else:
	print(re + re - 1)


word = input()
count_a = word.count('a')
max_count_not_a = count_a - 1
print(min(len(word), count_a + max_count_not_a))


n = input()
length = n.count('a')
if length > len(n) // 2:
	print(len(n))
else:
	print(length + length - 1)


s = input()
if s.count('a') > len(s) // 2:
	print(len(s))
else:
	output = len(s)
	while True:
		if s.count('a') <= output // 2:
			output -= 1
		else:
			break
	print(output)


string = input()
n = len(string)
a_count = 0
for ch in string:
	if ch == 'a':
		a_count += 1
import math
if n % 2 == 0:
	if a_count > n // 2:
		print(n)
	else:
		print(2 * a_count - 1)
elif a_count >= math.ceil(n / 2):
	print(n)
else:
	print(2 * a_count - 1)


s = input()
a = 0
for c in s:
	if c == 'a':
		a += 1
t = len(s) - a
if a > t:
	print(a + t)
else:
	print(2 * a - 1)


s = input()
l = len(s)
k = s.count('a')
print(min(2 * k - 1, l))


n = input()
l = list(str(n))
c = 0
for i in l:
	if i == 'a':
		c = c + 1
s = len(l)
if c > s / 2:
	print(s)
else:
	t = c + c - 1
	print(t)


s = input()
len_s = len(s)
cnt = 2 * s.count('a')
print(len_s if cnt > len_s else cnt - 1)


def loveA(s):
	n = len(s)
	a_count = len([i for i in s if i == 'a'])
	if a_count * 2 > n:
		return n
	else:
		return 2 * a_count - 1
print(loveA(input()))


a = input()
sum = 0
list = list(a)
for i in range(len(a)):
	if 'a' in list[i]:
		sum += 1
tedad_baghieh_harfa = len(a) - sum
if sum > tedad_baghieh_harfa:
	print(len(a))
elif sum == tedad_baghieh_harfa:
	c = tedad_baghieh_harfa - 1
	print(sum + c)
elif sum < tedad_baghieh_harfa:
	d = tedad_baghieh_harfa - sum + 1
	answer = len(a) - d
	print(answer)


s = input()
n = s.count('a')
y = len(s)
if n > y / 2:
	print(y)
else:
	while n <= y / 2:
		y -= 1
	print(y)


a = list(input())
n = len(a)
m = a.count('a')
b = n - m
l = min(b, m)
if l == b:
	if m > n // 2:
		print(n)
	else:
		print(n - 1)
elif l == m:
	print(m + m - 1)


z = input
l = z()
n = len(l)
one = l.count('a')
if n // 2 < one:
	print(n)
	exit(0)
print(one * 2 - 1)


s = input()
a = s.count('a')
nota = len(s) - a
print(a + nota * (nota < a) + (a - 1) * (nota >= a))


a = input()
print((a.count('a') * 2 - 1, len(a))[a.count('a') > len(a) / 2])


s = input()
sa = s.count('a')
if sa <= len(s) - sa:
	print(sa * 2 - 1)
else:
	print(len(s))


s = input()
N = len(s)
acnt = s.count('a')
if acnt > N // 2:
	print(N)
else:
	print(N - (N - acnt - acnt + 1))


s = list(input())
s.sort()
res = (len(s) - 1 - s[::-1].index('a') + 1) * 2 - 1
print(res if res <= len(s) else len(s))


data = input()
a = data.count('a')
r = len(data) - a
if a > r:
	print(len(data))
else:
	print(a * 2 - 1)


s = input()
a = s.count('a')
b = len(s) - a
if a > b:
	print(len(s))
elif a == 0:
	print(0)
else:
	cpt = 0
	while b >= a:
		b -= 1
		cpt += 1
	print(len(s) - cpt)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
s = insr()
n = len(s)
a = s.count('a')
b = n - a
if a > b:
	print(n)
else:
	x = a + (a - 1)
	print(x)


n = input()
count_a = n.count('a')
length = len(n)
dec = count_a / length
while dec <= 0.5:
	length -= 1
	dec = count_a / length
print(length)


qs = lambda : input().split()
(a,) = qs()
print(2 * a.count('a') - 1 if a.count('a') <= len(a) / 2 else len(a))


n = list(str(input()))

def love(n):
	i = 0
	a = 0
	for q in range(len(n)):
		if n[i] == 'a':
			a += 1
			i += 1
		else:
			i += 1
	x = len(n) - a
	if a <= x:
		print(a * 2 - 1)
	else:
		print(len(n))
love(n)


s = input()
num_of_a = s.count('a')
s_half = len(s) / 2
ans = len(s) if num_of_a > s_half else num_of_a * 2 - 1
print(ans)


def love_a(string):
	length = len(string)
	counta = 0
	for i in string:
		if i == 'a':
			counta += 1
	counto = length - counta
	removed = 0
	while (counto + counta) / 2 >= counta:
		removed += 1
		counto -= 1
	return length - removed
string = input()
print(love_a(string))


s = input().strip()
l = len(s)
listed = list(s)
num_a = int(listed.count('a'))
num_not_a = l - num_a
necc_a = l // 2
while num_a <= necc_a:
	num_not_a = num_not_a - 1
	l = l - 1
	necc_a = l // 2
print(l)


s = input()
c = 0
x = len(s)
for i in s:
	if i == 'a':
		c = c + 1
if c > int(x / 2):
	print(x)
else:
	for i in s:
		if c > int(x / 2):
			break
		elif i != 'a':
			s = s.replace(i, '')
			x = x - 1
	print(x)


a = list(input())
b = len(a)
c = a.count('a')
if 2 * c > b:
	print(b)
else:
	print(2 * c - 1)


from string import ascii_lowercase
a = input()
print(min(a.count('a') * 2 - 1, len(a)))


s = input()
s = s.strip()
a = s.count('a')
if len(s) / 2 < a:
	print(len(s))
else:
	print(a * 2 - 1)


n = input()
A = 0
for i in range(0, len(n)):
	if n[i] == 'a':
		A += 1
if A > len(n) / 2:
	print(len(n))
else:
	hasil = A * 2 - 1
	print(hasil)


s = input()

def lovea(s):
	p = s.count('a')
	j = len(s)
	if 2 * p > j:
		return j
	elif 2 * p == j:
		return j - 1
	else:
		return 2 * p - 1
print(lovea(s))


argstr = input()
total = len(argstr)
n_as = len([x for x in argstr if x == 'a'])
n_os = total - n_as
if n_os >= n_as:
	n_os = n_as - 1
print(n_os + n_as)


string = str(input())
other_letters = len(string) - string.count('a')
count_a = string.count('a')
add = count_a - 1 if other_letters >= count_a else other_letters
print(count_a + add)


string = input()
count_a = string.count('a')
count_other = len(string) - count_a
if count_a > count_other:
	print(len(string))
else:
	print(len(string) - (count_other - count_a) - 1)


string = str(input())
counta = 0
count = 0
for i in range(len(string)):
	if string[i] != 'a':
		count += 1
	else:
		counta += 1
if counta > count:
	print(len(string))
else:
	print(len(string) - (count + 1 - counta))


string = input()
n = len(string)
a = string.count('a')
if a > n // 2:
	print(n)
elif a <= n // 2:
	print(2 * a - 1)


s = str(input())
d = s.count('a')
if d > len(s) - d:
	print(len(s))
else:
	print(2 * d - 1)


s = str(input())
j = 0
for i in range(0, len(s)):
	if s[i] == 'a':
		j += 1
k = len(s)
while True:
	if j > k / 2:
		print(k)
		exit()
	else:
		k -= 1


a = input()
a.lower()
b = a.count('a')
if b > len(a) / 2:
	print(len(a))
else:
	print(2 * b - 1)


s = input()
a = s.count('a')
print(min(a - 1 + a, len(s)))


s = input()
b = s.count('a')
c = 2 * b - 1
if c > len(s):
	d = 1
else:
	d = 0
if b < len(s) // 2 + 1:
	if d == 1:
		print(b + 1)
	else:
		print(c)
else:
	print(len(s))


A = input()
a = A.count('a')
print(min(len(A), 2 * a - 1))


str = input()
a = 0
ret_a = 0
ret_lo = len(str)
for i in str:
	if i == 'a':
		ret_a += 1
if ret_a / ret_lo <= 0.5:
	a = 2 * ret_a - 1
else:
	a = ret_lo
print(a)


s = input()
count = 0
for x in s:
	if x == 'a':
		count += 1
if len(s) - count < count:
	print(len(s))
else:
	print(count - 1 + count)


s = list(input())
len_s = len(s)
status = 'Good'
count = 0
for i in range(len(s)):
	if s[i] == 'a':
		count += 1
if count <= len(s) / 2:
	status = 'Bad'
if status == 'Bad':
	for i in range(len(s)):
		if s[i] != 'a':
			s[i] = 'n/a'
			len_s -= 1
		if count > len_s / 2:
			break
print(len(s) - s.count('n/a'))


string = input()
count_a = 0
for letter in string:
	if letter == 'a':
		count_a += 1
print(min(len(string), count_a * 2 - 1))


s = input()
q = s.count('a')
print(min(2 * q - 1, len(s)))


word = input()
A = word.count('a')
if A > len(word) // 2:
	print(len(word))
else:
	print(2 * A - 1)


string = input()
counter = string.count('a')
if counter > len(string) / 2:
	print(len(string))
else:
	print(2 * counter - 1)


word = input()
a = word.count('a')
w = len(word)
c = 0
if w > a:
	c = w - a
	while c >= a:
		c -= 1
w = c + a
print(w)


lets = input()
ass = lets.count('a')
if ass > len(lets) / 2:
	print(len(lets))
else:
	print(ass * 2 - 1)


a = input()
count1 = 0
count2 = 0
for i in a:
	if i == 'a':
		count1 += 1
	else:
		count2 += 1
if count1 > count2:
	print(len(a))
else:
	print(count2 - (count2 - count1 + 1) + count1)


stri = sorted(list(map(str, input())))
a = stri.count('a')
while a < (len(stri) >> 1) + 1:
	stri.pop()
print(len(stri))


n = input()
m = 0
a_c = n.count('a')
if a_c > len(n) / 2:
	print(len(n))
elif a_c != 1:
	print(a_c + a_c - 1)
else:
	print(a_c)


s = input()
a = s.count('a')
total = len(s)
while a <= total / 2:
	total -= total - 2 * a + 1
print(total)


import sys
sa = str(input())
cona = sa.count('a')
if cona > len(sa) // 2 + 1:
	print(len(sa))
else:
	print(cona * 2 - 1)


n = str(input())
l = len(n)
count_a = 0
for i in n:
	if i == 'a':
		count_a += 1
if count_a * 2 - 1 > l:
	print(l)
else:
	print(count_a * 2 - 1)


s = list(str(input()))
num = 0
var1 = len(s)
for i in s:
	if i == 'a':
		num += 1
if num > var1 / 2:
	print(var1)
else:
	print(num + num - 1)


s = [x for x in input()]
n = m = 0
for i in s:
	n = n + 1
	if i == 'a':
		m = m + 1
if m > n / 2:
	print(n)
else:
	print(2 * m - 1)


str = input()
lent = len(str)
mid = lent // 2
res = str.count('a')
if res > mid:
	print(lent)
else:
	print(res * 2 - 1)


def RL():
	return list(map(int, input().split()))
mod = 1000000007
from collections import Counter
s = input()
le = len(s)
c = Counter(s)
if c['a'] * 2 > le:
	print(le)
else:
	print(c['a'] * 2 - 1)


str = input('')
num = 0
for i in str:
	if i == 'a':
		num += 1
if len(str) < 2 * num:
	print(len(str))
else:
	print(2 * num - 1)


s = input()
v = s.count('a')
if v > len(s) // 2:
	print(len(s))
else:
	print(2 * v - 1)


s = input()
soA = s.count('a')
doDaiChuoi = len(s)
if soA > doDaiChuoi / 2:
	print(doDaiChuoi)
else:
	soKhacA = doDaiChuoi - soA
	print(2 * soA - 1)


a = input()
b = 0
i = 0
while i < len(a):
	if a[i] == 'a':
		b += 1
	i += 1
d = b + b - 1
if d < len(a):
	print(d)
else:
	print(len(a))


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def int1():
	return int(input())
import string
import math
from itertools import combinations

def main():
	a = list(input())
	a.pop()
	z = a.count('a')
	if z <= int(len(a) / 2):
		print(z * 2 - 1)
	else:
		print(len(a))
main()


string = input()
acount = string.count('a')
if acount > len(string) - acount:
	print(len(string))
else:
	other_diff = len(string) - acount - acount
	print(acount + (len(string) - acount) - other_diff - 1)


p = input()
m = len(p)
n = p.count('a')
if n > m // 2:
	print(m)
else:
	print(2 * n - 1)


a = input()
(k, n) = (a.count('a'), len(a))
if k > n - k:
	print(n)
else:
	while True:
		if k > n - k:
			print(n)
			break
		else:
			n = n - 1


s1 = input()
print(min(len(s1), 2 * s1.count('a') - 1))


def goodString(x, a):
	n = len(x)
	i = 0
	while i < n:
		if len(x) == 1:
			return 1
		elif a > int(len(x) / 2):
			n = len(x)
			return n
		elif a <= int(len(x) / 2) and x[i] != 'a':
			x.pop(i)
			n = len(x)
			i = -1
		i = i + 1

def main():
	s1 = input()
	temp_list = []
	for i in s1:
		temp_list.append(i)
	a = 0
	for i in temp_list:
		if i == 'a':
			a += 1
	result = goodString(temp_list, a)
	print(result)
main()


st = input()
l = len(st)
n = st.count('a')
if 2 * n - 1 > l:
	ans = l
else:
	ans = 2 * n - 1
print(ans)


from collections import Counter as c
string = input()
g = c(string)
a = g['a']
print(min(len(string), 2 * a - 1))


s = input().strip()
l = len(s)
c = s.count('a')
while c <= l / 2:
	l = l - 1
print(l)


s = input()
a = len(s)
b = s.count('a')
while a / b >= 2:
	a -= 1
print(a)


s = input()
a = s.count('a')
na = len(s) - a
dec = 0
while True:
	if a > (na - dec + a) / 2:
		print(na - dec + a)
		break
	dec += 1


s = input()
ns = list(s).count('a')
if ns > len(s) // 2:
	print(len(s))
else:
	print(2 * ns - 1)


from typing import List
from collections import Counter

class LoveA:

	def find_longest_string(self) -> int:
		string = input()
		countr = Counter(string)
		if countr['a'] > len(string) // 2:
			return len(string)
		else:
			return countr['a'] + countr['a'] - 1
love = LoveA()
print(love.find_longest_string())


strok = input()
l = len(strok)
a = strok.count('a')
if l - a < a:
	print(l)
else:
	print(a + a - 1)


s = input()
if s.count('a') > len(s) // 2:
	print(len(s))
else:
	b = []
	c = len(s)
	x = len(s) - s.count('a')
	for i in range(1, x + 1):
		c -= 1
		if s.count('a') > c // 2:
			break
	print(c)


s = input()
a = 0
for idx in s:
	if idx == 'a':
		a += 1
if a > len(s) / 2:
	print(len(s))
else:
	print(a * 2 - 1)


s = sorted(list(input()))
print((len(s) - 1 - s[::-1].index('a') + 1) * 2 - 1 if (len(s) - 1 - s[::-1].index('a') + 1) * 2 - 1 <= len(s) else len(s))


string = str(input())
count = 0
for char in string:
	if char == 'a':
		count += 1
if len(string) // 2 < count:
	print(len(string))
else:
	print(count * 2 - 1)


s = input()
i = s.count('a')
print(len(s)) if i > len(s) / 2 else print(i * 2 - 1)


import re
string = input()
n = len(string)
a = len(re.findall('a', string))
if 'a' not in string:
	print(0)
elif a == 1:
	print(1)
elif a > n - a:
	print(n)
else:
	print(2 * a - 1)


import sys
pin = sys.stdin.readline
pout = sys.stdout.write
ran = range
string = pin()
count = string.count('a')
if count <= int(len(string) / 2):
	print(count * 2 - 1)
else:
	print(len(string) - 1)


s = input()
n = len(s)
c = 0
for i in range(n):
	if s[i] == 'a':
		c += 1
print(min(n, 2 * c - 1))


s = input()
cnt = 0
for elem in s:
	if elem == 'a':
		cnt += 1
print(min(len(s), max(cnt * 2 - 1, 0)))


s = input()
n = len(s)
count_a = s.count('a')
if count_a > n / 2:
	print(n)
else:
	print(count_a * 2 - 1)


huruf = input()
hasil1 = 0
hasil2 = 0
for i in huruf:
	if i == 'a':
		hasil1 += 1
	else:
		hasil2 += 1
if hasil1 > hasil2:
	print(len(huruf))
else:
	print(hasil1 + hasil1 - 1)


s = input('')
a = s.count('a')
sol = 0
for i in range(len(s), a - 1, -1):
	if a > i / 2:
		sol = i
		break
print(sol)


inp = str(input())
a = 0
for i in inp:
	if i == 'a':
		a += 1
print(int(min([len(inp), 2 * a - 1])))


s = input()
i = 0
a = 0
while i < len(s):
	if s[i] == 'a' or s[i] == 'A':
		a += 1
	i += 1
if a > len(s) / 2:
	print(len(s))
else:
	print(a * 2 - 1)


s = input()
n = sum([1 for i in s if i == 'a'])
a = n * 2 - 1
print(min(a, len(s)))


string = input()
string = list(string)
length = len(string)
counter = 0
for i in range(length):
	if string[i] == 'a':
		counter += 1
if counter > length / 2:
	print(length)
else:
	print(counter * 2 - 1)


s = input()
ka = s.count('a')
print(min(ka * 2 - 1, len(s)))


s = input()
a = 0
plusiki = 0
while len(s) > plusiki:
	if s[plusiki] == 'a':
		a = a + 1
	plusiki = plusiki + 1
if a <= plusiki - a:
	print(a * 2 - 1)
else:
	print(plusiki)


s = input()
f = len(s)
while s.count('a') <= f - s.count('a'):
	f -= 1
print(f)


s = input()
t = len(s)
p = s.count('a')
if t < 2 * p:
	print(t)
else:
	print(2 * p - 1)


s = input('').lower()
f = len(s)
a = s.count('a')
if a > f // 2:
	print(f)
else:
	print(2 * a - 1)


n = list(input())
a = n.count('a')
b = len(n) - a
if a > b:
	print(len(n))
else:
	for i in range(b):
		b -= 1
		if a > b:
			print(a + b)
			break


def answer():
	a = list(input())
	y = 0
	z = 0
	for x in a:
		if x != 'a':
			y += 1
		else:
			z += 1
	if z > y:
		return len(a)
	else:
		return z * 2 - 1
print(answer())


from collections import Counter

def LoveA(s):
	c = Counter(s)
	count = c['a']
	l = len(s)
	if count > l // 2:
		return l
	else:
		words = sorted(s)
		result = 0
		while c['a'] <= len(words) // 2:
			len1 = len(words) - 1
			del words[len1]
			c = Counter(words)
			result = result + 1
		return len(words)
x = input()
print(LoveA(x))


string = input()
l = len(string)
a = string.count('a')
if a > l / 2:
	print(len(string))
else:
	while a <= l / 2:
		l -= 1
	print(l)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		ss = self.next()
		ca = ss.count('a')
		print(min(len(ss), ca * 2 - 1))
Main().solve()


s = input()
n = len(s)
c = 0
for i in range(n):
	if s[i] == 'a':
		c += 1
while True:
	m = n // 2 + 1
	if c >= m:
		break
	n -= 1
print(n)


string = input()
lettersInString = 0
countOfA = 0
for i in string:
	lettersInString += 1
	if i == 'a':
		countOfA += 1
if lettersInString >= 2 * countOfA:
	print(2 * countOfA - 1)
else:
	print(lettersInString)


s = input()
anz_a = s.count('a')
if len(s) == anz_a:
	print(anz_a)
else:
	print(anz_a * 2 - 1 if len(s) > anz_a * 2 - 1 else len(s))


def main():
	s = input()
	numA = 0
	for c in s:
		if c == 'a':
			numA += 1
	tamanho = numA * 2 - 1
	if tamanho < len(s):
		return print(tamanho)
	else:
		return print(len(s))
main()


string = input()
counter = len(string)
if string.count('a') > len(string) / 2:
	print(len(string))
else:
	while True:
		if string.count('a') > len(string) / 2:
			print(len(string))
			break
		for char in string:
			if char != 'a':
				string = string.replace(char, '', 1)
				break


user_input = input()
count_a = sum(('a' == item for item in user_input))
not_a = len(user_input) - count_a
if not_a >= count_a:
	print(count_a * 2 - 1)
else:
	print(not_a + count_a)


a = input()
b = len(a)
c = 0
for r in a:
	if r == 'a':
		c = c + 1
if c > b / 2:
	print(b)
else:
	print(2 * c - 1)


a = input()
c = a.count('a')
dlina = int(len(a))
if c >= dlina // 2 + 1:
	print(dlina)
else:
	print(c + (c - 1))


import math
s = input()
ac = s.count('a')
xc = len(s) - ac
rem = 0
while True:
	if ac > xc:
		break
	xc -= 1
print(ac + xc)


import sys
sys.setrecursionlimit(10 ** 9)

def main():
	n = input()
	if n.count('a') * 2 > len(n):
		print(len(n))
	else:
		print(n.count('a') * 2 - 1)
main()


ch = input()
count = 0
for i in ch:
	if i == 'a':
		count += 1
if count > len(ch) / 2:
	print(len(ch))
else:
	print(2 * count - 1)


f = list(input())
a = f.count('a')
if a * 2 - 1 > len(f):
	print(len(f))
else:
	print(a * 2 - 1)


s = input()
a_cnt = 0
n_cnt = 0
for c in s:
	if c == 'a':
		a_cnt = a_cnt + 1
	else:
		n_cnt = n_cnt + 1
if a_cnt <= n_cnt:
	print(2 * a_cnt - 1)
else:
	print(a_cnt + n_cnt)


randomString = input()
count_a = 0
for i in randomString:
	if i == 'a':
		count_a += 1
count_not_a = len(randomString) - count_a
if count_not_a < count_a:
	print(len(randomString))
else:
	print(2 * count_a - 1)


s1 = input()
l1 = len(s1)
cnt1 = 0
for i in range(0, l1):
	if s1[i] == 'a':
		cnt1 = cnt1 + 1
cnt2 = l1 - cnt1
if l1 / 2 >= cnt1:
	print(cnt1 * 2 - 1)
else:
	print(l1)


s = str(input())
cnt = 0
for i in range(len(s)):
	if s[i] == 'a':
		cnt += 1
if 2 * cnt - 1 > len(s):
	print(len(s))
else:
	print(2 * cnt - 1)


s = input()
aCount = s.count('a')
ans = len(s)
while ans - aCount >= aCount:
	ans -= 1
print(ans)


word = str(input())
Acount = 0
for c in word:
	if c == 'a':
		Acount = Acount + 1
	else:
		Acount = Acount
if Acount > len(word) - Acount:
	print(len(word))
else:
	print(2 * Acount - 1)


a = input()
ac = 0
for c in a:
	if c == 'a':
		ac += 1
print(len(a) if ac > len(a) / 2 else ac * 2 - 1)


string = input()
string_length = len(string)
num_a = 0
num_not_a = 0
for current_letter in string:
	if current_letter == 'a':
		num_a += 1
	else:
		num_not_a += 1
if num_a > num_not_a:
	print(string_length)
else:
	diff = num_not_a - num_a
	string_length -= diff
	print(string_length - 1)


n = input()
li = []
for i in n:
	if i == 'a':
		li.append(i)
s = len(n) - len(li)
if len(li) > s:
	print(len(n))
else:
	print(len(li) + (len(li) - 1))


s = input()
count_a = s.count('a')
count_s = len(s)
if count_a <= count_s - count_a:
	print(2 * count_a - 1)
else:
	print(count_s)


class Main:
	s = input()
	initial = len(s)
	add = 0
	while not s.count('a') > len(s) / 2:
		s = s + 'a'
		add += 1
	max_length = initial - add
	print(max_length)
Main()


s = input()
a = 0
x = 0
for i in range(len(s)):
	if s[i] == 'a':
		a += 1
	else:
		x += 1
if a > x:
	print(a + x)
else:
	rest = x - a
	print(a + x - rest - 1)


s = input()
a = len(s)
b = s.count('a')
c = a - b
if b == c:
	print(a - 1)
elif b > c:
	print(a)
else:
	d = c - b + 1
	e = a - d
	print(e)


s = input()
ca = s.count('a')
cv = len(s)
cna = cv - ca
while True:
	ca = s.count('a')
	cv = len(s)
	l = cv // 2 + 1
	if ca >= l:
		print(len(s))
		exit()
	else:
		e = list(enumerate(s))
		c = list(filter(lambda x: x[1] != 'a', e))
		i = c[0][1]
		s = s.replace(i, '', 1)
		continue


s = input()
cnt = len([x for x in s if x == 'a'])
print(min(2 * cnt - 1, len(s)))


string = input()
acount = 0
for c in string:
	if c == 'a':
		acount += 1
print(min([acount * 2 - 1, len(string)]))


s = input()
cnt = 0
for c in s:
	if c == 'a':
		cnt += 1
	else:
		cnt -= 1
ans = len(s)
while cnt <= 0:
	ans -= 1
	cnt += 1
print(ans)


def main():
	s = input()
	count = 0
	for i in range(len(s)):
		if s[i] == 'a':
			count = count + 1
	l = len(s)
	sub = 0
	while True:
		if count > (l - sub) / 2:
			break
		else:
			sub = sub + 1
	print(l - sub)
main()


s = input()
half = len(s) // 2 + 1
if s.count('a') > len(s) // 2:
	print(len(s))
	exit()
else:
	print(s.count('a') * 2 - 1)


def mp():
	return map(int, input().split())
s = input()
n = len(s)
a = s.count('a')
x = max(0, n - a * 2 + 1)
print(n - x)


z = input()
x = []
l = []
for y in range(len(z)):
	x.append(z[y])
a = 0
b = 0
for d in x:
	if d == 'a':
		a += 1
	if d != 'a':
		b += 1
if b >= a:
	print(2 * a - 1)
else:
	print(a + b)


a = str(input())
b = a.count('a')
if b <= len(a) / 2:
	print(b * 2 - 1)
else:
	print(len(a))


ins = list(input())
ca = 0
for c in ins:
	if c == 'a':
		ca += 1
if ca > len(ins) // 2:
	print(len(ins))
	exit()
print(ca * 2 - 1)


a = input()
count = 0
count2 = 0
for b in a:
	if b == 'a':
		count += 1
	else:
		count2 += 1
if count > count2:
	print(len(a))
else:
	z = count2 - count
	print(len(a) - (z + 1))


s = input()

def love_a(s):
	while s.count('a') <= len(s) / 2:
		k = -1
		for i in range(len(s)):
			if s[i] != 'a':
				k = i
				break
		if k != -1:
			s = s[:k] + s[k + 1:]
	print(len(s))
love_a(s)


s = input()
count = 0
if len(s) >= 1 and len(s) <= 50:
	ls = list(s)
	for i in ls:
		if i == 'a':
			count = count + 1
	if count >= len(s) // 2 + 1:
		print(len(s))
	else:
		notneed = count + (count - 1)
		print(notneed)


n = input()
l = len(n)
a = n.count('a')
if a > l / 2:
	print(l)
if a < l / 2:
	print(a * 2 - 1)
if a == l / 2:
	print(l - 1)


s = str(input())
l = list(s)
count = 0
for i in range(len(l)):
	if l[i] == 'a':
		count += 1
if count > len(l) // 2:
	print(len(l))
else:
	print(2 * count - 1)


s = input()
li = list(s)
mid = len(s) // 2
count_a = li.count('a')
if count_a > mid:
	print(len(s))
else:
	print(count_a * 2 - 1)


s = list(input())
count = 0
flag = 0
for i in s:
	if i == 'a':
		count += 1
	if i != 'a':
		flag += 1
while count <= flag:
	flag -= 1
print(count + flag)


s = input()
n = len(s)
cnta = s.count('a')
if cnta > int(n / 2):
	print(n)
else:
	print(2 * cnta - 1)


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
s = input().strip()
a = s.count('a')
req = len(s) - a
if req < a:
	print(len(s))
else:
	print(len(s) - (req - a + 1))


def quicksort(array):
	if len(array) < 2:
		return array
	else:
		pivot = array[0]
		less = [i for i in array[1:] if i <= pivot]
		greater = [i for i in array[1:] if i > pivot]
		return quicksort(less) + [pivot] + quicksort(greater)
s = list(input())
s = quicksort(s)
la = len(list(filter(lambda x: x == 'a', s)))
lo = len(s) - la
if lo >= la:
	ans = 2 * la - 1
	print(ans)
else:
	print(len(s))


x = input()
k = x.count('a')
print(len(x) if k > len(x) // 2 else k * 2 - 1)


s = input()
cou = s.count('a')
if cou > len(s) // 2:
	print(len(s))
else:
	print(cou + cou - 1)


x = input()
all_frq = {}
length = len(x)
for i in x:
	if i in all_frq:
		all_frq[i] += 1
	else:
		all_frq[i] = 1
while all_frq['a'] <= length / 2:
	length -= 1
print(length)


st = input()
num_a = st.count('a')
if len(st) / 2 >= num_a:
	print(num_a * 2 - 1)
else:
	print(len(st))


s = input()
nba = s.count('a')
nbo = len(s) - nba
print(min(len(s) - (nbo - nba + 1), len(s)))


s = input()
value_of_a = 0
for i in range(0, len(s)):
	if s[i:i + 1] == 'a':
		value_of_a += 1
if len(s) / 2 < value_of_a:
	print(len(s))
	exit()
else:
	print(2 * value_of_a - 1)


n = input().strip()
lists = list(n)
a = n.count('a')
e = len(n)
if a * 2 <= e:
	print(a * 2 - 1)
else:
	print(e)


S = input()
a_count = S.count('a')
rem_char = len(S) - a_count
if a_count > rem_char:
	print(len(S))
else:
	print(2 * a_count - 1)


from collections import Counter
s = input()
d = Counter(s)
c = 0
for i in d:
	if i == 'a':
		continue
	c = c + d[i]
if c < d['a']:
	print(len(s))
elif c == d['a']:
	print(len(s) - 1)
else:
	print(len(s) - (c - d['a']) - 1)


s = input()
a = 0
o = 0
c = 0
for i in range(0, len(s)):
	if s[i] == 'a':
		a += 1
	else:
		o += 1
if a > o:
	print(a + o)
elif a == o:
	print(a + o - 1)
else:
	while 1:
		o -= 1
		if a > o:
			c = 1
			break
	if c == 1:
		print(a + o)


s = str(input())
a = sorted(s)
x = len(a)
count = 0
for i in range(0, x):
	if a[i] == 'a':
		count += 1
print(max(min(2 * count - 1, x), 0))


A = input()
Na = 0
Nx = 0
for i in A:
	if i == 'a':
		Na += 1
	else:
		Nx += 1
print(min(Na * 2 - 1, Na + Nx))


s = input()
length = len(s)
num = s.count('a')
if num >= length // 2 + 1:
	print(length)
else:
	print(num + num - 1)


def main():
	s = input()
	count = s.count('a')
	if count > len(s) // 2:
		return len(s)
	else:
		return count * 2 - 1
print(main())


def isGoodOrNot(word):
	frequencyOfA = 0
	for character in word:
		if character == 'a':
			frequencyOfA = frequencyOfA + 1
	if frequencyOfA / len(word) > 0.5:
		return len(word)
	else:
		length = len(word) - 1
		while frequencyOfA / length <= 0.5:
			length = length - 1
		return length
word = input()
print(isGoodOrNot(word))


import math
s = input()
l = len(s)
m = l // 2
x = s.count('a')
if x > m:
	print(l)
else:
	print(2 * x - 1)


s = input()
na = s.count('a')
nl = len(s)
erase = max(nl - 2 * na + 1, 0)
print(nl - erase)


def main():
	inp = {}
	inp_str = input()
	length = len(inp_str)
	cnt = inp_str.count('a')
	s_l = length // 2
	while cnt <= s_l:
		length -= 1
		if length // 2 < cnt:
			break
	print(length)
main()


for i in range(1):
	s = input()
	a = s.count('a')
	if a > len(s) // 2:
		print(len(s))
	else:
		s = sorted(s)
		while s.count('a') <= len(s) // 2:
			s.pop()
		print(len(s))


s = input()
a = s.count('a')
if a > len(s) // 2:
	print(len(s))
else:
	v = len(s) - a
	while 1:
		v -= 1
		if a > v:
			break
	print(a + v)


a = input()
same = 0
different = 0
for i in a:
	if i == 'a':
		same += 1
	else:
		different += 1
if different > same:
	print(len(a) - (different - same + 1))
elif different == same:
	print(len(a) - 1)
else:
	print(len(a) - 0)


string = input()
occurences = 0
for char in string:
	if char == 'a':
		occurences += 1
difference = len(string) - occurences
if difference >= occurences:
	print(len(string) - (difference - occurences) - 1)
else:
	print(len(string))


str = input()
l = len(str)
cnt = str.count('a')
sum = 2 * cnt - 1
m = min(l, sum)
print(m)


line = input()
a = line.count('a')
nona = len(line) - a
if a > len(line) // 2:
	print(len(line))
else:
	print(2 * a - 1)


s = input()
temp = s.count('a')
if temp * 2 > len(s):
	print(len(s))
else:
	print(2 * temp - 1)


import sys
import math
str = input()
c = str.count('a')
l = len(str)
if c > math.ceil(l / 2) and l % 2 == 0:
	print(l)
elif c >= math.ceil(l / 2) and l % 2 != 0:
	print(l)
else:
	print(c * 2 - 1)


def calcul_a(s):
	a = 0
	for x in s:
		if x == 'a':
			a = a + 1
	return a
s = input()
a = calcul_a(s)
if a > len(s) // 2:
	print(len(s))
else:
	print(2 * a - 1)


def cal_good_string(n):
	if n.count('a') > len(n) / 2:
		return len(n)
	else:
		return cal_good_string(''.join(sorted(n))[:-1])
n = input()
i = cal_good_string(n)
print(i)


m = list(input())
l = len(m)
w = 0
count = 0
s = 1
for i in range(len(m)):
	if m[i] == 'a':
		w = w + 1
	else:
		count = count + 1
i = 1
if w > count:
	print(len(m))
else:
	while w <= count:
		if m[l - i] != 'a':
			m.remove(m[l - i])
			count -= 1
		i += 1
	print(w + count)


s = input()
n = len(s)
c = 0
m = []
p = s.count('a')
q = n - p
if p > q:
	print(n)
else:
	print(p + (p - 1))


l = list(input())
acount = sum([l[x] == 'a' for x in range(len(l))] * 1)
if acount > len(l) - acount:
	print(len(l))
elif acount == len(l) - acount:
	print(len(l) - 1)
else:
	print(2 * acount - 1)


s = input()
a = len([i for i in s if i in 'a']) * 2 - 1
if a < 0:
	print(0)
	exit()
if a <= len(s):
	print(a)
elif a > len(s):
	print(len(s))


s = input()
som = 0
for i in range(len(s)):
	if s[i] == 'a':
		som += 1
	else:
		som -= 1
if som > 0:
	print(len(s))
else:
	print(len(s) + som - 1)


s = sorted(input())
print(min(2 * s.count('a') - 1, len(s)))


import sys
input = sys.stdin.readline
test_str = input()
a_count = test_str.count('a')
if a_count > len(test_str) / 2:
	print(len(test_str) - 1)
else:
	print(a_count * 2 - 1)


x = input()
l = len(x)
c = 0
y = l / 2
for i in range(l):
	if x[i] == 'a':
		c = c + 1
a = 0
if y > c:
	a = y - c
if c > y:
	print(l)
elif c == y:
	print(l - 1)
else:
	print(2 * c - 1)


s = input()
n = []
for i in s:
	n.append(i)
(count, count1) = (0, 0)
n.sort()
for i in range(len(n)):
	if n[i] == 'a':
		count += 1
	elif n[i] != 'a':
		count1 += 1
if count > count1:
	print(len(n))
else:
	print(count + count - 1)


import math

def solution(s):
	no_of_a = sum((1 for i in s if i == 'a'))
	n = len(s)
	half = n // 2
	if no_of_a > half:
		print(n)
	else:
		print(2 * no_of_a - 1)
s = input().strip()
solution(s)


string = input()
count = 0
othercount = 0
for i in range(len(string)):
	if string[i] == 'a':
		count += 1
	else:
		othercount += 1
if count > len(string) / 2:
	print(len(string))
else:
	print(count * 2 - 1)


word = input()
a_count = word.count('a')
length = len(word)
while a_count <= length / 2:
	length -= 1
print(length)


x = input()
numAs = x.count('a')
answer = min(len(x), 2 * numAs - 1)
print(answer)


n = input()
slen = len(n)
acount = n.count('a')
if acount > slen // 2:
	print(slen)
else:
	print(acount * 2 - 1)


a = str(input(''))
b = list(a)
count = int(0)
for i in range(len(b)):
	if b[i] == 'a':
		count = int(count + 1)
if count > len(b) / 2:
	print(len(b))
else:
	print(count + (count - 1))


n = str(input())
output = 0
for i in n:
	if n.count('a') > len(n) - n.count('a'):
		output = len(n)
	else:
		output = n.count('a') * 2 - 1
print(output)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	S = Scanner.string()
	an = S.count('a')
	xn = len(S) - an
	print(min(an + an - 1, an + xn))
main()


s = input()
n = len(s)
a = s.count('a')
non_a = n - a
if a > non_a:
	print(n)
else:
	print(a * 2 - 1)


text = list(input())
a = text.count('a')
f = ''.join(text).replace('a', '')
while a <= len(f):
	f = f[:-1]
	text = text[:-1]
print(len(text))


a = str(input())
b = 0
d = len(a) // 2
k = len(a)
z = 0
for i in range(len(a)):
	if 'a' in a[i]:
		b = b + 1
	elif 'a' not in a[i]:
		z -= -1
if b > z:
	c = int(len(a))
elif b == z:
	c = k - 1
elif b < z:
	c = k - (z - b) - 1
print(c)


def main():
	s = [x for x in input()]
	acount = 0
	ocount = 0
	for i in s:
		if i == 'a':
			acount += 1
		else:
			ocount += 1
	ans = 0
	while acount <= (acount + ocount) // 2:
		ans += 1
		ocount -= 1
	print(len(s) - ans)
main()


s = input()
a_cnt = s.count('a')
if a_cnt > len(s) // 2:
	print(len(s))
else:
	print(a_cnt * 2 - 1)


from math import ceil
s = input()
t = len(s)
c = s.count('a')
if t % 2 == 0:
	mm = t // 2 + 1
	if c >= mm:
		print(t)
	else:
		print(c * 2 - 1)
else:
	mm = t // 2 + 1
	if c >= mm:
		print(t)
	else:
		print(c * 2 - 1)


s = input()
acnt = s.count('a')
non_acnt = len(s) - acnt
if non_acnt >= acnt:
	print(str(acnt + acnt - 1))
else:
	print(len(s))


i1 = list(input())
if i1.count('a') * 2 - 1 > len(i1):
	print(len(i1))
else:
	print(i1.count('a') * 2 - 1)


str = input()
while True:
	if str.count('a') > len(str) / 2:
		break
	for letter in str:
		if letter != 'a':
			str = str.replace(letter, '', 1)
			break
print(len(str))


n = input()
b = list(n)
r = len(b)
x = b.count('a')
lst = []
for i in b:
	if i != 'a':
		lst.append(i)
y = len(lst)
if x > y:
	print(r)
elif x == y:
	print(r - 1)
elif x < y:
	c = y - x
	k = c + 1
	m = r - k
	print(m)


import heapq
import queue
from collections import *
import math

def sieve(n):
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return primes
s = str(input())
le = len(s)
lei = le // 2
lea = s.count('a')
if lea > lei:
	print(le)
else:
	while lea <= lei:
		le -= 1
		lei = le // 2
	print(le)


class CodeforcesTask1146ASolution:

	def __init__(self):
		self.result = ''
		self.s = ''

	def read_input(self):
		self.s = input()

	def process_task(self):
		a = self.s.count('a')
		if a > len(self.s) // 2:
			self.result = str(len(self.s))
		else:
			self.result = str(a * 2 - 1)

	def get_result(self):
		return self.result
Solution = CodeforcesTask1146ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


s = input()
n = len(s)
k = s.count('a')
if n >= 2 * k:
	print(2 * k - 1)
else:
	print(n)


def a(s):
	n = s.count('a')
	if n > len(s) / 2:
		print(len(s))
	else:
		print(n * 2 - 1)
s = input()
a(s)


(a, s) = (0, input())
for i in s:
	if i == 'a':
		a += 1
l = a
while a > l / 2 and l <= len(s):
	l += 1
print(l - 1)


a1 = input()
count1 = 0
count2 = 0
for i in a1:
	if i == 'a':
		count1 += 1
	else:
		count2 += 1
rez = len(a1)
while count2 >= count1:
	rez -= 1
	count2 -= 1
print(rez)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]
s = input()
a = s.count('a')
if a > len(s) // 2:
	print(len(s))
else:
	print(a + a - 1)


s = str(input())
aCount = 0
other = 0
for i in s:
	if i == 'a':
		aCount += 1
	else:
		other += 1
while other >= aCount:
	other -= 1
print(aCount + other)


ip = input()
aCount = 0
others = 0
for i in ip:
	if i == 'a':
		aCount += 1
	else:
		others += 1
if others >= aCount:
	print(2 * aCount - 1)
else:
	print(len(ip))


a = input()
s = list(a)
d = len(s)
n = s.count('a')
if n > len(s) // 2:
	print(len(s))
else:
	for i in s:
		if i != 'a':
			d -= 1
		if n > d // 2:
			break
	print(d)


s = input()
a = 0
na = 0
for i in range(len(s)):
	if s[i] == 'a':
		a += 1
	else:
		na += 1
while a <= na:
	na -= 1
print(a + na)


s = input()
a = 0
for i in range(len(s)):
	if s[i] == 'a':
		a += 1
n = len(s)
k = n - a
c = a - k
if c > 0:
	print(n)
else:
	print(a + k + c - 1)


def solve(s):
	return min(s.lower().count('a') * 2 - 1, len(s))

def main():
	s = input()
	print(solve(s))
main()


inputString = input()
numberOfA = inputString.count('a')
lengthOfString = len(inputString)
maxGoodStringIfLong = numberOfA + (numberOfA - 1)
if lengthOfString > maxGoodStringIfLong:
	print(maxGoodStringIfLong)
else:
	print(lengthOfString)


p = input()
p2 = len(p)
p1 = 0
for i in p:
	if i == 'a':
		p1 = p1 + 1
if p1 > p2 / 2:
	print(int(p2))
else:
	print(int(p1) + int(p1 - 1))


h = input()
x = len(h)
if x == 0:
	print(0)
else:
	y = x // 2
	c1 = 0
	c2 = 0
	for i in range(x):
		if h[i] == 'a':
			c1 = c1 + 1
		else:
			c2 = c2 + 1
	if c1 > y:
		print(x)
	else:
		z = c2 - c1 + 1
		print(x - z)


s = list(input())
countA = s.count('a')
otherLetters = len(s) - countA
if countA > otherLetters:
	print(len(s))
else:
	lettersRemove = otherLetters - countA + 1
	print(len(s) - lettersRemove)


t = input()
a = t.count('a')
if a > len(t) - a:
	print(len(t))
else:
	print(len(t) - (len(t) - a - a + 1))


x = input()
a = x.count('a')
ans = a * 2 - 1
if ans > len(x):
	print(len(x))
else:
	print(ans)


st = list(input())
print(min(len(st), st.count('a') * 2 - 1))


s = input()
k = 0

def char_split(str):
	return [char for char in str]
letters = char_split(s)
a_count = 0
for letter in letters:
	if letter == 'a':
		a_count += 1
l = len(letters)
while l >= a_count * 2:
	l -= 1
print(l)


a = input()
(n, c) = (len(a), a.count('a'))
print([n, 2 * c - 1][c * 2 <= n])


n = input()
count = 0
counta = 0
for letter in n:
	if letter == 'a':
		counta = counta + 1
	count = count + 1
if counta > count // 2:
	print(count)
else:
	print(counta + counta - 1)


ipt = input().strip()
c = 0
a = 0
for ch in ipt:
	c += 1
	if ch == 'a':
		a += 1
if a > c / 2:
	print(c)
else:
	print(a * 2 - 1)


s = input()
a_count = sum([1 for c in s if c == 'a'])
if a_count > len(s) // 2:
	print(len(s))
else:
	print(a_count * 2 - 1)


def main():
	letters = input()
	while letters.count('a') <= len(letters) / 2:
		for i in range(len(letters)):
			popped = False
			if popped == True:
				break
			if letters[i] != 'a':
				letters = letters[:i] + letters[i + 1:]
				break
	print(len(letters))
main()


s = str(input(''))
numOfAs = 0
numOfNotAs = 0
for i in s:
	if i == 'a':
		numOfAs += 1
	else:
		numOfNotAs += 1
if numOfAs > numOfNotAs:
	print(len(s))
else:
	print(len(s) - (numOfNotAs + 1 - numOfAs))


s = list(input())
a = s.count('a')
l = len(s)
if a > l / 2:
	print(l)
else:
	anotherLetters = l - a
	delta = anotherLetters - a
	l = l - delta - 1
	print(l)


s = input()
a_count: int = 0
l: int = len(s)
for x in s:
	if x == 'a':
		a_count += 1
while a_count <= l / 2:
	l -= 1
print(l)


s = input()
l = len(s)
n = s.count('a')
m = min(l, 2 * n - 1)
print(m)


s = input()
n = s.count('a')
l = len(s)
if n > l / 2:
	print(l)
else:
	print(n + (n - 1))


s = input()
cnt = 0
for c in s:
	if c == 'a':
		cnt += 1
print(cnt + min(len(s) - cnt, cnt - 1))


import math
s = input()
n = len(s)
count = s.count('a')
comp = math.ceil(n / 2)
if count > comp:
	print(n)
else:
	print(2 * count - 1)


n = input()
print(len(n) - max(len(n) - 2 * n.count('a') + 1, 0))


stringa = input()
aantalcaracter = len(stringa)
aantala = 0
aantalander = 0
for i in stringa:
	if i == 'a':
		aantala += 1
	else:
		aantalander += 1
if aantala > aantalander:
	print(aantalcaracter)
else:
	print(aantala + aantala - 1)


import math
aliceStr = input()
length = len(aliceStr)
count = aliceStr.count('a')
if count == 1:
	print(count)
else:
	mid = int(math.ceil(length / 2))
	if mid < count:
		print(length)
	else:
		print(count * 2 - 1)


s = input()
cont = 0
for i in s:
	if i == 'a':
		cont += 1
total = len(s)
temp = cont * 2 - 1
print(min(temp, total))


s = input()
c = 0
n = len(s)
for i in s:
	if i == 'a':
		c = c + 1
x = 2 * c - 1
if n < x:
	print(n)
else:
	print(x)


from sys import stdin

def readLine():
	return stdin.readline().strip()

def readInt():
	return int(readLine())

def readInts():
	return list(map(int, readLine().split()))

def count(c, S):
	res = 0
	for e in S:
		if c == e:
			res += 1
	return res

def main():
	S = readLine()
	N = len(S)
	M = count('a', S)
	if M > N / 2:
		print(N)
	else:
		print(2 * M - 1)
main()


import sys
line = sys.stdin.readline().strip()
print(min(2 * line.count('a') - 1, len(line)))


s = input()
count = 0
counta = 0
for item in s:
	if item == 'a':
		counta = counta + 1
	else:
		count = count + 1
if count < counta:
	print(counta + count)
else:
	print(2 * counta - 1)


import time

def enhanceAliceStr(nStr):
	qtyA = 0
	lenS = len(nStr)
	for x in nStr:
		if x == 'a':
			qtyA += 1
	if qtyA == 1:
		return 1
	else:
		opt = qtyA * 2 - 1
		if qtyA > int(lenS / 2):
			return lenS
		else:
			return opt

def solve():
	aliceStr = input()
	print(enhanceAliceStr(aliceStr))
solve()


import re
s = input()
a = 'a'
l = len(re.findall(a, s))
if l <= len(s) - l:
	print(l * 2 - 1)
elif l > len(s) - l:
	print(len(s))


import math

def a(s):
	numOfA = 0
	for i in s:
		if i == 'a':
			numOfA += 1
	if numOfA > len(s) / 2:
		print(len(s))
	else:
		print(2 * numOfA - 1)
a(input())


def main():
	letters = input()
	answer = min(len(letters), 2 * letters.count('a') - 1)
	print(answer)
main()


n = input()
l = list(n)
r = []
for i in range(len(l)):
	if l[i] == 'a':
		r.append(l[i])
if len(r) > len(n) - len(r):
	print(len(n))
else:
	x = len(r) - 1
	a = x + len(r)
	print(a)


def main():
	iv = input()
	ac = len([v for v in iv if v == 'a'])
	print(min(ac + ac - 1, len(iv)))
main()


string = input()
k = len(string)
count = 0
counta = 0
for i in range(0, k):
	if string[i] == 'a':
		counta += 1
	else:
		count += 1
if counta == 1:
	print(1)
elif counta > count:
	print(k)
else:
	while True:
		count -= 1
		if counta > count:
			c = 1
			break
	if c == 1:
		print(counta + count)


s = input()
half_s = len(s) / 2
if s.count('a') > half_s:
	print(len(s))
else:
	print(s.count('a') + s.count('a') - 1)


s = input()
chars = {'a': 0, 'e': 0}
for c in s:
	if c == 'a':
		chars['a'] += 1
	else:
		chars['e'] += 1
deleted = 0
while chars['a'] <= chars['e']:
	deleted += 1
	chars['e'] -= 1
print(len(s) - deleted)


string = input()
string_length = len(string)
a_length = string.count('a')
if string_length < a_length * 2:
	print(string_length)
else:
	print(string_length - min(string_length - a_length, string_length - 2 * a_length + 1))


s = input()
ca = 0
cx = 0
for x in s:
	if x == 'a':
		ca += 1
	else:
		cx += 1
print(ca + min(ca - 1, cx))


a = input()
l = len(a)
c = a.count('a')
t = c + c - 1
if l > t:
	print(t)
else:
	print(c + (l - c))


import sys
import copy
sys.setrecursionlimit(1000000)
s: str = input()
a = s.count('a')
e = len(s) - a
print(a + min(a - 1, e))


def three_numbers():
	numbers = list(map(int, input().split(sep=' ')))
	m = max(numbers)
	for i in numbers:
		if i != m:
			print(m - i, end=' ')

def gen_and_card_game():
	card = input()
	my_cards = list(input().split(sep=' '))
	for i in my_cards:
		if i[0] == card[0] or i[1] == card[1]:
			print('YES')
			break
	else:
		print('NO')

def kazak_vus_and_contest():
	(a, b, c) = map(int, input().split(sep=' '))
	if a - b <= 0 and a - c <= 0:
		print('YES')
	else:
		print('NO')

def like_A():
	st = input()
	count_a = 0
	for i in st:
		if i == 'a':
			count_a += 1
	if count_a > len(st) - count_a:
		print(len(st))
	else:
		print(count_a + count_a - 1)
like_A()


x = input()
countA = x.count('a')
countOther = len(x) - countA
if countOther >= countA:
	print(countA + (countA - 1))
else:
	print(countA + countOther)


import math
t = input('')
n = len(t)
c = t.count('a')
if n % 2 == 0:
	if c > n // 2:
		print(n)
	else:
		print(2 * c - 1)
elif c >= n // 2 + 1:
	print(n)
else:
	print(2 * c - 1)


i = input()
len_ = len(i)
count_a = i.count('a')
if round(len_ / 2) < count_a:
	print(len_)
else:
	print(count_a * 2 - 1)


s = input()
a = len(list(filter(lambda x: x == 'a', s)))
print(min(2 * a - 1, len(s)))


s = input()
list = []
for word in s:
	list.append(word)
a = 0
x = 0
for i in range(0, len(list)):
	if list[i] == 'a':
		a += 1
	else:
		x += 1
if a > x:
	print(a + x)
else:
	while x >= a:
		x -= 1
	print(a + x)


s = input()
sca = s.count('a')
ls = len(s)
print(min(ls, sca * 2 - 1))


import re
s = input()
x = re.findall('a', s)
if len(x) > len(s) // 2:
	print(len(s))
else:
	print(2 * len(x) - 1)


s = input()
n = len(s)
n_a = s.count('a')
for i in range(n):
	if n_a > (n - i) // 2:
		print(n - i)
		break


st = str(input())
cou = st.count('a')
lo = len(st)
if cou > len(st) // 2:
	print(len(st))
else:
	co = lo
	while cou <= lo / 2:
		co -= 1
		lo -= 1
	print(co)


def main():
	s = input()
	n = len(s)
	count_a = s.count('a')
	count_others = n - count_a
	max_others = count_a - 1
	print(n if count_others <= max_others else n - (count_others - max_others))
main()


from collections import Counter
x = list(input())
le = len(x)
d = Counter(x)
temp = d['a']
if temp * 2 > le:
	print(le)
else:
	temp = le - temp * 2 + 1
	print(le - temp)


def main():
	s = input()
	x = s.count('a')
	print(min(len(s), 2 * x - 1))
main()


s = input()
ca = 0
cx = 0
for i in range(len(s)):
	if s[i] == 'a':
		ca += 1
	else:
		cx += 1
if ca > len(s) // 2:
	print(len(s))
else:
	print(len(s) - abs(ca - cx) - 1)


s = list(input())
counter = s.count('a')
if counter > len(s) - counter:
	print(len(s))
else:
	print(2 * counter - 1)


string = input()
counta = 0
county = 0
for x in string:
	if x == 'a':
		counta += 1
	else:
		county += 1
if counta > county:
	print(counta + county)
else:
	print(counta + counta - 1)


l = list(input())
a = b = 0
for i in l:
	if i == 'a':
		a += 1
	if i != 'a':
		b += 1
if a > b:
	print(a + b)
else:
	print(2 * a - 1)


s = input()
acount = s.count('a')
if acount <= len(s) / 2:
	print(2 * acount - 1)
else:
	print(len(s))


z = input()
t = z.count('a')
l = len(z)
if l < 2 * t:
	print(l)
else:
	print(2 * t - 1)


st = input()
a = 0
for c in st:
	if c == 'a':
		a += 1
print(min(len(st), a * 2 - 1))


str = input()
l = len(str)
j = 0
for i in range(0, l):
	if str[i] == 'a':
		j += 1
if j > l / 2:
	print(l)
else:
	print(j * 2 - 1)


t = input()
soA = t.count('a')
if soA > len(t) / 2:
	print(len(t))
else:
	print(2 * soA - 1)


def main():
	from collections import Counter
	a = input()
	d = Counter(a)
	print(min(len(a), 2 * d['a'] - 1))
main()


s = input()
s = list(s)
k = s.count('a')
print(min(len(s), 2 * k - 1))


s = input()
noa = s.count('a')
l = len(s)
if noa > l / 2:
	print(l)
else:
	print(int(noa * 2 - 1))


s = input()
cnt = 0
for i in s:
	if i != 'a':
		cnt += 1
a = len(s) - cnt
erase = 0
while cnt and cnt >= a:
	cnt -= 1
	erase += 1
print(len(s) - erase)


s = input()
n = len(s)
na = sum(map(lambda c: c == 'a', s))
print(min(n, na * 2 - 1))


n = input()
x = []
for i in n:
	n.split(i)
	x.append(i)
e = x.count('a')
if e > len(x) / 2:
	print(len(x))
elif len(x) / 2 == e:
	print(int(len(x) - len(x) / (2 * e)))
elif len(x) / 2 >= e:
	print(len(x) - (len(x) - 2 * e + 1))


s = input()
hln = len(s) // 2 + (len(s) & 1)
print(len(s) if hln < s.count('a') else s.count('a') * 2 - 1)


import array
arr1 = array.array('l', [])
s = input()
l = len(s)
ll = 0
for i in range(0, l, 1):
	if s[i] == 'a':
		ll = ll + 1
p = int(ll * 2 - 1)
if p == l:
	print(l)
elif p > l:
	print(l)
else:
	print(p)


x = str(input())
s = len(x)
count_love = 0
for love in range(0, s, 1):
	if x[love] == 'a':
		count_love += 1
if count_love > s / 2:
	print(s)
else:
	print(2 * count_love - 1)


st = input()
x = st.count('a')
y = len(st) - x
while x <= y:
	y -= 1
print(x + y)


lita = input()
a = lita.count('a')
b = len(lita)
if a > b / 2:
	print(b)
else:
	print(2 * a - 1)


s = input()
ln = len(s)
cnt1 = 0
cnt2 = 0
cnt3 = 0
for i in range(0, ln):
	if s[i] == 'a':
		cnt1 += 1
	elif s[i] != 'a':
		cnt2 += 1
if cnt1 > cnt2 and cnt1 > ln / 2:
	print(ln)
elif cnt1 == cnt2:
	print(ln - 1)
else:
	while 1:
		cnt2 -= 1
		if cnt1 > cnt2:
			cnt3 = 1
			break
	if cnt3 == 1:
		print(cnt1 + cnt2)


seq = input()
maxx = 0
if seq.count('a') > len(seq) / 2:
	maxx = len(seq)
else:
	maxx = seq.count('a') * 2 - 1
print(maxx)


letters = list(input())
a = letters.count('a')
if len(letters) - a >= a:
	a += a - 1
else:
	a += len(letters) - a
print(a)


def solve():
	s = input()
	a = s.count('a')
	if a * 2 - 1 > len(s):
		print(len(s))
	else:
		print(a * 2 - 1)
solve()


w = input()
l = len(w)
a = w.count('a')
x = l - a
if a - x > 0:
	print(l)
else:
	print(l + a - x - 1)


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n
primes = []

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return int(input())
s = input()
n = len(s)
a = 0
for i in range(n):
	if s[i] == 'a':
		a += 1
o = n - a
if a >= o + 1:
	print(n)
else:
	d = o - a + 1
	print(n - d)


string = input().lower()
print(min(len(string), 2 * string.count('a') - 1))


string = input()
a_count = 0
other_count = 0
for i in range(len(string)):
	if string[i] == 'a':
		a_count += 1
	else:
		other_count += 1
removed = 0
i = 0
if other_count >= a_count:
	while other_count >= a_count:
		if string[i] != 'a':
			removed += 1
			other_count -= 1
		i += 1
	print(len(string) - removed)
else:
	print(len(string))


z = list(input())
l = len(z)
count = 0
q = 0
for i in range(l):
	if z[i] == 'a':
		count += 1
	else:
		q += 1
i = 1
if count > q:
	print(l)
else:
	while count <= q:
		if z[l - i] != 'a':
			z.remove(z[l - i])
			q = q - 1
		i += 1
	print(count + q)


import math
a = str(input())
c = a.count('a')
n = len(a) - c
l = math.ceil(len(a) / 2)
if c > n:
	print(len(a))
else:
	print(2 * c - 1)


s = input()
acount = s.count('a')
ls = len(s)
if acount > ls // 2:
	print(ls)
else:
	while acount <= ls // 2:
		ls -= 1
	print(ls)


s = input()
n = len(s)
countA = s.count('a')
if countA > n / 2:
	print(n)
else:
	print(countA * 2 - 1)


s = input()
n = s.count('a')
z = s.__len__() - n
if n <= z:
	z = z - n + 1
	print(s.__len__() - z)
else:
	print(s.__len__())


import math

def list_str(l, char):
	output_str = ''
	for i in range(len(l) - 1):
		output_str += str(l[i]) + char
	output_str += str(l[len(l) - 1])
	return output_str

def str_list(s, char):
	output_list = []
	intermediate = ''
	for i in range(len(s)):
		if s[i] != char:
			intermediate += s[i]
			if i == len(s) - 1:
				output_list.append(int(intermediate))
		elif intermediate:
			output_list.append(int(intermediate))
			intermediate = ''
	return output_list

def merge_sort(l):

	def merge(l1, l2):
		(i, j) = (0, 0)
		output_list = []
		while i < len(l1) and j < len(l2):
			if l1[i] > l2[j]:
				output_list.append(l1[i])
				i += 1
			else:
				output_list.append(l2[j])
				j += 1
		if i == len(l1):
			output_list += l2[j:]
		elif j == len(l2):
			output_list += l1[i:]
		return output_list

	def sort(l):
		if len(l) < 2:
			return l
		else:
			mid = len(l) // 2
			left = sort(l[:mid])
			right = sort(l[mid:])
			return merge(left, right)
	return sort(l)

def quicksort(l):

	def partition(l, start, end):
		i = start
		ind_pivot = end
		for j in range(start, end):
			if l[j] >= l[ind_pivot]:
				(l[j], l[i]) = (l[i], l[j])
				i += 1
		(l[ind_pivot], l[i]) = (l[i], l[ind_pivot])
		return i

	def quick_sort(l, start, end):
		if len(l) < 2:
			return l
		elif start < end:
			p = partition(l, start, end)
			quick_sort(l, start, p - 1)
			quick_sort(l, p + 1, end)
	quick_sort(l, 0, len(l) - 1)
	return l

def collector_recursive(l):
	output_list = []

	def colec(l, start, end, cl):
		if start > end:
			return cl
		else:
			cl.append(f'{l[start][1]} {l[end][1]}')
			return colec(l, start + 1, end - 1, cl)
	return colec(l, 0, len(l) - 1, output_list)

def main_function():
	s = input()
	count_a = 0
	for i in s:
		if i == 'a':
			count_a += 1
	if count_a > len(s) // 2:
		return len(s)
	return count_a * 2 - 1
print(main_function())


s = input()
a = list(s)
c = 0
b = len(s)
for i in range(b):
	if a[i] == 'a':
		c += 1
if c > b // 2:
	print(b)
else:
	print(c * 2 - 1)


s = input()
na = s.count('a')
print(min(len(s), na * 2 - 1))


s = input()
l = len(s)
ac = s.count('a')
if ac > l / 2:
	print(l)
else:
	while ac <= l / 2:
		l -= 1
	print(l)


s = input()
p = s.count('a')
if p > len(s) / 2:
	print(len(s))
elif p == len(s) / 2:
	print(len(s) - 1)
else:
	print(p * 2 - 1)


l = list(input())
c = 0
j = 0
for i in range(len(l)):
	if l[i] == 'a':
		c += 1
	else:
		j += 1
if c > j:
	print(len(l))
else:
	print(2 * c - 1)


s = list(input())
if len(s) == 1:
	print(1)
elif s.count('a') > len(s) / 2:
	print(len(s))
else:
	k = len(s)
	while s.count('a') <= k / 2:
		k -= 1
	print(k)


import random
s = input()
x = list(s)
l1 = []
l2 = []
for i in x:
	if i == 'a':
		l1.append(i)
	else:
		l2.append(i)
while len(l1) <= len(l2):
	l2.pop(random.randrange(len(l2)))
fin = len(l1) + len(l2)
print(fin)


q = input()
a = 0
noa = 0
for i in q:
	if i == 'a':
		a = a + 1
	else:
		noa = noa + 1
if noa >= a:
	print(a * 2 - 1)
else:
	print(noa + a)


n = list(map(str, input()))
c = 0
b = 0
for i in range(len(n)):
	if n[i] == 'a':
		c = c + 1
	else:
		b = 1
print(min(2 * c - 1, len(n)))


import sys
inputString = input()
aCount = 0
iCount = len(inputString)
for elem in inputString:
	if elem == 'a':
		aCount += 1
if aCount > iCount - aCount:
	print(iCount)
else:
	print(aCount * 2 - 1)


s = input()
c = s.count('a')
s = s.replace('a', '')
while c <= len(s):
	s = s[1:]
print(c + len(s))


val = input()
numA = 0
numElse = 0
for i in val:
	if i == 'a':
		numA += 1
	else:
		numElse += 1
ans = len(val)
while numElse >= numA:
	numElse -= 1
	ans -= 1
print(ans)


s = input()
a = 0
for i in s:
	if i == 'a':
		a += 1
half = len(s) // 2
if a > half:
	print(len(s))
else:
	alls = len(s)
	while a <= half:
		alls -= 1
		half = alls // 2
	print(alls)


s = input()
nba = len([k for k in s if k == 'a'])
res = nba + min(nba - 1, len(s) - nba)
print(res)


string = input()
freq = 0
l = len(string)
for i in string:
	if i == 'a':
		freq = freq + 1
if freq > l // 2:
	print(l)
else:
	print(freq * 2 - 1)


X = input()
L = list(X)
(count, count2) = (0, 0)
for i in range(len(L)):
	if L[i] == 'a':
		count += 1
	else:
		count2 += 1
if count > count2:
	print(count + count2)
else:
	print(2 * count - 1)


s = input()
k = s.count('a')
n = len(s)
while k <= n / 2:
	n -= 1
print(n)


l = list(input())
ans = l.count('a')
ln = len(l)
if ans - 1 + ans > ln:
	print(ln)
else:
	ans += ans - 1
	print(ans)


s = input()
num_a = 0
for el in s:
	if el == 'a':
		num_a += 1
res = min(len(s), num_a * 2 - 1)
print(res)


s = input()
length = len(s)
a = 0
for char in s:
	if char == 'a':
		a += 1
if length < a * 2:
	result = length
else:
	result = a * 2 - 1
if result < 0:
	result = 0
print(result)


x = list(input())
x.sort()
s = ''
for i in x:
	s += i
count = 0
for i in s:
	if i == 'a':
		count += 1
if count > int(len(s) / 2):
	print(len(s))
else:
	while count <= int(len(s) / 2):
		s = s[:len(s) - 1]
		if count > int(len(s) / 2):
			print(len(s))
			break


s = input()
counter = 0
for elem in s:
	if elem == 'a':
		counter += 1
if counter > len(s) / 2:
	print(len(s))
elif counter <= len(s) / 2:
	print(counter + (counter - 1))


a = str(input())
s = len(a)
d = 0
for i in range(s):
	if a[i] == 'a':
		d = d + 1
if s < 2 * d:
	print(int(s))
else:
	s = 2 * d - 1
	print(int(s))


s = input()
a = s.count('a')
s2 = s.replace('a', '')
other = len(s2)
if len(s) == 0:
	print(0)
elif a == 1:
	print(1)
elif a < other:
	print(len(s) - (other - a) - 1)
elif a == other:
	print(len(s) - 1)
else:
	print(len(s))


string = input()
a = string.count('a')
if a / len(string) > 0.5:
	print(str(len(string)))
else:
	print(str(2 * a - 1))


def sol(s):
	res = 0
	hash = {}
	for i in range(len(s)):
		if s[i] not in hash:
			hash[s[i]] = 1
			continue
		hash[s[i]] += 1
	not_a = len(s) - hash['a']
	res = hash['a']
	if not_a >= hash['a']:
		res += hash['a'] - 1
	else:
		res += not_a
	print(res)
s = input()
sol(s)


string = input()
n = len(string)
a = string.count('a')
if a > n // 2:
	print(n)
else:
	req = 2 * a - 1
	print(req)


s = input()
k = s.count('a')
m = len(s)
if k > m / 2:
	print(m)
else:
	print(2 * k - 1)


t = input()
print(min(len(t), t.count('a') * 2 - 1))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	s = inp()
	k = s.count('a')
	n = len(s)
	print(k + min(n - k, k - 1))
solve()


my_str = input()
a = my_str.count('a')
ans = a + a - 1
if ans > len(my_str):
	print(len(my_str))
else:
	print(ans)


import math
count = 0
s = input()
for i in range(len(s)):
	if s[i] == 'a':
		count += 1
x = int(math.ceil(len(s) / 2))
if count > x:
	print(len(s))
else:
	print(2 * count - 1)


lst = list(input())
cur = lst.count('a')
if cur > len(lst) - cur:
	print(len(lst))
else:
	print(cur * 2 - 1)


import math
s = input()
a = 0
for i in range(len(s)):
	if s[i] == 'a':
		a = a + 1
if a > math.ceil(float(len(s)) / 2):
	print(len(s))
else:
	print(2 * a - 1)


string = input()
numA = 0
length = len(string)
for x in string:
	if x == 'a':
		numA += 1
if numA > int(length):
	print(length)
else:
	rest = length - numA
	while rest >= numA:
		length -= 1
		rest -= 1
	print(length)


from collections import Counter
S = input()
C = Counter(S)
L = len(S)
A = C['a']
print(min(A * 2 - 1, L))


s = str(input())
print(min(len(s), s.count('a') * 2 - 1))


y = input()
k = 0
for i in range(len(y)):
	if y[i] == 'a':
		k = k + 1
if k > 0:
	if k > int(len(y) / 2):
		print(len(y))
	else:
		print(2 * k - 1)
else:
	print('0')


a = input()
k = b = 0
for i in range(len(a)):
	if a[i] != 'a':
		k += 1
	else:
		b += 1
while k > b or k == b:
	k -= 1
print(k + b)


s = input()
mymap = {}
for c in s:
	if c in mymap:
		mymap[c] = mymap[c] + 1
	else:
		mymap[c] = 1
total = 0
if len(mymap) > 1:
	for k in mymap:
		if k != 'a':
			total += mymap[k]
	while mymap['a'] <= (mymap['a'] + total) // 2:
		total -= 1
	print(mymap['a'] + total)
else:
	print(mymap['a'])


import sys
from functools import reduce
from collections import Counter
import time
import datetime
import math

def ip():
	return int(sys.stdin.readline())

def sip():
	return input()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def slip():
	return list(map(str, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.insert(i, arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
s = sip()
a = 0
n = 0
for item in s:
	if item == 'a':
		a += 1
	n += 1
if a > n // 2:
	print(n)
else:
	print(2 * a - 1)


string = input()
count = 0
i = 0
while string.count('a') <= len(string) / 2:
	if string[i] != 'a':
		string = string[:i] + string[i + 1:]
	else:
		i = i + 1
print(len(string))


s = input()
n = len(s)
cou = s.count('a')
if cou > n - cou:
	print(n)
else:
	print(cou + (cou - 1))


s = input()
c = s.count('a')
sc = len(s)
if c > sc / 2:
	print(sc)
else:
	d = c * 2 - 1
	print(d)


inputs = input()
a = 0
x = 0
list = []
for i in range(len(inputs)):
	list.append(inputs[i])
for i in range(len(list)):
	if list[i] == 'a':
		a += 1
	else:
		x += 1
i = 0
while a <= x:
	if list[i] != 'a':
		del list[i]
		x -= 1
	else:
		i += 1
print(a + x)


s = input()
a = len(s)
b = s.count('a') * 2 - 1
print(min(a, b))


st = input()
a = st.count('a')
b = len(st)
if a > b / 2:
	print(b)
else:
	print(2 * a - 1)


x = input()
l = []
for i in x:
	l.append(i)
l.sort()
c = 0
for i in x:
	if i == 'a':
		c += 1
while len(l) > 0:
	if c > len(l) - c:
		print(len(l))
		break
	else:
		l.pop()


s = input()
l = list(s)
c = 0
d = 0
for i in range(len(l)):
	if l[i] == 'a':
		c += 1
	else:
		d += 1
if c > d:
	print(len(l))
else:
	print(len(l) - (d - c + 1))


string = input()
counter = 0
while counter + string.count('a') < len(string) and counter < string.count('a') - 1:
	counter += 1
print(string.count('a') + counter)


string = input().strip()
length = len(string)
ctr = 0
for i in string:
	if i == 'a':
		ctr += 1
print(length if ctr > length // 2 else ctr + ctr - 1)


sen = input()
num = len(sen)
count = 0
for x in sen:
	if x == 'a':
		count += 1
if count * 2 > num:
	print('%d' % num)
else:
	print('%d' % (count * 2 - 1))


x = 0
a = 0
m = input()
fre = {}
for i in m:
	if i == 'a':
		a = a + 1
	else:
		x = x + 1
if a > len(m) / 2:
	print(a + x)
else:
	while a <= (a + x) / 2:
		x = x - 1
	print(a + x)


inp = input()
a = inp.count('a')
x = len(inp) - a * 2
if x == 0:
	print(len(inp) - 1)
	exit()
elif x == 1:
	print(len(inp) - 2)
	exit()
elif x == 2:
	print(a)
	exit()
elif len(inp) // 2 > a and a > x:
	print(x)
	exit()
elif x * 2 > a:
	print(a * 2 - 1)
else:
	print(len(inp))


def fun(str):
	counter = 0
	for c in str:
		if c == 'a':
			counter = counter + 1
	return counter
mystr = input('')
ret = fun(mystr)
if ret >= len(mystr) // 2 + 1:
	print(len(mystr))
else:
	print(len(mystr) - (len(mystr) - ret - (ret - 1)))


a = input()
s = len(a)
c = 0
for i in range(s):
	if a[i] == 'a':
		c += 1
o = s - c
if c > s // 2:
	print(s)
elif c <= s // 2:
	print(s - (o - c) - 1)


s = input()
n = s.count('a')
n_other = len(s) - n
if n > n_other:
	print(len(s))
else:
	print(len(s) - (1 + n_other - n))


a = input()
b = len(a)
count = 0
for letter in a:
	if letter == 'a':
		count = count + 1
if count == 0:
	print(count)
elif count > b / 2:
	print(b)
elif count <= b / 2:
	print(count + (count - 1))


cadena = input()
longitud = len(cadena)
totalA = 0
totalOtros = 0
for i in range(0, longitud):
	if cadena[i] == 'a':
		totalA += 1
	else:
		totalOtros += 1
while totalOtros >= totalA:
	totalOtros -= 1
nuevaLongitud = totalA + totalOtros
print(nuevaLongitud)


x = input()
l = len(x)
s = 'a'
c = x.count(s)
if c > l - c:
	print(l)
else:
	print(c + c - 1)


S = str(input())
numA = 0
numOther = 0
total = len(S)
for i in range(0, len(S)):
	if S[i] == 'a':
		numA += 1
	else:
		numOther += 1
if numOther >= numA:
	total = 2 * numA - 1
print(total)


import math
txt = list(input())
n = len(txt)
a = txt.count('a')
div = n / 2
if a > div:
	print(n)
else:
	print(a * 2 - 1)


from math import *
a = input()
coun = 0
ans = len(a)
for i in range(len(a)):
	if a[i] == 'a':
		coun += 1
if coun <= ceil(len(a) / 2):
	ans = coun + coun - 1
print(ans)


w = input()
l = len(w)
a = w.count('a')
if a / l <= 0.5:
	c = a * 2 - 1
	print(c)
else:
	print(l)


s = input()
ac = 0
ex = 0
for i in range(len(s)):
	if s[i] == 'a':
		ac += 1
	else:
		ex += 1
if ac > ex:
	print(ac + ex)
elif ac == ex:
	print(ac + ex - 1)
else:
	k = ex - ac
	ex = ex - k - 1
	print(ac + ex)


def love_a(st):
	a_s = 0
	for i in st:
		if i == 'a':
			a_s += 1
	if a_s > len(st) // 2:
		print(len(st))
	else:
		print(a_s * 2 - 1)
love_a(input().strip(' '))


s = input()
p = len(s)
q = s.count('a')
if q > p // 2:
	print(p)
elif q == 0:
	print(0)
else:
	print(min(p, q * 2 - 1))


a = input()
cnt = 0
cnt2 = 0
for i in a:
	if i == 'a':
		cnt += 1
	else:
		cnt2 += 1
p = max(0, cnt2 - cnt + 1)
print(len(a) - p)


a = str(input())
b = a.count('a')
c = len(a) // 2
if b <= c:
	d = b + (b - 1)
	print(d)
else:
	print(len(a))


s = str(input())
c_a = 0
for i in s:
	if i == 'a':
		c_a += 1
k = len(s) - c_a
if k >= c_a:
	print(2 * c_a - 1)
else:
	print(c_a + k)


s = input()
(len_s, sum) = (len(s), 0)
for i in range(0, len_s):
	if s[i] == 'a':
		sum += 1
print(min(sum * 2 - 1, len_s))


s = input()
l = []
k = []
d = []
for i in s:
	if i != 'a':
		l.append(i)
m = len(l)
e = s.count('a')
for i in range(e):
	d.append('a')
if m >= e:
	q = l[0:e - 1]
	t = len(q)
	print(e + t)
else:
	print(len(s))


(data, a_a) = (list(input().strip().lower()), 0)
for d in data:
	if d == 'a':
		a_a += 1
h_string = a_a * 2 - 1
a_string = len(data)
if h_string > a_string:
	print(a_string)
else:
	print(h_string)


s = list(input())
kol_a = 0
for b in s:
	if b == 'a':
		kol_a += 1
lenn = kol_a * 2 - 1
if len(s) > lenn:
	print(lenn)
else:
	print(len(s))


def rahul(word):
	return [char for char in word]
a = input()
b = rahul(a)
r = 0
c = 0
while r < len(b):
	if b[r] == 'a':
		c = c + 1
	r = r + 1
if c > len(b) / 2:
	print(len(b))
else:
	print(2 * c - 1)


s = input()
a = [x for x in s]
cnt = a.count('a')
if cnt > len(s) - cnt:
	print(len(s))
else:
	print(2 * cnt - 1)


ipString = input()
As = ipString.count('a')
print(2 * As - 1 if As <= len(ipString) / 2 else len(ipString))


S = input()
print(min(len(S), 2 * S.count('a') - 1))


s = input()
a = s.count('a')
d = len(s) - a
while a <= d:
	d -= 1
print(d + a)


s = input()
str = sorted(s)
count = s.count('a')
for i in range(len(str)):
	if count <= len(str) // 2:
		str.pop()
print(len(str))


n = input()
k = n.count('a')
c = k * 2 - 1
if len(n) < c:
	print(len(n))
else:
	print(c)


d = input()
print(min(len(d), 2 * d.count('a') - 1))


s = input()
a = b = 0
for i in s:
	if i == 'a':
		a += 1
	else:
		b += 1
while a <= b:
	b -= 1
print(a + b)


from collections import Counter
palabra = input()
cnt_palabra = Counter(palabra)
n = len(palabra)
if cnt_palabra['a'] > n // 2:
	print(n)
else:
	print(cnt_palabra['a'] * 2 - 1)


a = input()
b = len(a)
c = a.count('a')
print(min(b, c * 2 - 1))


a = input()
if a.count('a') > len(a) // 2:
	print(len(a))
	exit(0)
print(a.count('a') * 2 - 1)


s = input()
x = s.count('a')
y = len(s)
z = y // 2
if x > z:
	print(len(s))
else:
	print(x * 2 - 1)


s = input()
a = 0
t = 0
for i in s:
	if i == 'a':
		a += 1
	else:
		t += 1
print(a + min(a - 1, t))


x = input()
p = x.count('a')
y = 2 * p - 1
print(min(y, len(x)))


s = input()
a = ''
for i in s:
	if i == 'a':
		a += i
if len(a) > len(s) // 2:
	print(len(s))
else:
	for j in range(len(s), 0, -1):
		if len(a) * 2 > j:
			print(j)
			break


s = input()
a = s.count('a')
nona = len(s) - a
if a > nona:
	print(len(s))
else:
	while a <= nona:
		nona -= 1
	print(a + nona)


for _ in range(1):
	s = input()
	num = s.count('a')
	n = len(s)
	if num > n // 2:
		print(n)
		exit()
	d = n - num
	while num <= n // 2:
		d -= 1
		n -= 1
	print(n)


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : li(ent())
s = inp()
a = 0
for i in s:
	if i == 'a':
		a += 1
if a > len(s) / 2:
	print(len(s))
else:
	lon = len(s) - a
	while lon >= a:
		lon -= 1
	print(lon + a)


word = input()
count = 0
for c in word:
	if c == 'a':
		count += 1
if count > len(word) / 2:
	print(len(word))
else:
	print(2 * count - 1)


stringinput = input()
count = 0
checklength = len(stringinput)
for i in range(0, len(stringinput)):
	if stringinput[i] == 'a':
		count += 1
while count <= checklength / 2:
	checklength = checklength - 1
print(checklength)


def main():
	s = input()
	count = 0
	count1 = 0
	for i in s:
		if i == 'a':
			count += 1
		else:
			count1 += 1
	if count > count1:
		print(len(s))
	else:
		print(2 * count - 1)
main()


string = input()
ascount = string.count('a')
if ascount > len(string) // 2:
	res = len(string)
else:
	res = ascount * 2 - 1
print(res)


s = list(input())
na = 0
l = len(s)
for i in range(l):
	if s[i] == 'a':
		na += 1
if na <= l - na:
	k = 2 * na - 1
else:
	k = l
print(k)


s = [n for n in input()]
if s.count('a') > len(s) // 2:
	print(len(s))
else:
	print(2 * s.count('a') - 1)


def solve():
	s = input()
	print(min(len(s), 2 * s.count('a') - 1))

def __starting_point():
	solve()
__starting_point()


line = input()
print(len(line) - max(0, len(line) + 1 - line.count('a') * 2))


s = input()
n = s.count('a')
q = len(s) - n - n + 1
print(len(s) - q) if n <= len(s) - n else print(len(s))


s = input()
k = 0
while s.count('a') <= (len(s) - k) / 2:
	k += 1
print(len(s) - k)


s = input()
ls = [i for i in s]
length = len(s)
countOfA = ls.count('a')
print(min(length, 2 * countOfA - 1))


def is_good(n, n_a):
	if n_a > n / 2:
		return True
	else:
		return False
s = str(input())
n = len(s)
n_a = 0
for letter in s:
	if letter == 'a':
		n_a += 1
while True:
	if is_good(n, n_a):
		print(n)
		break
	else:
		n -= 1
		continue


ast = input()
anum = ast.count('a')
if anum > len(ast) / 2:
	print(len(ast))
else:
	print(2 * anum - 1)


string = input()
aCount = 0
elseCount = 0
for i in range(len(string)):
	if string[i] == 'a':
		aCount = aCount + 1
	else:
		elseCount = elseCount + 1
if aCount - elseCount <= 0:
	print(len(string) - (elseCount - aCount) - 1)
else:
	print(len(string))


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = input().strip()
print(min(len(n), 2 * n.count('a') - 1))


s = input()
x = 0
y = 0
for i in s:
	if i == 'a':
		x += 1
	else:
		y += 1
if x > y:
	print(x + y)
elif y >= x:
	print(x + x - 1)


s = input()
na = s.count('a')
length = len(s)
if 2 * na > length:
	print(length)
else:
	print(2 * na - 1)


st = list(input())
a = 0
for i in st:
	if i == 'a':
		a += 1
if 2 * a - 1 > len(st):
	print(len(st))
else:
	print(2 * a - 1)


s = input()
l = len(s)
ac = len(list(filter(lambda a: a == 'a', s)))
if ac > l - ac:
	print(l)
else:
	print(ac + ac - 1)


def check(s):
	x = s.count('a')
	if x > len(s) // 2:
		return True
	return False
s = list(input().strip())
s.sort(reverse=True)
ans = 0
for i in range(len(s)):
	if check(s[i:]):
		ans = max(ans, len(s[i:]))
print(ans)


a = list(input())
b = a
if a.count('a') > int(len(a)) / 2:
	print(len(a))
else:
	ak = int(a.count('a'))
	while 'a' in a:
		a.remove('a')
	while True:
		a.pop()
		if ak > int(len(a)):
			print(int(len(a)) + ak)
			break


n = input()
a = n.count('a')
st = len(n)
for i in range(st):
	if a <= st / 2:
		st -= 1
	else:
		print(st)
		break


string = input()
if string.count('a') > len(string) // 2:
	print(len(string))
else:
	string = ''.join(sorted(string))
	l = len(string)
	while not string.count('a') > l // 2:
		string = string[0:l]
		l -= 1
	print(l)


s = input()
ca = 0
for char in s:
	if char == 'a':
		ca += 1
aux = len(s.replace('a', ''))
while aux >= ca:
	aux -= 1
print(aux + ca)


s = input()
sa = s.count('a')
sb = len(s) - sa
if sa > sb:
	print(len(s))
else:
	h = sb - sa + 1
	for k in range(h):
		m = 0
		while m != len(s) - 1:
			if s[m] != 'a':
				break
			else:
				m += 1
		s = s[:m] + s[m + 1:]
	print(len(s))


s = input().strip()
su = 0
for k in range(len(s)):
	if s[k] == 'a':
		su += 1
print(min(2 * su - 1, len(s)))


s = input()
ans = len(s) - s.count('a') * 2
print(len(s) - ans - 1 if ans >= 0 else len(s))


s = str(input())
n = len(s)
countA = 0
for i in range(n):
	if s[i] == 'a':
		countA += 1
if countA > n // 2:
	print(n)
	exit(0)
else:
	print(countA + countA - 1)


s = str(input())
n = len(s)
x = s.count('a')
print(min(n, 2 * x - 1))


import math
t = input()
c = 0
for i in range(0, len(t)):
	if t[i] == 'a':
		c += 1
if c > math.ceil(len(t) / 2):
	print(len(t))
else:
	print(2 * c - 1)


s = str(input())
n = len(s)
x = s.count('a')
if x >= n // 2 + 1:
	print(n)
else:
	y = x * 2 - 1
	print(y)


import math
s = input()
cnt = s.count('a')
if cnt * 2 > len(s):
	print(len(s))
else:
	baki = len(s) - cnt
	bad = baki - cnt + 1
	print(len(s) - bad)


import os

def _f(s):
	count = 0
	for c in s:
		if c == 'a':
			count += 1
	n = len(s)
	return min(count * 2 - 1, n)

def f(s):
	return _f(s)
if os.environ.get('DEBUG', False):
	print(f"{f('xaxxxxa')} = 3")
	print(f"{f('aaabaa')} = 6")
else:
	print(f(input()))


s = input()
s_len = len(s)
a_count = s.count('a')
x = s_len - (a_count * 2 - 1)
if x > 0:
	print(s_len - x)
else:
	print(s_len)


s = input()
a = sum(map(lambda c: int(c == 'a'), s))
print(min(2 * a - 1, len(s)))


def solve(n):
	dic = {'a': 0, 'not_a': 0}
	for char in n:
		if char == 'a':
			dic['a'] += 1
		else:
			dic['not_a'] += 1
	if dic['a'] > dic['not_a']:
		return dic['a'] + dic['not_a']
	return dic['a'] * 2 - 1
n = input()
print(solve(n))


s = input()
k = 0
for i in range(len(s)):
	if s[i] == 'a':
		k += 1
if k == len(s):
	print(k)
elif len(s) - k < k:
	print(len(s))
else:
	print(k * 2 - 1)


string = list(input())
k = 0
while True:
	if string.count('a') > len(string) // 2:
		print(len(string))
		break
	else:
		for i in string:
			if i != 'a':
				string.remove(i)
				break


s = input()
(countA, countS) = (0, 0)
for S in s:
	if S == 'a':
		countA += 1
	else:
		countS += 1
res = countS - countA + 1 if countS >= countA else 0
print(countS + countA - res)


n = input()
a = n.count('a')
half = len(n) // 2
if a > half:
	print(len(n))
else:
	print(a + a - 1)


s = input()
ta = s.count('a')
tl = len(s)
if ta > tl // 2:
	print(tl)
else:
	print(2 * ta - 1)


a = input()
i = 0
c = 0
while i < len(a):
	if a[i] == 'a':
		c += 1
	i += 1
if 2 * c > len(a):
	print(len(a))
else:
	print(2 * c - 1)


s = input().strip()
acnt = s.count('a')
len = len(s)
print(min(acnt * 2 - 1, len))


string = input()
A_counter = string.count('a')
len_live = len(string) - A_counter
while A_counter <= len_live:
	len_live -= 1
print(len_live + A_counter)


def main():
	s = list(input())
	count = 0
	for i in range(len(s)):
		if s[i] == 'a':
			count += 1
	if count > int(len(s) / 2):
		print(len(s))
	else:
		print(2 * count - 1)
main()


a = input()
l = len(a)
c = a.count('a')
print(min(l, 2 * c - 1))


s = input().rstrip()
x = list(s)
f = x.count('a')
A = f * 2 - 1
if len(list(set(x))) == 1 and x[0] == 'a':
	print(len(x))
elif len(x) >= A:
	print(A)
else:
	while len(x) < A:
		A = A - 1
	print(A)


from sys import exit as sys_return
stringy = str(input())
count_a = 0
for i in stringy:
	if i == 'a':
		count_a += 1
print(len(stringy) if count_a > len(stringy) // 2 else min(count_a * 2 - 1, len(stringy)))


s = input()
numbers_a = s.count('a')
length = len(s)
numbers_a2 = 2 * numbers_a - 1
if length > numbers_a2:
	print(numbers_a2)
else:
	print(length)


def gd(s):
	if s.count('a') * 2 > len(s):
		return True
	return False
a = input()
if gd(a):
	print(len(a))
else:
	print(a.count('a') * 2 - 1)


t = input()
t = list(t)
l = len(t)
r = 2 * t.count('a') - 1
if l < r:
	print(l)
else:
	print(r)


s = input()
cnt = 0
sz = len(s)
for i in range(sz):
	cnt += s[i] == 'a'
print(min(2 * cnt - 1, len(s)))


def goodstr(st):
	st = list(st)
	c = st.count('a')
	if c > len(st) / 2:
		return len(st)
	else:
		return c * 2 - 1
st = str(input())
print(goodstr(st))


s = input()
l = []
for i in range(len(s)):
	l.append(s[i])
v = l.count('a')
y = len(l) - v
l.sort()
flag = 0
for i in range(len(l)):
	if v <= y:
		l.pop()
		y = y - 1
		flag = 1
	else:
		break
print(len(l))


n = input()
k = n.count('a')
l = len(n)
if l >= k * 2:
	print(k + (k - 1))
else:
	print(l)


n = input()
d = 0
for i in range(len(n)):
	if n[i] == 'a':
		d += 1
print(min(len(n), 2 * d - 1))


my_string = input()
number_of_a = my_string.count('a')
print(min(number_of_a + number_of_a - 1, len(my_string)), end='')


inp = input()
lenn = len(inp)
a = inp.count('a')
others = lenn - a
if a > others:
	print(lenn)
else:
	print(a + (a - 1))


import math
sch = input()
lstr = len(sch)
ca = sch.count('a')
if lstr // 2 + 1 > ca:
	print(2 * ca - 1)
else:
	print(lstr)


string = input()
chars = set(string)
count = {'a': 0, 'else': 0}
for element in string:
	if element == 'a':
		count['a'] += 1
	else:
		count['else'] += 1
if count['a'] > len(string) // 2:
	print(len(string))
else:
	print(len(string) - (count['else'] - count['a'] + 1))


s = str(input())
n = len(s)
a = s.count('a')
if a % 2 == 0:
	print(min(a * 2 - 1, n))
else:
	print(min(a * 2 - 1, n))


s = input()
c = 0
l = len(s)
for i in s:
	if i == 'a':
		c += 1
c1 = l - c
if c > l // 2:
	print(l)
else:
	while c1 >= c:
		l -= 1
		c1 -= 1
	print(l)


i = input()
c = i.count('a')
if c > len(i) / 2:
	print(len(i))
elif c <= len(i) / 2:
	print(2 * c - 1)


s = input()
z = s.count('a')
print(min(z * 2 - 1, len(s)))


store = {}
text = list(input())
count = 0
for ch in text:
	if ch == 'a':
		count += 1
length = len(text)
for i in range(len(text)):
	if count > length // 2:
		print(length)
		exit()
	else:
		length -= 1


s = input()
h_s = len(s) / 2
if s.count('a') > h_s:
	print(len(s))
else:
	print(s.count('a') + s.count('a') - 1)


import sys
sys.setrecursionlimit(2000)
from collections import Counter
from functools import reduce
s = input()
n = len(s)
c = Counter(s)
a = c['a']
v = a * 2 - 1
if n <= v:
	print(n)
else:
	print(v)


def solve(n):
	a = n.count('a')
	b = len(n)
	if a > b / 2:
		print(b)
	else:
		print(a * 2 - 1)
solve(list(input()))


x = list(input())
y = len(x)
v = x.count('a')
for i in range(y):
	if v > y // 2:
		break
	else:
		y = y - 1
		i += 1
print(len(x) - i)


s = input()
x = []
for i in range(0, len(s)):
	x.append(s[i])
if 2 * x.count('a') > len(s):
	print(len(s))
else:
	print(2 * x.count('a') - 1)


x = input()
y = x.count('a')
if len(x) < 2 * y:
	print(len(x))
else:
	print(2 * y - 1)


string = input()
As = string.count('a')
if As > len(string) // 2:
	print(len(string))
else:
	print(2 * As - 1)


text = input()
count = 0
for ch in text:
	if ch == 'a':
		count += 1
length = len(text) // 2 + 1
if count >= length:
	print(len(text))
else:
	print(2 * count - 1)


s = input()
n = len(s)
num_a = 0
for i in s:
	if i == 'a':
		num_a += 1
dif = n - num_a
if dif < num_a:
	print(n)
else:
	print(2 * num_a - 1)


s = input()
counter_a = 0
counter_else = 0
for i in s:
	if 'a' == i:
		counter_a += 1
	else:
		counter_else += 1
s_len = len(s)
while counter_a <= counter_else:
	s_len -= 1
	counter_else -= 1
print(s_len)


s = input()
(nota, yesa) = (0, 0)
l = [i for i in s]
if l.count('a') > len(l) // 2:
	print(len(l))
else:
	for i in range(len(l)):
		if l[i] != 'a':
			nota += 1
		else:
			yesa += 1
	diff = nota - yesa
	print(nota + yesa - diff - 1)


s = input()
a = s.count('a')
n = len(s) - a
print(len(s) - (0 if a > n else n - a + 1))


s = input()
ls = len(s)
cnt = s.count('a')
if cnt > ls / 2:
	print(ls)
else:
	print(cnt * 2 - 1)


import math
count = 0
newstr = input()
for i in newstr:
	if i == 'a':
		count = count + 1
k = len(newstr)
if count > k - count:
	print(k)
elif count == k - count:
	print(k - 1)
else:
	print(2 * count - 1)


t = input()
y = str(t).count('a')
z = len(t) // 2
print(min(len(t), y * 2 - 1))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	s = S()
	c = s.count('a')
	if c > len(s) // 2:
		return len(s)
	return c * 2 - 1
print(main())


def like_a(s):
	n = s.count('a')
	if n > len(s) // 2:
		return len(s)
	return 2 * n - 1
print(like_a(input()))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
s = stringIn()
di = {}
for ch in s:
	if ch not in di:
		di[ch] = 1
	else:
		di[ch] += 1
cnta = di['a']
for i in range(len(s), -1, -1):
	if cnta > i // 2:
		break
print(i)


word = input()
z = word.count('a')
ans = 0
while z * 2 <= len(word) - ans:
	ans += 1
print(len(word) - ans)


_x = input()
_count = _x.count('a')
print(_count + _count - 1 if _count <= len(_x) // 2 else len(_x))


string = input()
length = len(string)
noa = 0
for i in string:
	if i == 'a':
		noa += 1
while length / 2 >= noa:
	length -= 1
print(length)


s = list(input())
count = 0
e_count = 0
for i in range(len(s)):
	if s[i] == 'a':
		count += 1
	else:
		e_count += 1
if count > e_count:
	print(count + e_count)
elif count == e_count:
	print(count + e_count - 1)
else:
	while True:
		e_count -= 1
		if count > e_count:
			break
	print(e_count + count)


def getLength(ambigiousStr):
	aCount = 0
	for i in range(0, len(ambigiousStr)):
		if ambigiousStr[i] == 'a':
			aCount += 1
	halfLen = int(len(ambigiousStr) / 2)
	if aCount > halfLen:
		return len(ambigiousStr)
	else:
		return aCount + aCount - 1

def main():
	ambigiousStr = input()
	print(getLength(ambigiousStr))
main()


from sys import stdin
input = stdin.readline
from collections import Counter
s = input().strip()
c = Counter(s)['a']
res = min(len(s), c * 2 - 1)
print(res)


s = str(input())
l = []
l1 = []
for i in range(0, len(s)):
	if s[i] == 'a':
		l.append(s[i])
	else:
		l1.append(s[i])
count = len(l)
sount = len(l1)
f = len(s) // 2 + 1
if count > sount:
	print(len(s))
else:
	print(len(s) - (sount - count + 1))


string = input().lower()
ideal_a = int(len(string) / 2) + 1
while string.count('a') < ideal_a:
	string = list(string)
	string.sort()
	del string[-1]
	string = ''.join(string)
	ideal_a = int(len(string) / 2) + 1
print(len(string))


st = input()
a = st.count('a')
length = len(st)
if a > length / 2:
	print(length)
else:
	print(2 * a - 1)


s = input()
a = 'a'
count_of_a = s.count(a)
count = len(s)
if count_of_a > count / 2:
	print(count)
else:
	while count_of_a <= count / 2:
		count -= 1
	print(count)


x = input()
c = 0
c1 = 0
for i in x:
	if i == 'a':
		c = c + 1
	else:
		c1 = c1 + 1
if c > c1:
	print(len(x))
else:
	print(c - 1 + c)


na = 0
n = input()
for i in n:
	if i == 'a':
		na += 1
if na > len(n) / 2:
	ans = len(n)
else:
	ans = na + na - 1
print(ans)


string = input()
a = int()
for x in string:
	if x == 'a':
		a += 1
if a > len(string) / 2:
	print(len(string))
else:
	print(a * 2 - 1)


from collections import Counter
s = input()
s_counter = Counter(s)
n_as = s_counter['a']
ans = min(n_as * 2 - 1 if n_as > 0 else 0, len(s))
print(ans)


from collections import Counter

def solution():
	word = input()
	n = len(word)
	cnt_a = Counter(word)['a']
	if 2 * cnt_a > n:
		print(n)
	else:
		print(2 * cnt_a - 1)
solution()


s = input()
count = s.count('a')
n = len(s)
ans = n
while count / ans <= 0.5:
	ans -= 1
print(ans)


awd = input()
hitungA = 0
for i in awd:
	if i == 'a':
		hitungA = hitungA + 1
if hitungA > len(awd) // 2:
	print(len(awd))
else:
	print(hitungA * 2 - 1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = 1
	rr = []
	for _ in range(t):
		s = S()
		c = collections.Counter(s)
		rr.append(min(c['a'] * 2 - 1, len(s)))
	return JA(rr, '\n')
print(main())


i = list(input())
a = i.count('a')
print(2 * a - 1 if not a - 1 > len(i) - a else len(i))


s = input()
D = {}
for i in s:
	if i not in D:
		D[i] = 1
	else:
		D[i] += 1
n = len(s)
while D['a'] <= n / 2:
	n = n - 1
print(n)


st = list(input())
stc = ''.join(st)
ca = 0
for i in st:
	if i == 'a':
		ca += 1
if ca > len(stc) // 2:
	print(len(stc))
else:
	print(ca * 2 - 1)


import sys
from collections import Counter
fin = sys.stdin
fout = sys.stdout
lines = (line.strip() for line in fin)
letters = next(lines)
n = len(letters)
counter = Counter(letters)
a_count = counter['a']
if a_count > n // 2:
	answer = n
else:
	answer = 2 * a_count - 1
print(answer, file=fout)


s = input()
length = len(s)
counter = 0
answer = 0
for z in s:
	if z == 'a':
		counter += 1
while True:
	if counter <= 0:
		print(0)
		break
	if counter > length - answer - counter:
		print(length - answer)
		break
	else:
		answer += 1


s = str(input())
a = s.count('a')
nota = 0
l = len(s)
for x in range(l):
	if s[x] != 'a':
		nota += 1
while a <= nota:
	nota -= 1
	l -= 1
print(l)


s = input().strip()
ca = s.count('a')
if ca > len(s) // 2:
	print(len(s))
else:
	x = len(s) - ca
	r = x - ca + 1
	l = len(s) - r
	print(l)


n = input()
n = list(n)
z = 0
for i in range(len(n)):
	if n[i] == 'a':
		z = z + 1
if z >= len(n) // 2 + 1:
	print(len(n))
else:
	print(z + z - 1)


s = input().lower()
a_c = s.count('a')
if a_c > len(s) // 2:
	print(len(s))
else:
	print(2 * a_c - 1)


x = input()
m = x.count('a')
if m > len(x) / 2:
	print(len(x))
else:
	print(2 * m - 1)


a = sorted(input())
b = a.count('a')
c = len(a)
while b <= c - b:
	c = c - 1
print(c)


s = list(input())
a = s.count('a')
n = len(s)
if a > n / 2:
	print(n)
else:
	print(a * 2 - 1)


s = input()
aq = s.count('a')
if aq > len(s) - aq:
	print(len(s))
else:
	print(aq + aq - 1)


data = list(input())
length = len(data)
apple = data.count('a')
if apple > 0.5 * length:
	print(length)
elif apple <= 0.5 * length:
	new_length = apple * 1.960784314
	print(int(new_length))


s = input()
az = 0
for i in s:
	if i == 'a':
		az += 1
if az > len(s) / 2:
	print(len(s))
else:
	fin = len(s)
	for i in s:
		if i != 'a' and az <= fin / 2:
			fin -= 1
	print(fin)


import sys
st = input()
s = 0
for i in range(0, len(st)):
	if st[i] == 'a':
		s += 1
n = len(st)
if n > s * 2 - 1:
	print(s * 2 - 1)
else:
	print(n)


string = input()
totalChars = len(string)
count = 0
for char in string:
	if char == 'a':
		count += 1
difference = totalChars - count
answer = totalChars
if difference >= count:
	toSubtract = difference - count + 1
	answer = totalChars - toSubtract
print(answer)


import collections
t = input()
t = list(t)
d = collections.Counter(t)
vala = d['a']
d.pop('a')
sumo = sum(d.values())
if vala > sumo:
	print(vala + sumo)
else:
	print(2 * vala - 1)


s = input()
n_a = 0
n_x = 0
for element in s:
	if element == 'a':
		n_a = n_a + 1
print(min(2 * n_a - 1, len(s)))


string = str(input())
new = []
for i in string:
	new.append(i)
m = 0
n = 0
for i in new:
	if i == 'a':
		m = m + 1
	else:
		n = n + 1
print(min(m + n, 2 * m - 1))


v = input()
n = len(v)
half = n // 2 + 1
dicts = {}
for i in v:
	if i not in dicts:
		dicts[i] = 1
	else:
		dicts[i] += 1
if 'a' not in dicts:
	print(n)
elif dicts['a'] >= half:
	print(n)
else:
	others = n - dicts['a']
	aa = dicts['a'] * 2 - 1 - dicts['a']
	kk = others - aa
	ans = max(n - kk, 0)
	print(ans)


s = input()
a = s.count('a')
if a == 1:
	print(1)
elif a > len(s) - a:
	print(len(s))
else:
	print(a + a - 1)


s = input()
num = s.count('a')
n = len(s)
if num > n // 2:
	print(n)
	exit()
d = n - num
while num <= n // 2:
	d -= 1
	n -= 1
print(n)


s = input()
a = 0
for c in s:
	if c == 'a':
		a += 1
na = len(s) - a
if a > na:
	print(len(s))
elif a == na:
	print(len(s) - 1)
else:
	print(len(s) - (na - (a - 1)))


text = input()
As = text.count('a')
non_As = len(text) - As
if As > non_As:
	print(len(text))
else:
	print(As + As - 1)


from sys import stdin, stdout
txt = stdin.readline().strip()
a_count = txt.count('a')
other_count = len(txt) - a_count
most_a_allowed = a_count - 1
if other_count < a_count:
	stdout.write('%d\n' % len(txt))
else:
	stdout.write('%d\n' % (most_a_allowed + a_count))


s = list(input())
c = s.count('a')
n = len(s)
if c > len(s) // 2:
	print(len(s))
else:
	while True:
		if c > n // 2:
			print(n)
			break
		else:
			n -= 1


a = input()
k1 = 0
k2 = 0
for i in range(0, len(a)):
	if a[i] == 'a':
		k1 += 1
	else:
		k2 += 1
print(len(a) - max(0, k2 - k1 + 1))


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
chrs = RW()
acnt = chrs.count('a')
print(min(len(chrs), 2 * acnt - 1))


x = input()
z = len(x)
s = 0
for i in x:
	if i == 'a':
		s = s + 1
if s <= z / 2:
	print(s + (s - 1))
else:
	print(z)


x = input()
if x.count('a') > len(x) - x.count('a'):
	print(len(x))
elif x.count('a') == 0:
	print(0)
else:
	print(x.count('a') * 2 - 1)


stringa = input()
count = 0
for i in stringa:
	if i == 'a':
		count += 1
n = len(stringa)
ans = min(2 * count - 1, n)
print(ans)


s = input()
a = 0
b = 0
for i in range(0, len(s)):
	if s[i] == 'a':
		a += 1
	else:
		b += 1
while b != 0 and a <= (a + b) / 2:
	b -= 1
print(a + b)


from collections import Counter
S = input()
SC = Counter(S)
a = SC['a']
print(min(len(S), 2 * a - 1))


from sys import stdin
inp = stdin.readline
s = inp().strip()
print(min(s.count('a') * 2 - 1, len(s)))


import sys
from collections import *
from math import *
import re

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	c = 0
	for i in range(2, n):
		if prime[i]:
			c += 1
	return c

def iseven(n):
	return [False, True][0 if n % 2 else 1]

def inp_arr():
	return list(map(int, input().split()))

def inp():
	return map(int, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)
max_int = sys.maxsize
mod = 10 ** 9 + 7
s = input()
count = sum([1 for i in s if i == 'a'])
print(len(s) if count > len(s) // 2 else 2 * count - 1)


line = input()
counter = 0
for i in line:
	if i == 'a':
		counter += 1
x = counter
x = x * 2
x -= 1
if x >= len(line):
	print(len(line))
else:
	print(x)


from collections import Counter
from bisect import bisect_right
s = str(input())
s = list(s)
s.sort()
n = len(s)
i = bisect_right(s, 'a')
print(min(2 * i - 1, n))


s = str(input())
l = len(s)
x = s.count('a')
ans = 0
for i in range(1, len(s) + 1):
	if x > l // 2:
		print(l)
		exit(0)
	else:
		l -= 1


def GoodString(Str):
	A = []
	for letter in Str:
		A.append(letter)
	A.sort()
	counter = 0
	delete = len(A)
	for letter in A:
		if letter == 'a':
			counter += 1
		else:
			break
	while counter <= delete - counter:
		delete -= 1
	print(delete)
Str = input()
GoodString(Str)


A = input()
B = len(A)
count = 0
for i in A:
	if i == 'a':
		count = count + 1
if count <= B / 2:
	print(2 * count - 1)
else:
	print(len(A))


def LoveA(s):
	a_s = s.count('a')
	rest = len(s) - a_s
	print(len(s) - max(0, rest - a_s + 1), end='')
LoveA(str(input()))


s = input()
cnt = 0
for i in s:
	if i == 'a':
		cnt += 1
for i in range(len(s)):
	if cnt > (len(s) - i) / 2:
		print(len(s) - i)
		break


s = input()
n = len(s)
num_of_a = res = 0
for ch in s:
	if ch == 'a':
		num_of_a = num_of_a + 1
if num_of_a > n / 2:
	res = n
else:
	res = num_of_a + num_of_a - 1
print(res)


from sys import stdin
import math
from copy import deepcopy
from collections import defaultdict

def get_freq(string):
	count = 0
	for i in string:
		if i == 'a':
			count += 1
	return count
string = list(stdin.readline().strip())
freq_a = get_freq(string)
if freq_a > len(string) // 2:
	print(len(string))
else:
	print(freq_a * 2 - 1)


str = input()
counter = str.count('a')
totala = counter
leng = len(str)
if leng / 2 < counter:
	print(leng)
else:
	lastchar = str[0]
	newstr = lastchar
	for i in range(1, leng, 1):
		c = str[i]
		if c == 'a':
			newstr += 'a'
			totala -= 1
		elif lastchar == 'a':
			newstr += c
		elif totala > 0:
			newstr += c
			totala -= 1
		lastchar = c
	l = len(newstr)
	if l < counter * 2:
		print(l)
		print(newstr)
	else:
		print(counter * 2 - 1)


n = list((x for x in input()))
v = n.count('a')
a = len(n) - v
if v > a:
	print(len(n))
elif v == a:
	print(len(n) - 1)
else:
	print(len(n) - (a - v + 1))


s = str(input())
s1 = list(s)
k = len(s1)
if k % 2 == 0:
	f = 1
	g = k // 2
else:
	f = 0
	g = k // 2 + 1
if f == 1 and s1.count('a') > g:
	print(k)
elif s1.count('a') <= g and f == 1:
	print(2 * s1.count('a') - 1)
elif f == 0 and s1.count('a') >= g:
	print(k)
elif s1.count('a') < g and f == 0:
	print(2 * s1.count('a') - 1)


s = input()
count_a = s.count('a')
letter_count = 0
if count_a > len(s) / 2:
	print(len(s))
elif count_a <= len(s) / 2:
	for i in range(len(s)):
		if s[i] != 'a':
			letter_count += 1
	while letter_count >= count_a:
		if count_a <= letter_count:
			letter_count -= 1
	output = count_a + letter_count
	print(output)


txt = str(input())
i = len(txt)
j = 0
a = 0
x = 0
while j < i:
	if txt[j] == 'a':
		a += 1
		j += 1
	else:
		x += 1
		j += 1
if x > a:
	print(i - (x - a) - 1)
elif x == a:
	print(i - 1)
else:
	print(i)


s = str(input())
count = s.count('a')
i = 0
while count <= len(s) / 2:
	if s[i] != 'a':
		s = s[:i] + s[i + 1:]
	else:
		i += 1
print(len(s))


s = input()
n = s.count('a')
e = len(s)
if n > e // 2:
	print(e)
else:
	print(n + n - 1)


s = input()
n = len(s)
x = s.count('a')
if x > n // 2:
	ans = n
else:
	ans = 2 * x - 1
print(ans)


a = input()
b = sum([1 for i in a if i == 'a'])
c = len(a)
if b > c / 2:
	print(c)
else:
	print(2 * b - 1)


s = input()
length = len(s)
if s.count('a') > length / 2:
	print(length)
else:
	i = 0
	while s.count('a') <= len(s) / 2:
		if s[i] != 'a':
			s = s.replace(s[i], '', 1)
		else:
			i += 1
	print(len(s))


s = input()
(count, other) = (0, 0)
for i in s:
	if i == 'a':
		count += 1
	else:
		other += 1
if count > other:
	print(len(s))
else:
	while count <= other:
		other -= 1
	print(other + count)


word = input()
temporarily = list(word)
char_a = 0
for i in range(len(temporarily)):
	if temporarily[i] == 'a':
		char_a += 1
if char_a > len(temporarily) / 2:
	print(len(temporarily))
elif char_a == len(temporarily) / 2:
	print(len(temporarily) - 1)
else:
	print(char_a + (char_a - 1))


s = input()
arrayA = []
arrayX = []
for i in s:
	if i == 'a':
		arrayA.append(i)
	else:
		arrayX.append(i)
if len(arrayA) > len(arrayX):
	print(len(arrayA) + len(arrayX))
else:
	print(len(arrayA) + (len(arrayX) - (len(arrayX) - len(arrayA) + 1)))


s = list(input())
while s.count('a') / len(s) <= 0.5:
	for c in s:
		if c != 'a':
			s.remove(c)
			break
print(len(s))


st = input()
cou = st.count('a')
if cou > len(st) / 2:
	print(len(st))
else:
	print(2 * cou - 1)