

s = eval(input())

n = len(s)

for i in range(n):

    if s[i] == "A":

        l = i

        break



for i in range(n-1,i,-1):

    if s[i] == "Z":

        r = i+1

        break



ans = max(0,r-l)

print(ans)


s = eval(input())

i = s.find("A")

j = s.rfind("Z")



print((j-i+1))

s = eval(input())
n = len(s)
for i in range(n):
    if s[i] == "A":
        l = i
        break
for i in range(n - 1, i, -1):
    if s[i] == "Z":
        r = i + 1
        break
ans = max(0, r - l)
print(ans)

s = eval(input())
i = s.find("A")
j = s.rfind("Z")
print((j - i + 1))

-n = len(s) -for i in range(n): -    if s[i] == "A": -        l = i -        break -for i in range(n - 1, i, -1): -    if s[i] == "Z": -        r = i + 1 -        break -ans = max(0, r - l) -print(ans) +i = s.find("A") +j = s.rfind("Z") +print((j - i + 1))