s=eval(input())

a=0

find_a=0

z=len(s)-1

find_z=0

while find_a==0 or find_z==0:

    if find_a==0 and s[a]=="A":

        find_a=1

    if find_z==0 and s[z]=="Z":

        find_z=1

    if find_a==0:

        a+=1

    if find_z==0:

        z-=1

print((z-a+1))
s=eval(input())

a=0

find_a=0

z=len(s)-1

find_z=0

while find_a==0 or find_z==0:

    if find_a==0:

        if s[a]=="A":

            find_a=1

        else:

            a+=1

    if find_z==0:

        if s[z]=="Z":

            find_z=1

        else:

            z-=1

print((z-a+1))
s = eval(input())
a = 0
find_a = 0
z = len(s) - 1
find_z = 0
while find_a == 0 or find_z == 0:
    if find_a == 0 and s[a] == "A":
        find_a = 1
    if find_z == 0 and s[z] == "Z":
        find_z = 1
    if find_a == 0:
        a += 1
    if find_z == 0:
        z -= 1
print((z - a + 1))

s = eval(input())
a = 0
find_a = 0
z = len(s) - 1
find_z = 0
while find_a == 0 or find_z == 0:
    if find_a == 0:
        if s[a] == "A":
            find_a = 1
        else:
            a += 1
    if find_z == 0:
        if s[z] == "Z":
            find_z = 1
        else:
            z -= 1
print((z - a + 1))

-    if find_a == 0 and s[a] == "A": -        find_a = 1 -    if find_z == 0 and s[z] == "Z": -        find_z = 1 -        a += 1 +        if s[a] == "A": +            find_a = 1 +        else: +            a += 1 -        z -= 1 +        if s[z] == "Z": +            find_z = 1 +        else: +            z -= 1