s = eval(input())

p = -1

for i in range(len(s)) :

    if s[i] == 'A' and p == -1:

        p = i

    if s[i] == 'Z':

        q = i

print((q - p + 1))



    

s = eval(input())

p = s.find('A')

q = s.rfind('Z')

ans = q - p + 1

print(ans)



    

s = eval(input())
p = -1
for i in range(len(s)):
    if s[i] == "A" and p == -1:
        p = i
    if s[i] == "Z":
        q = i
print((q - p + 1))

s = eval(input())
p = s.find("A")
q = s.rfind("Z")
ans = q - p + 1
print(ans)

-p = -1 -for i in range(len(s)): -    if s[i] == "A" and p == -1: -        p = i -    if s[i] == "Z": -        q = i -print((q - p + 1)) +p = s.find("A") +q = s.rfind("Z") +ans = q - p + 1 +print(ans)