Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let rec loop i mi mx =
        if i = n then mx - mi + 1 else
            if s.[i] = 'Z' then loop (i + 1) mi i else
            if s.[i] = 'A' then loop (i + 1) (min mi i) mx else
                loop (i + 1) mi mx
    in
    loop 0 max_int 0 |> Printf.printf "%d\n"
)