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

s=input()

n=len(s)

ac = 0;

for i in range(0,n):

    if s[i] == 'a':
        ac+=1

while True:

    m = int(n / 2) + 1
    if(ac >= m):
        break
    n-=1

print(n)

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))

###################################################################
# Class Definition.
class LoveA:
    # Method to compute 'Good' String of Maximum length.
    def computeLengthForGoodString(self):
        countA,countB = self.obtainCounts();length = len(self.string)
        # Determining Required Length.
        index = 0
        while(countA<=length/2 and index<len(self.string)):
            if self.string[index] != LoveA.characterA:
                length = length - 1
            index = index + 1
        return length
    # Method to Count A's and non A's.
    def obtainCounts(self):
        aCount = self.string.count(LoveA.characterA)
        return [aCount,len(self.string)-aCount]
    # Soluttion.
    def Solution(self):
        return self.computeLengthForGoodString()
    # Constructor.
    def __init__(self,string):
        self.string = string
    # Class for Storing Character A.
    characterA = 'a'
###################################################################
# Driver Program.
newObject = LoveA(raw_input())
print newObject.Solution()
###################################################################

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

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

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

s=raw_input()

count=0
count1=0

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

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

s = raw_input()
a = 0
b = 0
for i in s:
    if i == 'a':
        a+=1
    else:
        b+=1

if a>b:
    print len(s)
else:
    print a+a-1

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 = input()
print(min(len(s),2*s.count('a')-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)

# your code goes here
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))

# -*- coding: utf-8 -*-
import sys
from fractions import gcd
def fi():
    return int(sys.stdin.readline())

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

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

def fo(*args):
    for s in args:
        sys.stdout.write(str(s)+' ')
    sys.stdout.write('\n')
INF=10**9+7
sys.setrecursionlimit(INF)

#main
s=raw_input()
count=0
for i in s:
    if i=="a":
        count+=1
if count>len(s)/2:
    fo(len(s))
else:
    fo(count*2-1)

#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__

    str = lambda x=b"": x if type(x) is bytes else __str__(x).encode()

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
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    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)

sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", b" "), 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", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()

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

if __name__ == "__main__":
    main()

import sys
sys.setrecursionlimit(10 ** 6)
# pow(3,2,5)==4

s=raw_input()

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

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

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

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

s = raw_input()

a = s.count('a')

print min(len(s), a * 2 - 1)

'''input
aaabaa

'''

RI = lambda : [int(x) for x in raw_input().split()]
rw = lambda : raw_input().strip()
mod  = 10**9+7

s = rw()
no = s.count("a")
print min(len(s),2*no-1)

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

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

s=input()
n=len(s)
count_a=s.count('a')

if(count_a>(n/2)):
	print(n)
else:
	print(count_a*2-1)

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())

s=list(input())
c=s.count("a")
#print(len(s))
#print(c)
n=len(s)
if(c>len(s)//2):
    print(len(s))

else:
    while(True):
        if(c>n//2):
            print(n)
            break
        else:
            n-=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)

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

if __name__ == "__main__":
    solve()

# ~*~ coding: utf-8 ~*~

s = raw_input()
count_a = s.count("a")
print min(len(s), count_a + (count_a - 1))
#минимальное значение между длиной текста и количеством букв а. Функции min, count и len
# функция len - глобальная и пишется через (), а не "точку".

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=raw_input()
n=len(s)
a=sum(k=='a' for k in s)
print(min(n,2*a-1))

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()
ca = s.count('a')
cv = len(s)
if ca >= cv // 2 + 1:
    print(cv)
else:
    print(ca * 2 - 1)

S = raw_input().strip()
n = len(S)
a = len([c for c in S if c == 'a'])
while a * 2 <= n:
	n -= 1
print n

s = input()
l = len(s)
c=0

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

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)

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

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()
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))

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

while a < len(s)//2+1:
  for i in range(0,len(s)):
    if s[i] >= 'b' and s[i] <= 'z':
      s = s[:i] + s[i+1:]
      break;

print(len(s))

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()

temp=s.count('a')

if temp*2>len(s):
     print(len(s))
else:
     print((2*temp)-1)

a = input()
count = 0
for i in range (len(a)):
    if (a[i] == 'a'):
        count+=1
if (count>len(a)//2):
    print(len(a))
else:
    print((2*count)-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)

s=input()
n=0
for i in range(0,len(s)) :
    if s[i] == "a" :
        n=n+1
if(n==len(s)):
    print(n)
elif (n> (len(s)/2)):
         print(len(s))
else:
    print(2*n-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()
acount = s.count('a')
if( acount <= (len(s) /2) ):
	print((2*acount) - 1)
else:
	print(len(s))
# print(len(s) - deslength)

str = input()
x = str.count("a")
y = len(str)-x
c = 0
if x>y:
    print(len(str))
elif x==y:
    print(len(str)-1)
else:
    while(True):
        y-=1
        if x>y:
            c = 1
            break
if c==1:
    print(x+y)

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)

# A. Love "A"

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)

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))

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 = input()
aCnt = 0
for idx in s:
    if(idx == 'a'):
        aCnt += 1

if(aCnt > len(s)/2):
    print(len(s))
else:
    print(aCnt * 2 - 1)

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

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)

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

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)

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

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)
else:
  if c >= (n//2)+1:
    print(n)
  else:
    print((2*c)-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)

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

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)

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

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

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 = input()
if(len(s)%2==0):
    if(s.count('a')>len(s)//2):
        print(len(s))
    else:
        print((2*s.count('a')-1))
else:
    if(s.count('a')>len(s)//2):
        print(len(s))
    else:
        print((2*s.count('a')-1))

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

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

#tt = int(input())

#while tt:
    #tt -= 1
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)

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

#!/usr/bin/env python

from sys import stdin, stderr

def main():
   S = stdin.readline().strip()
   cnta = len( [1 for c in S if c == 'a'] )
   N = len(S)

   while cnta*2 <= N:
      N -= 1
   print(N)

   return 0

if __name__ == '__main__': main()

s = input()

a, other = 0, 0
for c in s:
    if c == 'a':
        a += 1
    else:
        other += 1

if a > other:
    print(len(s))
else:
    print(len(s) - (other - (a - 1)))

s = raw_input().strip()
c = s.count('a')
l = len(s)
for i in xrange(l):
    if c > l - i - c:
        print l - i
        break

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

#https://codeforces.com/contest/1146/problem/0

s=raw_input()
l=len(s)
a=s.count("a")
tar=(l/2)+1
if a>=tar:
    print l
else:
    if a==1:
        print 1
    else:
        print (a*2)-1

s = raw_input()

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

import sys
input = sys.stdin.readline

cute = input().strip()

cutes = cute.count("a")
uncutes = len(cute) - cutes

if (cutes == 0):
  print(0)
else:
  print(len(cute) - max(uncutes - cutes + 1, 0))

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

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

s = raw_input()
n = len(s)
c = s.count('a')
print min(n, c+c-1)

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

s = raw_input()
n1 = len(s)
n2 =s.count('a')
print min(n1,n2*2-1)

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

s = [i for i in input()]
# print (s)
count = 0
for i in s:
  if i == 'a':
    count += 1
# print (count)
if count > len(s) / 2:
  print (len(s))
else:
  if count + 2 < len(s):
    count1 = count + 2
  print (max(count + 1 , count +2 ))

n=str(input())
s=list(n)
g = s.count('a')
f=len(s)-g
if (f-1)-g==0:
    print(len(s)-2)
elif f<g:
    print(len(s))
elif f==g:
    print(len(s)-1)
else:
    print(f-g)

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
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):

    # Create a boolean array "prime[0..n]" and initialize
    #  all entries it as true. A value in prime[i] will
    # finally be false if i is Not a prime, else true.
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):

        # If prime[p] is not changed, then it is a prime
        if (prime[p] == True):

            # Update all multiples of p
            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

if __name__ == '__main__':
	s=str(input())
	c1=0
	for i in range(len(s)):
		if(s[i:i+1]=="a"):
			c1+=1
	if(c1>len(s)//2):
		print(len(s))
	else:
		print(c1+1)

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

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

a = input()
sum = 0
list = list(a)

for i in range(len(a)):
    if 'a' in list[i]:
        sum += 1

if len(a) // 2 < sum:
    print(sum + 1)
elif len(a) // 2 == sum:
    print(len(a) - 1)
else:
    print((len(a) - sum) - sum)

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

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(k)
else:
    print(k*2-1)

s = input()
n = 0
n = s.count('a')
print(n+1)

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

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

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

s=input()
l=list(s)
c=[]
for i in range(len(l)):
    if(l[i]=='a'):
        coun=0
        for j in range(i+1,len(l)):
            if(l[j]=='x'):
                coun+=1
        c.append(coun)
d=max(c)
print(len(l)-d)

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 len(inp)//2>a:
    print(x)
    exit()
else:
    print(len(inp))

import sys
import math
str = input()
c = str.count("a")
l = len(str)

if c >= math.ceil(l / 2):

    print(l)
else:
    print((c * 2) - 1)

str = input()
c=str.count("a")
l=len(str)
if l==1:
	print(l)
if c>l//2:
    print(l)
else:
    print((c*2)-1)

string = input()
occurences = 0
for char in string:
    if char == 'a':
        occurences += 1

print(occurences)
difference = len(string) - occurences
print(difference)
print(len(string))
if difference > occurences:
    print(len(string) - difference + 1)
elif difference == occurences:
    print(len(string) - 1)
else:
    print(len(string))

s = input()
n = len(s)

count = 0
for i in range(n):
    if s[i] == 'a':
        count += 1

if count > n//2:
    print (n)
elif count == n//2:
    print (2*count-1)
else:
    if count > 1:
        print (count + 1)
    else:
        print (count)

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

s = input()
ans = 0
oth = 0
for i in s:
    if i == "a":
        ans += 1
    else:
        oth += 1
if (ans > oth):
    print(len(s))
elif (ans == oth):
    print(len(s)-1)
else:
    print(ans+1)

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

s = input()
l = len(s)
c=0

for i in range(l):
    if s[i]=='a':
        c = c+1
cnt = c+1
if c>l/2 :
    print(l)
else:
    print(cnt)

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

s = input()
k = s.count('a')
m = len(s) - k
if(m < k):
    print(len(s))
else:
    print(m-k)

s=input()
count=0
i=0
if s[0] == "a":
    count = count + 1
    i=i+1

while i<len(s):
    if s[i]=="a":
        count=count+1
        i=i+1

    else:
        if(i!=0 and i!=len(s)-1):
            if(s[i+1]=="a"):
                count=count+1
            i = i + 1
        else:
            i=i+1

print(count)

s = input()
L = len(s)
nA = L - s.count("a")
if L%2 == 0:
    h = int(L/2)
else:
    h = int(L/2) +1
if nA != 0:
    print(L - nA + 1)
elif s.count("a") > h and nA == 0:
    print(L)

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

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

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(c+b)

s = input()
a = s.count('a')
b = len(s)//2
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)

s = input()
n = len(s)

count = 0
for i in range(n):
    if s[i] == 'a':
        count += 1

if count > n//2:
    print (n)
else:
    print (count + 1)

x=input()
count=0
y=len(x)//2
for i in range (len(x)):
    if x[i]=='a':
        count=count+1
if count>(y):
    print(y*2)
elif count==y:
    print((y*2)-1)
else:
    print((2*y)-count-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(b-a)

s = input()
ans = 0
oth = 0
for i in s:
    if i == "a":
        ans += 1
    oth += 1
if (ans > oth):
    print(len(s))
else:
    print(ans+1)

s = input()
n = 0
n = s.count('a')
print(n+1)

string = input()
count = 0
for x in string:
    if x == "a":
        count += 1
print(count + 1)

a=input()
g=a.count('a')
h=len(a)
f=h
cnt=0
if h%2!=0 and g<h//2+1:
  while g<h//2+1:
    h=h-1
    cnt+=1
  print(f-cnt)
elif h%2==0 and g<h//2:
  while g<h//2:
    h=h-1
    cnt+=1
  print(f-cnt)
else:
  print(h)

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

def count(arr):
    m=0
    for i in range(len(arr)):
        if arr[i]=='a':
            m=m+1
    return m

s = input()
arr=[]
for i in range(len(s)):
    arr.append(s[i])

arr.sort()
b=True
m=0
cc=count(arr)

if count(arr)<len(arr)-count(arr):
    while b:
        if cc<int(len(arr)/2):
            del arr[-1]
            m=m+1
        else:
            break
    print(m+1)
else:
    print(len(s))

# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

s=input()
c=s.count('a')
print(c+1)

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

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

for c in range(1,26):
  ch = chr(c + 97)
  k = 0
  for i in range(0,len(s)):
    if ch == s[i]:
      k += 1
  #print(ch,k)
  if(k > a):
    cnt += abs(k-(a-1))

print(len(s)-cnt)

def ret():
    st = input()
    count  = 0
    lenSt = len(st)

    for i in range(lenSt):
        if st[i] == 'a':
            count += 1
    if count > lenSt//2:
        return lenSt
    else:
        availabeOthers = lenSt - count
        needed = (lenSt // 2)
        return needed
print(ret())

import sys
input = sys.stdin.readline

cute = input().strip()

uncutes = cute.count("x")
cutes = cute.count("a")

if (cutes == 0):
  print(0)
else:
  print(len(cute) - max(uncutes - cutes + 1, 0))

s = input()
b = s
c = 0
d = []
for item in b:
    d.append(item)
    if (item == "a"):
        c = c + 1
if (c > (len(b)//2)):
    print(len(b))
else:
    for objects in d:
        if (objects != "a"):
            d.remove(objects)
            if (c > (len(d)//2)):
                break
    print(len(d))

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)

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

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

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:
    print(cnt2-cnt1)

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

s=input()
a= len(s)
count =0
new=""
for i in range(len(s)):
    if s[i]=="a":
       new = new + "a"
    else:
        new = new +" "
k=new.index("a")
t=new[k::]
g=""
for i in t:
    if i=="a":
        g=g+i

print(len(g)+1)

a=input()
#b=len(a)
c=a.count('a')
if c==len(a):
  print(len(a))

elif c==(len(a))/2:
  print(len(a)-1)
else:
  print(c+1)

from math import ceil as c
s = input()
print(len(s) if s.count('a') > int(len(s) / 2) else c((len(s) - s.count('a')) / 2))

def solve():
    s = input()
    a = s.count("a")
    print(a+1)

if __name__ == "__main__":
    solve()

arr = input()

a = arr.count('a')

tot = len(arr)

rem = tot - a

rm = 0

if(rem>a):
	print(tot-rem+1)

elif(rem==a):
	print(tot-1)

elif(a>rem):
	print(tot)

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

z = input()
x = []
l = []
for y in range(len(z)):
    x.append(z[y])
a = 0
b = 0
c = 0

for d in x:
    if d == "a":
        a+=1
    if d != "a":
        l.append(d)
l.sort()
for x in l:
    if x == l[0]:
        b+=1
    else:
        c = c+1
if b>a:
    if c > 1:
        print(2*a-c)
    else:
        print(2*a-1)
else:
    print(a+b)

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

for c in range(1,26):
  ch = chr(c + 97)
  k = 0
  for i in range(0,len(s)):
    if ch == s[i]:
      k += 1
  #print(ch,k)
  if(k > a):
    cnt += abs(k-a+1)

print(len(s)-cnt)

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

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

n = input()

c = n.count('a')

if c == len(n):
    print(c)
else:
    print(c + 1)

g=input()
h=len(g)
c=0
d=0
l=[]
for x in range(h):
	if g[x]=='a':
		c+=1
	elif g[x]!='a':
		d+=1
	l.append(g[x])
for x in l:
	while(d>=c):
		if x != 'a':
			l.remove(x)
		d-=1
v=0
for x in l:
	v+=1
print(v)

s=input()
st=list(s)
siz=len(st)
lock =0
cnt=0
for i in range(siz):
    if st[i]=='a':
        cnt+=1

rest =siz-(cnt+1)
if cnt==siz/2:
    print(siz-1)
elif cnt>siz/2:
    print(siz)
else:
    print(siz-rest)

# your code goes here
a=input()
b=len(a)
count=0
for letter in a:
	if(letter=='a'):
		count=count+1
if(count>(b/2)):
	print(b)
elif(count<(b/2)):
	print(count+1)

pal = input()
letter_a = pal.count('a')
dif = len(pal) - letter_a
if (letter_a > dif):
    print(len(pal))
elif(letter_a == dif):
    print(len(pal)-1)
else:
    print(letter_a + 1)

string = input()
count = 0
for x in string:
    if x == "a":
        count += 1
if count + 1 > len(string):
    print(len(string))
else:
    print(count+1)

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

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

def ret():
    st = input()
    count  = 0
    lenSt = len(st)
    for i in range(lenSt):
        if st[i] == 'a':
            count += 1
    print("Count",count)
    if count >= (lenSt//2)+1:
#         print("lenSt//2+1",(lenSt//2)+1)
        return lenSt
    else:
        needed = (lenSt // 2) + 1
        return lenSt-needed
print(ret())

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

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

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

def count(arr):
    m=0
    for i in range(len(arr)):
        if arr[i]=='a':
            m = m + 1
    return m

arr = input()
arr2=[]
for i in range(len(arr)):
    arr2.append(arr[i])

m = len(arr2)
c = count(arr2)
print(m)

s = input()
l = len(s)
c=0

for i in range(l):
    if s[i]=='a':
        c = c+1
cnt = c+1
if c>l/2 :
    print(l)
else:
    print(cnt)

l=list(input())
l.sort()
c=0
for i in range(len(l)):
    if l[i]=='a':
        c=c+1
    else:
        break
if len(l)//2<c:
    print(len(l))
else:
    print(c+1)

def fun(str):
    counter = 0
    for c in str:
        if c == 'a':
            counter = counter + 1
    return counter

mystr = input("please enter the str: ")
ret = fun(mystr)
if ret == len(mystr):
    print("0")
else:
    print(len(mystr) - (len(mystr) - ret - ( ret - 1)))

s = input()
b = []
c = []
for item in s:
    if (item == "a"):
        b.append(item)
    else:
        c.append(item)
index = 0
while (len(b) > (len(c)//2)):
    b.append(c[index])
    index = index + 1
str1 = ""
str1.join(b)
print(len(b))

string = input()
num_a = 0
for i in string:
    if i == 'a':
        num_a += 1
print(num_a + 1)

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

a = input()
a = list(a)
b = []

for x in range(len(a)):
    if x < (len(a)-1):
        if (a[x] != a[x+1]) | (a[x] == "a"):
            b.append(a[x])
    else:
        if a[x] == "a":
            b.append(a[x])

for y in range(len(b)):
    if b[0] != "a":
        b.remove(b[0])
    else:
        break

for y in range(len(b)):
    if b[-1] != "a":
        b.remove(b[-1])
    else:
        break

print(len(b))

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

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

s = input()

list = []

for word in s:
    list.append(word)

a = 0
x = 0
for i in range(len(list)):
    if list[i] == 'a':
        a +=1
    else:
        x+=1

counter = -1
if a > x:
    print(a+x)
else:
    while a <= x:
        x -= 1
        counter +=1
    print(counter)

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

str = input()
c=str.count("a")
l=len(str)
if l==1:
	print(1)
if c>round(l/2):
    print(l)
else:
    print((c*2)-1)

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

s=raw_input()
c=s.count('a')
if len(s)==c:
    print c
elif len(s)/2<c:
    print len(s)
else:
    print c+1

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

if __name__ == '__main__':
    s = input()
    b = s.count('a')
    if b<(len(s)/2):
        print(b+1)
    else:
        print(len(s))

s=input()
a= len(s)
count =0
new=""
for i in range(len(s)):
    if s[i]=="a":
       new = new + "a"
    else:
        new = new +" "
k=new.index("a")
t=new[k::]
g=""
for i in t:
    if i=="a":
        g=g+i
    else:
        g=g+" "
m=""
if g.count(" ")>=1:
    m=" "
count=g.count("a")
m=m+"a"*count
print(len(m))

a = input()
sum = 0
list = list(a)

for i in range(len(a)):
    if 'a' in list[i]:
        sum += 1

if len(a) // 2 < sum:
    print(len(a))
elif len(a) // 2 == sum:
    print(len(a) - 1)
else:
    print(len(a) - sum - sum)