s = eval(input())

n = len(s)

res = 0



for i in range(0, n):

    if s[i] == "A":

        j = i

        break

for i in range(0, n):

    if s[i] == "Z":

        k = i



res = k - j + 1

print(res)
s = eval(input())

res = s.rfind('Z') - s.find('A') + 1

print(res)

s = eval(input())
n = len(s)
res = 0
for i in range(0, n):
    if s[i] == "A":
        j = i
        break
for i in range(0, n):
    if s[i] == "Z":
        k = i
res = k - j + 1
print(res)

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

-n = len(s) -res = 0 -for i in range(0, n): -    if s[i] == "A": -        j = i -        break -for i in range(0, n): -    if s[i] == "Z": -        k = i -res = k - j + 1 +res = s.rfind("Z") - s.find("A") + 1