I=input S=I() S=I() A=C=a=n=0 L='A' for s in S: if s==L:A+=1 else:C,n=C+1,n+A c=C m=n for s in S: if sL a+=s==L m=max(n,m) print(m)