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.

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$$$.

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

NoteIn 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.

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

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

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

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)

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

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

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

s=raw_input()
c=s.count('a')
print min(len(s),2*c-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()
a=s.count('a')
if a>(len(s)//2):
    print(len(s))
else:
    print(a+a-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()
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))

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

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)

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

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()
k = s.count('a')
print(min(max(k + k - 1, 0), len(s)))

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

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

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

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

#!/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()

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)

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

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

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)

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

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

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

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

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

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()
a = s.count('a')
if a > len(s) // 2:
  print(len(s))
else:
  print(a * 2 - 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=raw_input()
c=s.count('a')
print min(len(s),2*c-1)

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

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

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)

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

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

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

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

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

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

#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

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

if(aCnt > len(s)/2):
    print(len(s))
else:
    print(aCnt * 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()
print(min(s.count('a')*2-1, 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()
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=raw_input()
c=s.count('a')
print min(c*2-1,len(s))

'''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=raw_input()
n=len(s)
a=sum(k=='a' for k in s)
print(min(n,2*a-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=input()
x=s.count('a')
if len(s) <= x*2-1:
    print(len(s))
else:
    print(x*2-1)

n=input()
l=len(n)
c=n.count("a")
if c>l//2:
    print(l)
else:
    print(c*2-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 = raw_input()

a = s.count('a')

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

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

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

#!/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 = 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().strip()
a = s.count('a')
print(len(s)) if a > len(s)/2 else print(a*2-1)

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

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

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

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

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

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

temp=s.count('a')

if temp*2>len(s):
     print(len(s))
else:
     print((2*temp)-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)

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

s = raw_input()

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

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)

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


Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?

The input contains a single integer n (0 ≤ n ≤ 2000000000).

TASK = "stars"
# FIN = open(TASK + ".in")
# FOUT = open(TASK + ".out", "w")

a = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0]
ans = 0
n = int(input())
if n == 0:
    print(1)
    exit()
while (n > 0):
    tmp = n % 16
    ans += a[tmp]
    n //= 16

print(ans)

# FIN.close()
# FOUT.close()

def main():
    n = int(input())
    n = hex(n)[2:]
    ans = 0
    for c in n:
        if c == '0' or c == '6' or c == '9' or c == 'a' or c == 'd' or c == '4':
            ans += 1
        if c == '8' or c == 'b':
            ans += 2
    print(ans)

if __name__ == '__main__':
    main()

a = int(input())
h = hex(a)
s = str(h)[2:]
oneHole = ['0', '4', '6', '9', 'a', 'd']
twoHoles = ['8', 'b']
count = 0
for i in range(len(s)):
    if s[i] in oneHole:
        count += 1
    elif s[i] in twoHoles:
        count += 2
print(count)

def mp():
    return map(int, input().split())

k = int(input())
if k == 0:
    print(1)
else:
    abc = '0123456789ABCDEF'
    r = 0
    while k > 0:
        d = abc[k % 16]
        if d in '0469AD':
            r += 1
        elif d in '8B':
            r += 2
        k //= 16
    print(r)

def f(i) : return i in ['4','6','8','9','0','a','b','d']
def g(i) : return i in ['8','b']
print sum([f(i)+g(i) for i in hex(int(raw_input()))])-1

n = int(raw_input())
hx = hex(n)[2:]

cnt = 0

for a in hx:
	if a == "0":
		cnt += 1
	if a == "4":
		cnt += 1
	if a == "6":
		cnt += 1
	if a == "8":
		cnt += 2
	if a == "9":
		cnt += 1
	if a == "a":
		cnt += 1
	if a == "b":
		cnt += 2
	if a == "d":
		cnt += 1

print cnt

n = int(input())
n = hex(n)[2:]
x = n.count('0') + n.count('4') + n.count('6') + n.count('9')
x += n.count('a') + n.count('d') + n.count('8') * 2 + n.count('b') * 2
print(x)

def count(x):
    if x == 0:
        return 1
    ans = 0
    holes = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0]
    while x:
        ans += holes[x % 16]
        x //= 16
    return ans
print(count(int(input())))

o = ['0','4','6','9','a','d']
oo = ['8','b']
cnt = 0
n = list(hex(int(input())))
x = ''
for i in range(2,len(n)):
    x += n[i]
x = str(x)
for j in x:
    if j in o:
        cnt += 1
    elif j in oo:
        cnt += 2
print(cnt)

s=int(raw_input())
b=str(hex(s))[2:]
sum=0
s1='0469ad'
s2='8b'
for i in b:
    if s1.find(i) != -1:
        sum += 1
    elif s2.find(i) != -1:
        sum += 2
print sum

n=int(input())
sumx=0
if(n==0):
	print(1)
else:
	while(n>0):
		a=n%16
		if(a<10):
			if(a==0 or a==4 or a==6 or a==9):
				sumx+=1
			elif(a==8):
				sumx+=2
		elif(a==10 or a==13):
			sumx+=1
		elif(a==11):
			sumx+=2
		n=n//16
	print(sumx)

from collections import defaultdict

a = input()
b = hex(a).upper()[2:]
d = defaultdict(lambda: 0, {'0':1, '4':1, '6':1, '8':2, '9':1, 'A':1, 'B':2, 'D':1})
print sum(map(lambda x: d[x], b))

def count(s):
    res = 0
    for i in s:
        if i in ['0', '4', '6', '9', 'A', 'D']:
            res += 1
        elif i in ['8', 'B']:
            res += 2
    return res

def main():
    s = hex(int(input())).replace('0x', '').upper()
    print(count(s))

main()

print sum(["046889abbd".count(x)for x in hex(int(input()))])-1

n = str(hex(int(raw_input())))[2:]
ans = 0
for i in n:
    if i == '0':
        ans += 1
    elif i == '4':
        ans += 1
    elif i == '6':
        ans += 1
    elif i == '8':
        ans += 2
    elif i == '9':
        ans += 1
    elif i == 'a':
        ans += 1
    elif i == 'b':
        ans += 2
    elif i == 'd':
        ans += 1
print ans

x = hex(int(raw_input()))
ans = 0
for c in x[2:]:
    if c in '4690ad':
        ans += 1
    if c in '8b':
        ans += 2
print ans

s = int(input())
a = hex(s)[2:]
print(a.count('0') + a.count('4') + a.count('6') + a.count('8') * 2 + a.count('a') + a.count('9') + a.count('b') * 2 + a.count('d'))

N = int( input() )
str = hex( N )[ 2 : ]

one = { '0', '4', '6', '9', 'a', 'd' }
two = { '8', 'b' }

ans = 0

for i in range( len( str ) ):
  if str[ i ] in one:
    ans += 1
  elif str[ i ] in two:
    ans += 2

print( ans )

print(sum(["046889ABBDabbd".count(x) for x in hex(int(input()))])-1)

x = int(input(""))
x = hex(x)[2:]
one = ['0', '4', '6', '9', 'a', 'd']
two = ['8', 'b']
count = 0
for i in x:
    if(i in one):
        count += 1
    elif(i in two):
        count += 2
print(count)

print sum([(i in'46890abd')+(i in'8b')for i in hex(int(raw_input()))])-1

n = int(input())
ans = 1 if n == 0 else 0

while n > 0:
    d = n % 16
    n = n // 16
    if d == 8 or d == 11:
        ans += 2
    elif d == 0 or d == 4 or d == 6 or d == 9 or d == 10 or d == 13:
        ans += 1

print(ans)

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) 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 main():
    n = I()
    s = hex(n).upper()[2:]
    r = 0
    for c in s:
        if c in '8B':
            r += 2
        elif c in '0469AD':
            r += 1

    return r

print(main())

n = input()
print(n.count('0') + n.count('4') + n.count('6') + n.count('8') * 2 + n.count('9'))

n=int(input())
sumx=0
while(n>0):
	a=n%16
	if(a<10):
		if(a==0 or a==4 or a==6 or a==9):
			sumx+=1
		elif(a==8):
			sumx+=2
	elif(a==10 or a==13):
		sumx+=1
	elif(a==11):
		sumx+=2
	n=n//16
print(sumx)

n = int(input())
n = bin(n + 1)[2:]
print(n.count('0'))

rings = [1,0,0,1,0,1,0,2,1,1,2,0,1,0,0]
def cnt(n):
    if n:
        res = 0
        while n:
            res += rings[n%16]
            n //= 16
    else:
        res = 1
    return res
n = int(input())
print(cnt(n))

s=int(raw_input())
b=str(hex(s))[2:]
sum=0
s1='0469ad'
s2='8b'
for i in b:
    if s1.find(i):
        sum += 1
    elif s2.find(i):
        sum += 2
print sum

s=14
b=str(hex(s))[2:]
sum=0
s1='0469ad'
s2='8b'
for i in b:
    if s1.find(i) != -1:
        sum += 1
    elif s2.find(i) != -1:
        sum += 2
print sum

s=int(raw_input())
b=str(hex(s))[:2]
sum=0
s1='0469ad'
s2='8b'
for i in b:
    if s1.find(i):
        sum += 1
    elif s2.find(i):
        sum += 2
print sum

s = raw_input()
ans = 0
for i in xrange(len(s)):
    c = 0
    for j in xrange(i + 1, len(s)):
        if s[i] == s[j]:
            ans += int(s[i]) * 2 - c
        c += int(s[j])
print ans

count = {
    '0': 1,
    '6': 1,
    '8': 2,
    '9': 1,
    'a': 1,
    'b': 2,
    'd': 1
}
s = hex(int(input()))[2:]
cnt = 0
for ch in s:
    if ch in count:
        cnt += count[ch]
print cnt

x = hex(int(raw_input()))
ans = 0
for c in x[2:]:
    if c in '4690AD':
        ans += 1
    if c in '8B':
        ans += 2
print ans

a = int(raw_input())
res = 0
while a > 0:
    part = a % 16
    a /= 16
    if part == 0 or part == 4 or part == 6 or part == 9 or part == 10 or part == 13:
        res += 1
    if part == 8 or part == 11:
        res += 2
print res

n = input()

ans = 0
while n > 0:
    x = n % 16
    n /= 16
    if x == 0 or x == 4 or x == 6 or x == 9 or x == 10 or x == 13:
        ans += 1
    else:
      if x == 8 or x == 11:
          ans += 2

print ans

a=sorted(map(int,raw_input().split())[1:])
i=0
while i<11000000:
	i+=1
print " ".join(map(str,a))

s = hex(int(raw_input())).upper()[2:]
ret = 0
for x in s:
    if x in ['0', '6', '9', 'A', 'D']:
        ret += 1
    if x in ['8', 'B']:
        ret += 2
print ret

n = int(input())
summa = 0
while n>0:
    x = n%16
    n //= 16
    if x==15 or x==1 or x==2 or x==10:
        summa += 1
    if x==8 or x==11:
        summa += 2
print(summa)

n = int(input())
summa = 0
while n>0:
    x = n%16
    n //= 16
    if x==15 or x==1 or x==2 or x==7:
        summa += 1
    if x==8 or x==15:
        summa += 2
print(summa)

n = int(input())
summa = 0
while n>0:
    x = n%16
    n //= 16
    if x==15 or x==1 or x==2 or x==10:
        summa += 1
    if x==8 or x==15:
        summa += 2
print(summa)

n = int(input())
summa = 0
while n>0:
    x = n%16
    n //= 16
    if x==15 or x==1 or x==2 or x==7:
        summa += 1
    if x==8 or x==11:
        summa += 2
print(summa)

n = int(input())
summa = 0
while n>0:
    x = n%16
    n //= 16
    if x==4 or x==0 or x==6 or x==9 or x==10 or x==13:
        summa += 1
    if x==8 or x==11:
        summa += 2
print(summa)

print(sum(["046889ABBDabde".count(x) for x in hex(int(input()))])-1)

cur = int(input())
hex = ""
shit = ['A', 'B', 'C', 'D', 'E', 'F']
while cur != 0:
    temp = cur % 16
    cur = cur // 16
    if temp >= 10:
        hex += shit[temp - 10]
    else:
        hex += str(temp)
answ = 0
for a in hex:
    if a == 'A' or a == '6' or a == '0' or a == 'D' or a == '4' or a == '9':
        answ = answ + 1
    elif a == '8' or a == 'B':
        answ += 2
print(answ)

n = int(input())
ans = 1 if n == 0 else 0

while n > 0:
    d = n % 16
    n = n // 16
    if d == 8 or d == 11:
        ans += 2
    elif d == 0 or d == 4 or d == 6 or d == 10 or d == 13:
        ans += 1

print(ans)

def mp():
    return map(int, input().split())

k = int(input())
abc = '0123456789ABCDEF'
r = 0
while k > 0:
    d = abc[k % 16]
    if d in '069AD':
        r += 1
    elif d in '8B':
        r += 2
    k //= 16
print(r)

def mp():
    return map(int, input().split())

k = int(input())
abc = '0123456789ABCDEF'
r = 0
while k > 0:
    d = abc[k % 16]
    if d in '0469AD':
        r += 1
    elif d in '8B':
        r += 2
    k //= 16
print(r)

def main():
    n = int(input())
    n = hex(n)[2:]
    ans = 0
    for c in n:
        if c == '0' or c == '6' or c == '9' or c == 'a':
            ans += 1
        if c == '8' or c == 'b':
            ans += 2
    print(ans)

if __name__ == '__main__':
    main()

def main():
    n = int(input())
    n = hex(n)[2:]
    ans = 0
    for c in n:
        if c == '0' or c == '6' or c == '9' or c == 'd':
            ans += 1
        if c == '8' or c == 'b':
            ans += 2
    print(ans)

if __name__ == '__main__':
    main()

def main():
    n = int(input())
    n = hex(n)[2:]
    ans = 0
    for c in n:
        if c == '0' or c == '6' or c == '9':
            ans += 1
        if c == '8' or c == 'b':
            ans += 2
    print(ans)

if __name__ == '__main__':
    main()

def main():
    n = int(input())
    n = hex(n)[2:]
    ans = 0
    for c in n:
        if c == '0' or c == '6' or c == '9' or c == 'a' or c == 'd':
            ans += 1
        if c == '8' or c == 'b':
            ans += 2
    print(ans)

if __name__ == '__main__':
    main()

x = int(input(""))
x = hex(x)[2:]
one = ['0', '4', '6', '9', 'a', 'c']
two = ['8', 'b']
count = 0
for i in x:
    if(i in one):
        count += 1
    elif(i in two):
        count += 2
print(count)

x = int(input(""))
one = ['0', '4', '6', '9', 'a', 'c']
two = ['8', 'b']
count = 0
while(True):
    y = (hex(int(x % 16)))[2:]
    if(y in one):
        count += 1
    elif(y in two):
        count += 2
    x = int(x/16)
    if(x == 0):
        break
print(count)

def count(x):
    if x == 0:
        return 1
    ans = 0
    holes = [1, 0, 0, 0, 0, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0]
    while x:
        ans += holes[x % 16]
        x //= 16
    return ans
print(count(int(input())))

def count(x):
    ans = 0
    holes = [1, 0, 0, 0, 0, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0]
    while x:
        ans += holes[x % 16]
        x //= 16
    return ans
print(count(int(input())))

p = int(input())
s = hex(p).upper()[2:]
ans = 0
for x in s:
    if x == '0':
        ans += 1
    if x == '6':
        ans += 1
    if x == '8':
        ans += 2
    if x == 'A':
        ans += 1
    if x == 'B':
        ans += 2
    if x == 'D':
        ans += 1
    if x == '4':
        ans += 1
print(ans)