Problem:
 Score : 200 points    Problem Statement Snuke has decided to construct a string that starts with A and ends with Z , by taking out a substring of a string s (that is, a consecutive part of s ).  Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z .      Constraints  1 ≦ |s| ≦ 200{,}000  s consists of uppercase English letters.  There exists a substring of s that starts with A and ends with Z .         Input The input is given from Standard Input in the following format:  s       Output Print the answer.        Sample Input 1 QWERTYASDFZXCV      Sample Output 1 5  By taking out the seventh through eleventh characters, it is possible to construct ASDFZ , which starts with A and ends with Z .       Sample Input 2 ZABCZ      Sample Output 2 4       Sample Input 3 HASFJGHOGAKZZFEGA      Sample Output 3 12

Solution (Python):
s=input()
n=len(s)
f=0
l=0
for i in range(n):
    if s[i]=="A":
        f=i
        break
for i in range(n)[::-1]:
    if s[i]=="Z":
        l=i
        break
print(l-f+1)

Solution (Python):
s=list(input())
print(len(s)-s[::-1].index('Z')-s.index('A'))

Solution (Python):
def main():
    s = input()
    As = []
    Zs = []
    for i in range(len(s)):
        if s[i] == "A":
            As.append(i)
        elif s[i] == "Z":
            Zs.append(i)
    return Zs[-1] - As[0] + 1

if __name__ == '__main__':
    print(main())

Solution (Python):
s = input()
st = s.index("A")
en = s.rindex("Z")
print(en-st+1)

Solution (Python):
s = input()
n = len(s)
start = s.index('A')
end = n - s[::-1].index('Z')
print(len(s[start:end]))

Solution (Python):
s = list(input())
a = s.index("A")
z = len(s) - s[::-1].index("Z")
print(z - a)

Solution (Python):
s = input()
l = s.index("A")
r = s.rindex("Z")
print(r - l + 1)

Solution (Python):
s  = input()

for i in range(len(s)):
    if s[i] == 'A':
        a = i
        break
for i in range(len(s)):
    if s[i] == 'Z':
        z = i + 1

print(len(s[a:z]))

Solution (Python):
s = str(input())
print(s.rfind('Z') - s.find('A') + 1)

Solution (Python):
s = input()
for i in range(len(s)):
         if s[i] == "A":
                  aindex = i
                  break
for i in range(len(s)):
         if s[i] == "Z":
                  zindex = i
print(zindex - aindex + 1)

Solution (Python):
a = input()
s = a.index('A')
e = a[::-1].index('Z')
print(len(a)-s-e)

Solution (Python):
import sys
input = sys.stdin.readline

S=input()

for i in range(0,len(S),1):
  if S[i]=='A':
    aind=i
    break
for i in range(len(S)-1,0,-1):
  if S[i]=='Z':
    zind=i
    break
print(zind-aind+1)

Solution (Python):
s = input()

start = 0
end = 0
for i in range(len(s)):
    if s[i] == 'A':
        start = i
        break
for i in reversed(range(len(s))):
    if s[i] == 'Z':
        end = i
        break
print(end - start + 1)

Solution (Python):
s = input()

for i in range(len(s)):
    if s[i] == "A":
        a = i
        break
for i in range(len(s)):
    if s[i] == "Z":
        z = i+1

print(len(s[a:z]))

Solution (Python):
s=input()

i = 0
a = -1
b = -1
for c in s:
    i+=1
    if c == 'A':
        if a == -1:
            a = i
    elif c == 'Z':
        if b < i:
            b = i

print(b-a+1)

Solution (Python):


def _index(l, c):
    if c in l:
        return l.index(c)
    else:
        return -1

chars = list(input())

a = _index(chars, "A")
z = _index(list(reversed(chars)), "Z")


if a == -1 or z == -1:
    print("0")
    exit(0)

if a + z < len(chars) - 1:
    print(len(chars) - a - z)
else:
    print("0")

Solution (Python):
s = str(input())
print(s.rfind('Z') - s.find('A') + 1)

Solution (Python):
s=input()
print(len(s)-s.index('A')-s[::-1].index('Z'))

Solution (Python):
s = input()
print(len(s) - s.index('A') - s[::-1].index('Z'))

Solution (Python):
s = input()
n = len(s)

for i in range(n):
  if s[i]=="A":
    ind=i
    break
    
ex=n
for i in reversed(s):
  ex -= 1
  if i=="Z":
    break

print(ex-ind+1)

Solution (Python):
S = input()

print(S.rfind("Z")-S.find("A")+1)

Solution (Python):
s=input()
left,right=0,0
left = s.index("A")
right = s[::-1].index("Z")
print(len(s)- right-left)

Solution (Python):
s = input()
start = s.find("A")
end = s[::-1].find("Z")
print(len(s[start:len(s)-end]))

Solution (Python):
s=input()
print(s.rfind('Z')-s.find('A')+1)

Solution (Python):
s = input()
for i in range(len(s)):
    if s[i] == "A":
        min = i
        break
for i in range(len(s))[::-1]:
    if s[i] == "Z":
        max = i
        break
print(max-min+1)

Solution (Python):
s=input()
for i in range(len(s)):
    if s[i]=="A":
        a=i
        break
for i in range(len(s)):
    if s[-i-1]=="Z":
        print(len(s)-i-a)
        break

Solution (Python):
s = input()
c1 = 0
c2 = 0
for i in s:
    if i == "A":
        break
    c1 += 1
    
for i in reversed(s):
    if i == "Z":
        break
    c2 += 1
    
print(len(s)-c2-c1)

Solution (Python):
s = list(input())
print(len(s) - s.index('A') - s[::-1].index('Z'))

Solution (Python):
s = input()
a = [i for i, x in enumerate(s) if x == 'A']
z = [i for i, x in enumerate(s) if x == 'Z']
print(z[-1] - a[0] + 1)

Solution (Python):
s = str(input())
start=0
end = 0
for i,j in enumerate(s):
  if j == "A":
    start = i
    break
for i,j in enumerate(s[::-1]):
  if j == "Z":
    end = i
    break
print(len(s) - start - end)

Solution (Python):
s = input()
print(len(s[s.find("A"):s.rfind("Z")+1]))

Solution (Python):
s = input()
start = 0
end = 0

for i in range(len(s)):
    if s[i] == 'A':
        start = i
        break

for i in range(len(s)):
    p = len(s) - 1 - i
    if s[p] == 'Z':
        end = p
        break
print(end - start + 1)

Solution (Python):
s = input()
print(s.rfind("Z") - s.find("A") + 1)

Solution (Python):
s = input()
m = 0
for i in range(len(s)):
  if s[i] == 'Z':
    m = i
print(m-s.index('A')+1)

Solution (Python):
s = input()
print(len(s)-s[::-1].index("Z")-s.index("A"))

Solution (Python):
s = input()
print(len(s[s.index('A'):][::-1][s[s.index('A'):][::-1].index('Z'):]))

Solution (Python):
s = input()
begin = s.find("A")
end = s.rfind("Z")
print(end - begin + 1)

Solution (Python):
S = list(input())
num = 0
num2 = 0
for i in range(len(S)):
    if S[i] == "A":
        num = i
        break
for i in range(len(S)):
    if S[i] == "Z":
        num2 = i

print(num2 - num + 1)

Solution (Python):
s=input();print(len(s)-s[::-1].index("Z")-s.index("A"))

Solution (Python):
s = input()

for n, i in enumerate(s):
    if i=='A':
        a=n
        break
for n, i in enumerate(reversed(s)):
    if i=='Z':
        b=len(s)-n
        break

print(b-a)

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 




 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    s = list(input())
    ans = 0
    ss = -1
    e = -1
    for i,val in enumerate(s):
        if val == "A":
            ss = i
            break
            
    s = s[::-1]
    for i,val in enumerate(s):
        if val == "Z":
            e = i
            break
            
    
    print((len(s)-e)-ss)
            
            
if __name__ == "__main__":
	main()

Solution (Python):

import sys
INF = float("inf")


def solve(s: str):
    start = s.find("A")
    end = s.rfind("Z")
    print(end-start+1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)


if __name__ == '__main__':
    main()

Solution (Python):
s=list(input())
n=len(s)
a=[]
z=[]
for i in range(n):
  if s[i]=='A':
    a.append(i)
  if s[i]=='Z':
    z.append(i)
print(max(z)-min(a)+1)

Solution (Python):

s = input()
left = s.index('A')
for i in range(len(s)-1, 0, -1):
    if s[i] == 'Z':
        right = i
        break

print(len(s[left:right+1]))

Solution (Python):
s=input()
left=s.index("A")
right=s[::-1].index("Z")
print(len(s)-left-right)

Solution (Python):
s = input()
print(s.rfind('Z')-s.find('A')+1)

Solution (Python):
s=input()
A=s.index("A")
Z=s[::-1].index("Z")
print(len(s)-A-Z)

Solution (Python):
s = list(input())
a = s.index('A')
z = list(reversed(s)).index('Z')
print((len(s) - z) - a)

Solution (Python):
s = input()
a = s.find("A")
b = s.rfind("Z")
r = b-a+1
print(r)

Solution (Python):


s = input()
n = len(s)
for i in range(n):
    if s[i] == 'A':
        start = i
        break
for i in range(n - 1, -1, -1):
    if s[i] == 'Z':
        end = i
        break
print(end + 1 - start)

Solution (Python):
s=input()
A=s.find("A")
Z=s.rfind("Z")
result=Z-A+1
print(result)

Solution (Python):
from sys import stdin
S = stdin.readline()
flag = 0
a_pos = 0
z_pos = 0
for c, s in enumerate(S):
    if (s == "A") & (flag == 0):
        flag = 1
        a_pos = c
    if s == "Z":
        z_pos = c
print(z_pos - a_pos + 1)

Solution (Python):
x = [i for i in input()]
p = x.index("A")
t = [i for i,x in enumerate(x) if x == "Z"]
q = max(t)
print(q-p+1)

Solution (Python):
S=input()
a=S.index('A')
for i in range(len(S)-1,0,-1):
    if S[i]=='Z':
        z=i
        break
print(z-a+1)

Solution (Python):
S = input()

Z = [i for i,j in enumerate(S) if j == 'Z']
print(Z[-1]-S.index("A")+1)

Solution (Python):
s = input()
length = len(s)
start =0
end=0

for i in range(length):
  if s[i] == "A":
    start = i
    break
    
for i in range(length-1,-1,-1):
  if s[i] == "Z":
    end = i
    break

print(end-start+1)

Solution (Python):
s = str(input())
ptA = s.find("A")
ptB = s.rfind("Z")
print(ptB-ptA+1)

Solution (Python):
s = input()
print(len(s)-s[::-1].index("Z")-s.index("A"))

Solution (Python):
s = input()

a = s.find('A')
z = s.rfind('Z')

print(z - a +1)

Solution (Python):
import re
s = input()
start =s.index('A')
end =s.index('Z')
for i in s:
  if i == 'A':
    start = s.find('A')


end =s.rfind('Z')
print(end-start+1)

Solution (Python):
s=input()
a=s.index("A")
b=s.rfind("Z")
print(len(s[a:b+1]))

Solution (Python):
s = input()
a_idx = s.index('A')
s = s[a_idx:]
s = s[::-1]
z_idx= s.index('Z')
s = s[z_idx:]
print(len(s))

Solution (Python):
s = input()
print(s.rfind('Z') -  s.find('A') + 1)

Solution (Python):
s = input()
a = s.find("A")
z = s.rfind("Z")
print(z - a + 1)

Solution (Python):
s = input()
a = 0
z = 0
for i in range(len(s)):
    if s[i] == 'A' and a == 0:
        a = i + 1
    if s[-i] == 'Z' and z == 0 and i != 0:
        z = len(s) -i + 1
print(z - a + 1)

Solution (Python):
s = input()
a = s.find('A')
z = s.rfind('Z')
print(len(s[a:z+1]))

Solution (Python):



s = input()


for i in range(len(s)):
    if s[i] == 'A':
        a = i
        break

for i in reversed(range(len(s))):
    if s[i] == 'Z':
        z = i
        break


print(z - a + 1)

Solution (Python):
s = input()
print(s.rfind('Z')-s.find('A')+1)

Solution (Python):
s = input()
print(s.rindex("Z") - s.index("A") + 1)

Solution (Python):
a = input()

b = a.find("A")+1
c = a.rfind("Z")+1

print(c-b+1)

Solution (Python):
s = input()

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

Solution (Python):
S = input()
print(S.rindex("Z")-S.index("A")+1)

Solution (Python):
s = input()

a_pos = -1
z_pos = -1

for i, si in enumerate(s):
    if si == 'A' and a_pos == -1:
        a_pos = i
    if si == 'Z':
        z_pos = i

print(z_pos - a_pos + 1)

Solution (Python):
s = input()

a_pos = s.find('A')
z_pos = "".join(reversed(s)).find('Z')
z_pos = len(s) - z_pos - 1


print(z_pos - a_pos + 1)

Solution (Python):
s = list(input())
a = s.index('A')
z = s[::-1].index('Z')
z = len(s) - z
print(z-a)

Solution (Python):
s = list(input())
a = 0
z = 0
for i in range(len(s)):
    if s[i] == 'A':
        a = i+1
        break
for i in range(1, len(s)):
    if s[-i] == 'Z':
        z = len(s)-i+1
        break
print(z-a+1)

Solution (Python):
s = input()
a = s.find('A')
b = s.rfind('Z')
print(b-a+1)

Solution (Python):
s = input()
print(len(s)-s[::-1].index('Z')-s.index('A'))

Solution (Python):
s=input()
print(len(s)-s[::-1].index("Z")-s.index("A"))

Solution (Python):
s = input()
a_iter=0
z_iter=0
for i in range(len(s)):
  if s[i]=="A":
    a_iter=i+1
    break
for i in range(1,len(s)+1):
  if s[-i]=="Z":
    z_iter=(len(s)-1)-(i-1)
    break
print(z_iter-a_iter+2)

Solution (Python):
s = input()
a = -1
z = -1
for i in range(len(s)):
  if s[i] == "A" and a == -1:
    a = i
  if s[-1-i] == "Z" and z == -1:
    z = len(s)-i
print(z-a)

Solution (Python):
a = input()

for i in range(len(a)):
  if 'A' in a[i]:
    b = i
    break

for i in range(len(a)):
  if i != 0 and 'Z' in a[-i]:
    c = i
    break
      
d = len(a) - c + 1

print(len(a[b:d]))

Solution (Python):
s = input()

aidx_list = []
zidx_list = []

for i in range(len(s)):
    if (s[i]  == 'A'):
        aidx_list.append(i)
    if (s[i] == 'Z'):
        zidx_list.append(i)

print(len(s[aidx_list[0]:zidx_list[-1]+1]))

Solution (Python):
s = input()
for i in range(len(s)):
    if s[i] == 'A':
        left = i
        break
for j in range(len(s) - 1, 0, -1):
    if s[j] == 'Z':
        right = j
        break
ans = len(s[left:right+1])
print(ans)

Solution (Python):
s = input()

print (s.rfind("Z") - s.find("A") + 1)

Solution (Python):
Strings = input()

for i in range(0,len(Strings)):
    if Strings[i] == "A":
        length = i
        break

for i in range(len(Strings))[::-1]:
    if Strings[i] == "Z":
        length2 = i
        break

print(length2 - length +1 )

Solution (Python):
s = input()
a = 0
z = 0
for i in range(int(len(s))):
    if s[i] == 'A' and a == 0:
        a = i + 1
    if s[-i] == 'Z' and z == 0 and i != 0:
        z = len(s) - i + 1
print(z - a + 1)

Solution (Python):
sl=list(input())

n=len(sl) 
al=[];zl=[]
ans=[]
for i in range(n) :
  if sl[i]=="A" :
    al.append(i)
  if sl[i]=="Z" :
    zl.append(i)


print(max(zl)+1-min(al))

Solution (Python):
n = input()
nn = n[::-1]
print(len(n)-nn.index("Z")-n.index("A"))

Solution (Python):
s = input()
i, j = 0, 0
for t in range(len(s)):
    if s[t] == 'A':
        i = t
        break
for t in reversed(range(len(s))):
    if s[t] == 'Z':
        j = t
        break
print(len(s[i:j])+1)

Solution (Python):
s=input()
a=0
z=0
flag=0
for i in range(len(s)):
    if s[i]=='A' and flag==0:
        a=i
        flag=1
    elif s[i]=='Z':
        z=i
print(z-a+1)

Solution (Python):
S = input()

begin = S.find("A")
end = S.rfind("Z")
print(end - begin + 1)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

s = input()
left = 0
right = 0
for i in range(len(s)):
    if (s[i] == "A"):
        left = i
        break
for i in range(len(s) - 2, 0, -1):
    if (s[i] == "Z"):
        right = i
        break
print(right - left + 1)

Solution (Python):
strInp = input()
print(abs(strInp.find('A',0) - strInp.rfind('Z',0)) + 1)

Solution (Python):
s = input()
n = len(s)
a = 0
z = -1
while True:
  if s[a] == 'A':
    break
  a += 1
  n -= 1
while True:
  if s[z] == 'Z':
    break
  z -= 1
  n -= 1
print(n)

Solution (Python):
s = input()
print(s.rindex("Z")-s.index("A")+1)

Solution (Python):
import sys
import math
input=sys.stdin.readline

s = input().strip()

print(s.rfind("Z")-s.find("A")+1)

Solution (Python):
import re

s = input()
list_s = [len(i) for i in re.findall("A.*Z", s)]
print(max(list_s))

Solution (Python):
s = str(input())
for i in range(len(s)):
  if s[i] == 'A':
    a_idx = i
    break
for i in range(len(s)-1, -1, -1):
  if s[i] == 'Z':
    z_idx = i
    break
print(z_idx - a_idx + 1)

Solution (Python):
s=list(input())
ans=len(s)-s[::-1].index("Z")-s.index("A")
print(ans)

Solution (Python):
s = input()
print(s.rfind('Z') - s.find('A') + 1)

Solution (Python):
s=input()
a = 0
i=0
while True:
    if s[i]=="A":
        a=i
        break
    else: i+=1
z=0
j=1
while True:
    if s[-j]=="Z":
        z=j
        break
    else: j+=1
print((len(s)-j)-i+1)

Solution (Python):
s = input()
min = 0
flg = 0
max = 0
for i in range(len(s)):
    if s[i] == 'A':
        if flg == 0:
            min = i
            flg = 1
    
    if s[i] == 'Z':
        max = i

ans = max - min + 1
print(ans)

Solution (Python):
s = input()
print(s.rindex("Z") - s.index("A") + 1)

Solution (Python):
string = input().rstrip("\n")
string_r = "".join(reversed(string))
print(len(string) - string_r.index("Z") - string.index("A"))

Solution (Python):
s = input()
start = len(s)
end = len(s)

for i in range(len(s)):
    if s[i] == "A":
        start = min(start,i)
    if s[len(s)-1-i] == "Z":
        end = min(end,i)

print(len(s)-start-end)

Solution (Python):
s = input()
n = len(s)
for i in range(n):
  if s[i]=="A":
    indexA = i
    break
for j in reversed(range(n)):
  if s[j]=="Z":
    indexZ = j
    break
ans = indexZ - indexA + 1
print(ans)

Solution (Python):
s = input()

A_index = s.find('A')
Z_index = s.rfind('Z')

print(Z_index - A_index + 1)

Solution (Python):
s = input()

left = 0
right = 0
for i in range(len(s)):
    if s[i] == 'A':
        left = i
        break
for i in reversed(range(len(s))):
    if s[i] == 'Z':
        right = i
        break
print(right - left + 1)

Solution (Python):
s = input()
print(len(s) - s[::-1].index('Z') - 1 - s.index('A') + 1)

Solution (Python):
S = input()
a = S.index('A')
z = len(S) - S[::-1].index('Z') 
print(z-a)

Solution (Python):
s = input()
print(s.rindex('Z')-s.index('A')+1)

Solution (Python):
s = input()

indexa = 0
indexz = 0
for i in range(len(s)):
    if s[i] == 'A':
        indexa = i
        break

for i in range(len(s) - 1, 0, -1):
    if s[i] == 'Z':
        indexz = i
        break

print(indexz - indexa + 1)

Solution (Python):
s = str(input())
for i in range(len(s)):
    if s[i] == 'A':
        min = i
        break
for i in reversed(range(len(s))):
    if s[i] =='Z':
        max = i
        break

print(max-min+1)

Solution (Python):
s = input()
n = len(s)
a = float('INF')
z = 0
for i in range(n):
    if s[i] == 'A':
        a = min(a, i)
    elif s[i] == 'Z':
        z = max(z, i)
print(z + 1 - a)

Solution (Python):
S = input()
start = 0
is_found_a = False
ans = 0
for i in range(len(S)):
    if not is_found_a and S[i] == 'A':
        start = i
        is_found_a = True
    elif S[i] == 'Z':
        ans = i - start + 1
print(ans)

Solution (Python):
s = input()

print(s.rfind("Z") - s.find("A") + 1)

Solution (Python):
import re
m = re.search(r'A.*Z' ,input().strip())
print(m.end()-m.start())

Solution (Python):
s = input()
apos = -1
zpos = 0
 
for i, c in enumerate(s):
  if c == "A" and apos == -1:
    apos = i
  if c == "Z":
    zpos = i
    
print(zpos - apos + 1)

Solution (Python):
S = input()
pos_a = -1
pos_z = -1
for i in range(len(S)):
  if S[i] == 'A' and pos_a < 0:
    pos_a = i
  if S[len(S)-i-1] == 'Z' and pos_z < 0:
    pos_z = len(S)-i-1
  if pos_a >= 0 and pos_z > 0:
    break
print(pos_z-pos_a+1)

Solution (Python):
str_list = list(input())

A_index = [i for i, s in enumerate(str_list) if s == 'A']
Z_index = [i for i, s in enumerate(str_list) if s == 'Z']

print(Z_index[-1] - A_index[0] + 1)

Solution (Python):
s = input()
numA = 0
for i in range(len(s)):
    if s[i] == 'A':
        numA = i + 1
        break

numZ = 0
for i in range(len(s)-1,-1,-1):
    if s[i] == 'Z':
        numZ = i + 1
        break
print(numZ - numA + 1)

Solution (Python):
s=list(input())

a_indexes = [i for i, s in enumerate(s) if s == 'A']
z_indexes = [i for i, s in enumerate(s) if s == 'Z']
print(max(z_indexes)-min(a_indexes)+1)

Solution (Python):
s = input()

l_counter = 0
r_counter = 0
onthelist =False
ans = 0
for l in s:
    if l == 'A':
        break
    l_counter += 1

for l in s[::-1]:
    if l == 'Z':
        break
    r_counter += 1


ans = len(s) - l_counter - r_counter


print(ans)

Solution (Python):
S = input()
s = None
for i in range(len(S)):
  c = S[i]
  if c == "A" and s is None:
    s = i
  if c == "Z":
    e = i
print(e-s+1)

Solution (Python):
S = input()
L = len(S)
for i in range(L):
  c = S[i]
  if c == "A":
    s = i
    break
for i in range(L):
  c = S[-(i+1)]
  if c == "Z":
    e = L - (i+1)
    break
print(e-s+1)

Solution (Python):
s = list(input())

print(len(s) - s.index('A') - s[::-1].index('Z'))

Solution (Python):
s=list(input())
a=200000
z=0

for i in range(len(s)):
  if s[i]=='A'and a>i:
    a=i
  if s[i]=='Z'and z<i:
    z=i
print(z-a+1)

Solution (Python):
s = input()
len = len(s)

for i in range(len):
    if s[i] == "A":
        ans1 = i
        break
for i in range(len):
    if s[-i-1] == "Z":
        ans2 = i
        break
print(len-ans1-ans2)

Solution (Python):
s = str(input())
a = -1
z = 0

for i in range(len(s)):
    if a == -1 and s[i] == "A":
        a = i
    if s[i] == "Z":
        z = i
print(z - a + 1)

Solution (Python):
s=input().strip()
a = s.find('A')
z = s.rfind('Z')
print(z-a+1)

Solution (Python):

import sys, math, fractions, itertools


def solve(s: str):
    a = s.find('A')
    z = ''.join(list(reversed(s))).find('Z')
    print(len(s) - z - a)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
e=10**9
for i,S in enumerate(s):
  if S=='A':
    b=i
    break
for i,S in enumerate(s[::-1]):
  if S=='Z':
    e=len(s)-i
    break
print(e-b)

Solution (Python):
l=input()
a=l.index("A")
z=l[::-1].index("Z")
print(len(l)-z-a)

Solution (Python):
s = input()
print(s.rfind('Z') - s.find('A') + 1)

Solution (Python):
s = str(input())
s = s.split("A",1)[1]
s = s.rsplit("Z",1)[0]
print(len(s)+2)

Solution (Python):
s = input()
print(s.rfind('Z') - s.find('A') + 1)

Solution (Python):
s=input()
a=s.find('A')
z=s.rfind('Z')
print(z-a+1)

Solution (Python):
s = list(input())
a = s.index('A')
z = len(s) - s[::-1].index('Z') - 1
print(z-a+1)

Solution (Python):
s = input()
a = s.index("A")
s = s[::-1]
z = s.index("Z")
print(len(s)-z-a)

Solution (Python):
s = input()
start = s.index("A")
s = s[::-1]
end = s.index("Z")
print(len(s) - start - end)

Solution (Python):

import sys

def main():
    data = list(input())

    for i in range(len(data)):
        if data[i] == 'A':
            left = i
            break

    for i in range(len(data))[::-1]:
        if data[i] == 'Z':
            right = i
            break

    print(right - left + 1)


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
a=s.find('A')
z=s.rfind('Z')
print(z-a+1)

Solution (Python):
s = list(input())
count = 0
index1 = s.index("A")
    
for num in s[::-1]:
  if num == "Z":  
    break
  else :
    count += 1

print(len(s) - (index1 + count))

Solution (Python):
s = list(input())
i = s.index("A")
s.reverse()
j = s.index("Z")
print(len(s) - j -  i)

Solution (Python):
s = input()
print(s.rfind("Z")-s.find("A")+1)

Solution (Python):
s = input()
print(s.rfind("Z")-s.find("A")+1)

Solution (Python):
s = input()
print(s.rfind("Z")-s.find("A")+1)

Solution (Python):
s = input()
print(len(s)-s.index("A")-s[::-1].index("Z"))

Solution (Python):
a = input()
b = 0
count = 0
while True:
  if a[count] == "A":
    b = count
    break
  else:
    count += 1
count = 1
while True:
  if a[-count] == "Z":
    print(len(a)-count-b+1)
    exit()
  else:
    count += 1

Solution (Python):
S = input()
s, e = 0, 0
for i in range(len(S)):
    if S[i] == "A":
        s = i
        break

for i in range(len(S)-1,-1,-1):
    if S[i] == "Z":
        e = i
        break

print(e-s+1)

Solution (Python):
s = input()
a = s.find('A')
b = s.rfind('Z')
print(b-a+1)

Solution (Python):
s = input()

for i in range(len(s)):
  if s[i] == 'A':
    a = i
    break
for k in range(len(s)-1, -1, -1):
  if s[k] == 'Z':
    b = k
    break

print(b - a + 1 )

Solution (Python):
s = list(input())
len = len(s)
fastA = s.index("A")+1
s.reverse()
Ztsal = s.index("Z")+1
lastZ = len - Ztsal + 1
print(lastZ - fastA + 1)

Solution (Python):
s = input()
print(s.rfind('Z') - s.find('A') + 1)

Solution (Python):
s = input()
start = 200030
end = 0

for i in range(len(s)):
    if s[i] == "A":
        if i < start:
            start = i
        
    elif s[i] == "Z":
        end = i

print(end - start + 1)

Solution (Python):
S = input()
aindex = -1
for i in range(0, len(S)):
	if S[i] == 'A':
		aindex = i
		break
zindex = -1
for i in range(0, len(S)):
	if S[-1-i] == 'Z':
		zindex = len(S)-1-i
		break
print(zindex-aindex+1)

Solution (Python):
s = input()

while True:
  for i, n in enumerate(s):
    if n == "A":
      inda = i
      break
  break

while True:
  for i, n in enumerate(s[::-1]):
    if n == "Z":
      indz = i
      break
  break

indz = len(s) - indz - 1
print(indz - inda + 1)

Solution (Python):
s = list(input())

res = 0
count = 0
for i in range(len(s)):
    if s[i] == 'A':
        for j in range(i, len(s)):
            count = count + 1
            if s[j] == 'Z':
                res = max(res, count)
        break

print(res)

Solution (Python):
st =input()
ai = st.find('A')
zi = st.rfind('Z')
print(zi - ai + 1)

Solution (Python):
a = input()
for i in range(len(a)):
    if a[i] == "A":
        for j in range(len(a)-1, -1, -1):
            if a[j] == "Z":
                print(j-i+1)
                exit()

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

Solution (Python):
s = input()

a = s.index("A")
z = s.rindex("Z")

print(str(z - a + 1))

Solution (Python):
s = input()
min_A = 200000
max_Z = 0
flag_A = False
for i in range(len(s)):
    if(flag_A==False and s[i] == 'A'):
        flag_A = True
        min_A = i
    if(s[i] == 'Z'):
        max_Z = i
print(max_Z-min_A + 1)

Solution (Python):
s = input()
idx_a = s.index('A')
idx_z = len(s) - s[::-1].index('Z')
print(idx_z - idx_a)

Solution (Python):
s=input()
a=min([i for i, x in enumerate(s) if x == "A"])
z=max([i for i, x in enumerate(s) if x == "Z"])
print(z-a+1)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    x = II()
    if x < 1200:
        print("ABC")
    else:
        print("ARC")
    return


def B():
    s = S()
    a = inf
    z = 0
    for num,si in enumerate(s):
        if si == "A":
            a = min(a, num)
        if si == "Z":
            z = max(z, num)
    print(z-a+1)
    return


def C():
    return


def D():
    return


if __name__ == '__main__':
    B()

Solution (Python):
s=input()
a=[]
z=[]
for i in range(len(s)):
	if s[i]=="A":
		a.append(i)
	if s[i]=="Z":
		z.append(i)
print(max(z)-min(a)+1)

Solution (Python):
s = input()

for i in range(len(s)):
  if s[i] == 'A':
    a = i
    break

for i in range(len(s)-1, -1, -1):
  if s[i] == 'Z':
    z = i
    break

print(z-a+1)

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(s: str):
    l, r = -1, -1
    for i, c in enumerate(s):
        if c == 'A' and l < 0:
            l = i
        if c == 'Z':
            r = i
    ret = r - l + 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
print(s.rfind('Z')-s.find('A')+1)

Solution (Python):
s = list(input())
start = s.index('A')
end = len(s) - s[-1::-1].index('Z')
print(end - start)

Solution (Python):

S = list(input())

for i in range(len(S)):
    if S[i] == 'A':
        start = i
        break
for j in range(len(S)-1, -1, -1):
    if S[j] == 'Z':
        end = j
        break
print(end - start+1)

Solution (Python):
s=input()
n=len(s)
a=[]
z=[]
for i in range(n):
    if s[i]=="A":
        a.append(i)
    elif s[i]=="Z":
        z.append(i)
print(max(z)-min(a)+1)

Solution (Python):
s=input()
a=s.find("A")
b=s.rfind("Z")
print(b+1-a)

Solution (Python):
S = list(input())
s = 0
f = 0
n = len(S)
for i in range(n):
    if S[i] == 'A':
        s = i
        break
for j in range(0, n)[::-1]:
    if S[j] == 'Z':
        f = j+1
        break

print(f-s)

Solution (Python):
a = input()
print(-a.index("A") + a.rindex("Z") + 1)

Solution (Python):
s = input()
left = -1
for i in range(len(s)):
    if s[i] == "A" and left == -1:
        left = i
    elif s[i] == "Z":
        right = i
print(len(s[left:right+1]))

Solution (Python):
s = input()

i = s.find('A')
j = s[::-1].find('Z')

print(len(s) - j - i)

Solution (Python):
def main():
    s=list(input())
    s_rev = reversed(s)
    h = 0
    t = -1
    for num,i in enumerate(s):
        if i =='A':
            h = num
            break
    for num,i in enumerate(s_rev):
        if i == 'Z':
            t = len(s)-num
            break
    print(t-h)
if __name__ == '__main__':
    main()

Solution (Python):
s = [i for i in input()]
index_Z = [i for i, x in enumerate(s) if x == 'Z']

print(max(index_Z) - s.index('A') + 1)

Solution (Python):

s = input()

lis = list(s)
lis.reverse()

rs = "".join(lis)

ans = len(s)


for i in range(len(s)):

    if s[i] == "A":

        ans -= i
        break

for i in range(len(rs)):

    if rs[i] == "Z":

        ans -= i
        break

print (ans)

Solution (Python):
s=input()
begin=s.index('A')
end=s.rindex('Z')
print((end+1)-begin)

Solution (Python):
s = input()
a = s.find("A")
b = s.rfind("Z")
print(b - a + 1)

Solution (Python):
X = str(input())

A_list = []
Z_list = []

for i in range(len(X)):
  if X[i] == 'A':
    A_list.append(i)
  if X[i] == 'Z':
    Z_list.append(i)

print(int(Z_list[-1] - A_list[0] + 1))

Solution (Python):
s = input()
print(len(s) - s.index('A') - s[::-1].index('Z'))

Solution (Python):
s=input()
t=[2000000,-2000000]
for i in range(len(s)):
    if s[i]=="A":
        t[0]=min(t[0],i)
    if s[i]=="Z":
        t[1]=max(t[1],i)
print(t[1]-t[0]+1)

Solution (Python):
import re


s = str(input())

pattern = r"A.*Z"

X = re.search(pattern, s)

print(len(X.group()))

Solution (Python):
s = str(input())
for i in range(len(s)) :
    if s[i] == 'A' :
        leftCnt = i
        break
for i in range(len(s)) :
    if s[-1-i] == 'Z' :
        rightCnt = len(s) - i
        break
print(rightCnt - leftCnt)

Solution (Python):
import sys, re
input = sys.stdin.readline

pattern = re.compile('A.*Z')
ans = 2 ** 18

s = input()

for m in pattern.findall(s):
  length = len(m)
  if length < ans:
    ans = length
    
print(ans)

Solution (Python):
s = input()

start = s.index('A')
end = s[::-1].index('Z')
print(len(s) - end - start)

Solution (Python):
s=input()
a=s.find("A")
z=s[::-1].find("Z")
print(len(s)-a-z)