program ABC053B
    implicit none
    integer(8)::i,top,tail,s_len
    character(200000)::s
    read(5,*)s
    s_len=len_trim(s)
    do i=1,s_len
        if(s(i:i)=='A')then
            top=i
            exit
        end if
    end do

    do i=0,s_len-1
        if(s(s_len-i:s_len-i)=='Z')then
            tail=s_len-i
            exit
        end if
    end do

    print'(i0)',tail-top+1
end program ABC053B