main::IO()
main =do
  str<-getLine
  print (solver1 str)

solver1::String -> Int
solver1 [] = 0
solver1 (x:xs) = if x/='A' then solver1 xs else (solver2 xs 0) + 1

solver2::String -> Int -> Int
solver2 [] i = i
solver2 (x:xs) i = if x/='Z' then (solver2 xs (i+1)) else i + (solver3 (x:xs) 0 0)

solver3::String -> Int -> Int -> Int
solver3 [] m _ = m
solver3 (x:xs) m n = if x/='Z' then (solver3 xs m (n+1)) else (solver3 xs (n+1) (n+1))