# -*- coding: utf-8 -*-





s = input().strip()

#----------

loc_A=len(s)+1

loc_Z=-1

for i in range(len(s)):

    if s[i] == "Z" and loc_Z < i:

        loc_Z = i

    elif s[i] == "A" and i < loc_A:

        loc_A = i



print(( loc_Z - (loc_A - 1) ))

# -*- coding: utf-8 -*-



s=input().strip()



for i,word in enumerate(s):

    if word == "A":

        start = i

        break



for i,word in enumerate( reversed(s) ):

    if word == "Z":

        end = len(s)-1-i

        break



print(( end-start+1 ))

# -*- coding: utf-8 -*-
s = input().strip()
# ----------
loc_A = len(s) + 1
loc_Z = -1
for i in range(len(s)):
    if s[i] == "Z" and loc_Z < i:
        loc_Z = i
    elif s[i] == "A" and i < loc_A:
        loc_A = i
print((loc_Z - (loc_A - 1)))

# -*- coding: utf-8 -*-
s = input().strip()
for i, word in enumerate(s):
    if word == "A":
        start = i
        break
for i, word in enumerate(reversed(s)):
    if word == "Z":
        end = len(s) - 1 - i
        break
print((end - start + 1))

-loc_A = len(s) + 1 -loc_Z = -1 -for i in range(len(s)): -    if s[i] == "Z" and loc_Z < i: -        loc_Z = i -    elif s[i] == "A" and i < loc_A: -        loc_A = i -print((loc_Z - (loc_A - 1))) +for i, word in enumerate(s): +    if word == "A": +        start = i +        break +for i, word in enumerate(reversed(s)): +    if word == "Z": +        end = len(s) - 1 - i +        break +print((end - start + 1))