s = eval(input())

i = 0

while i < len(s):

    if s[i] == "A":

        break

    i += 1

j = 1

while j <= len(s):

    if s[-j] == "Z":

        break

    j += 1

print(((len(s) - j) - i +1))
s = eval(input())

start = s.find("A")

end = s.rfind("Z")

print((end - start + 1))
s = eval(input())
i = 0
while i < len(s):
    if s[i] == "A":
        break
    i += 1
j = 1
while j <= len(s):
    if s[-j] == "Z":
        break
    j += 1
print(((len(s) - j) - i + 1))

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

-i = 0 -while i < len(s): -    if s[i] == "A": -        break -    i += 1 -j = 1 -while j <= len(s): -    if s[-j] == "Z": -        break -    j += 1 -print(((len(s) - j) - i + 1)) +start = s.find("A") +end = s.rfind("Z") +print((end - start + 1))