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()

slist = list(s)

aindex = slist.index("A")

slist.reverse()
zindex = slist.index("Z")

length = len(slist) - aindex - zindex
print(length)

Solution (Python):
s = input()

A_index = s.index("A")

for i in range(len(s)):
    if s[i] == "Z":
        Z_index = i

print(Z_index - A_index + 1)

Solution (Python):
import sys
input = sys.stdin.readline
s=input().strip()
for i in range(len(s)):
    if s[i]=="A":
        sa=i
        break
for i in range(len(s)):
    if s[i]=="Z":
        sz=i
print(len(s[sa:sz+1]))

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

Solution (Python):
s=input()
l=len(s)
for i in range(l):
  if s[i]=="A":
    flga=i
    break
for i in range(l):
  if s[i]=="Z":
    flgz=i

print(flgz-flga+1)

Solution (Python):
string = input()

start = -1
end = -1
for i, s in enumerate(string):
	if start == -1 and s == 'A':
		start = i
	if s == 'Z':
		end = i

print(end - start + 1)

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

print(z-a)

Solution (Python):
s = input()
cnt = 0
st = 0
ans = 0

for c in s:
    if c == "A": 
        st = 1
    if st == 1: 
        cnt += 1
        if c == "Z": 
            ans = cnt

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
s = input().rstrip()
s_rev = s[::-1]
mina = -1
maxz = -1
for i in range(len(s)):
    if s[i] == "A":
        mina = i
        break
for j in range(len(s)):
    if s[j] == "Z":
        maxz = max(maxz, j)
print(maxz - mina + 1)

Solution (Python):
s = input()

A_id = -1
Z_id = -1


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

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

print(Z_id - A_id + 1)

Solution (Python):
S = input()

a = 0
z = 0

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

Solution (Python):
s = input()

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

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

Solution (Python):
s = input()

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

print(z-a+1)

Solution (Python):
s = input()


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

Solution (Python):
s = list(input())
count_max = 0
count_on = False
for i in range(len(s)):
    if count_on != True and s[i]=="A" :
       count_stt = i
       count_on = True
    if count_on == True and s[i]=="Z" :
        count_end = i
print(count_end - count_stt+1)

Solution (Python):
import re

s = input()

pattern = r'A.+Z'

res = re.findall(pattern,s)

print(len(res[0]))

Solution (Python):
s=input()
i=0
while(s[i]!='A'):
    i+=1
j=len(s)-1
while(s[j]!='Z'):
    j-=1
print(j+1-i)

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

Solution (Python):
s = input()
for i in range(len(s)):
    if s[i] == 'A':
        a_index = i
        break

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

print(z_index - a_index + 1)

Solution (Python):
s=input()

A = -1
Z = 0

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

print((Z - A) + 1)

Solution (Python):
s = input()

a = 0
z = 0

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

Solution (Python):

import re

s = input()
res = re.search('A.*Z', s)
print(len(res.group()))

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

Solution (Python):
s = input()
index_a = 0
index_z = -1
for i in range(len(s)):
  if s[i] == 'A':
    index_a = i
    break
    
for i in reversed(range(len(s))):
  if s[i] == 'Z':
    index_z = i
    break

print(index_z - index_a + 1)

Solution (Python):
s = input()

a = -1
z = -1
for i in range(0, len(s)):
   if (a < 0 and s[i] == 'A'):
      a = i
   elif (s[i] == 'Z'):
      z = i

if (a >= 0 and z >= 0):
   print(z - a + 1)
else:
   print(0)

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

x = []

for i in range(n):
    if 'A' not in x and s[i] is 'A':
        x.append(i)
        x.append('A')
    elif 'A' in x and s[i] is 'Z':
        x.append(i)

print(x[-1] - x[0] + 1)

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

Solution (Python):
s = str(input())
Alst = []
Zlst = []
for i in range(len(s)):
    if s[i]=='A':
        Alst.append(i)
    elif s[i]=='Z':
        Zlst.append(i)
print(max(Zlst)-min(Alst)+1)

Solution (Python):


s = input()

first = len(s)
last = 0
for i in range(0, len(s)):
    if s[i] == "A":
        first = min(first, i)
    if s[i] == "Z":
        last = max(last, i)

print(len(s[first:last+1]))

Solution (Python):



S = input()

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

Solution (Python):
s = input()
n = len(s)
ans = 0
for i in range(n):
    if s[i] == 'A':
        ans -= i

        break

for j in reversed(range(0, n)):
    if s[j] == 'Z':
        ans += j
        break

print(ans + 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
print(len(re.search(r"A.*Z",input()).group()))

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

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

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

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

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

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

print(tmp[1]-tmp[0]+1)

Solution (Python):
s=list(input())
a=s.index('A')+1
s.reverse()
b=len(s)-s.index('Z')

print(b-a+1)

Solution (Python):

s=input()
a=0
z=0
flag=True
for i in range(len(s)):
    if flag:
        if s[i]=="A":
            a=i
            flag=False
    if s[i]=="Z":
        z=i
ans=len(s[a:z+1])
print(ans)

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

Solution (Python):
S = list(input())
num_first = 0
num_last = 0
for i in range(len(S)):
    if S[i] == 'A':
        num_first = i
        break
for j in range(len(S)):
    if S[j] == 'Z':
        num_last = j
print(num_last - num_first + 1)

Solution (Python):
S = list(input())
num_first = 0
num_last = 0
for i in range(len(S)):
    if S[i] == 'A':
        num_first = i
        break
S.reverse()
for j in range(len(S)):
    if S[j] == 'Z':
        num_last = len(S) - j
        break
print(num_last - num_first)

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

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

count = 0
count_temp = 0
A_index = S.index("A")

for i in range(A_index, len(S), 1):
    count_temp = count_temp + 1

    if S[i]=="Z":
        count = count_temp
        continue
print(count)

Solution (Python):
s=input()

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

Solution (Python):
s=list(input())
r=list(reversed(s))
acon=0
zcon=0
for i in range(len(s)):
  if s[i]=="A":
    break
  else:
    acon+=1
for i in range(len(s)):
  if r[i]=="Z":
    break
  else:
    zcon+=1
print(len(s)-(acon+zcon))

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

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

Solution (Python):
s = input()

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

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

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

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

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

Solution (Python):

s = str(input())
start = s.find('A')
last = s.rfind('Z')

print(last - start + 1)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
minans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Solution (Python):
S=input()
ans=0
cnt=0
flg=False
for s in S:
    if s=="A":
        cnt+=1
        flg=True
        continue
    elif s=="Z" and flg:
        cnt+=1
        ans=cnt
        continue
    
    if flg:
        cnt+=1
print(ans)

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

Solution (Python):
import re
s= input()
ans = re.findall(r"A[A-Z]*Z",s)
print(len(max(ans)))

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)):
  if s[-(i+1)] == 'Z':
    end = len(s)-i
    break
print(end - start)

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

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

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

Solution (Python):
from fractions import gcd

from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7



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


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
start = 0
end = 0
flag = 0
for i in range(len(s)):
    if s[i] == 'A' and flag == 0:
        start  = i
        flag += 1
    if s[i] == 'Z':
        end = i

ans = s[start:(end+1)]
print(len(ans))

Solution (Python):
s = input()
index_A = float('inf')
index_Z = float('inf')
for i in range(len(s)):
    if s[i] == 'A':
        index_A = i
        break

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

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

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

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

Solution (Python):

s = input()

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

print(z-a+1)

Solution (Python):
s = input()

print(len(s) - list(reversed(list(s))).index('Z') - s.index('A'))

Solution (Python):
s = input()

for i in range(len(s)):
  if s[i] == 'A':
    f = i
    break
for i in range(len(s)):
  if s[i] == 'Z':
    e = i
    
print(e-f+1)

Solution (Python):
import sys

s = sys.stdin.readline().rstrip()

def main():
    a = s.index('A')
    z = len(s) - (s[::-1].index('Z') + 1)
    return z - a + 1

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

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

Solution (Python):
s = input()
right = 0
left = 0
for i in range(len(s)):
 if(s[i] == "A"):
  right = i
  break
 
for i in range(len(s)):
 if(s[i] == "Z"):
  left = i

print(left - right + 1)

Solution (Python):
s = input()
a = s.index("A")
z = s.rfind("Z")

print(z-a+1)

Solution (Python):
w=input()
first_A=None
last_Z=None
for i,v in enumerate(w):
    if v=="A" and first_A is None:
        first_A=i
    if v=="Z":
        last_Z=i
print(last_Z-first_A+1)

Solution (Python):
s = input()

start = s.find('A')
end = s.rfind('Z')

print(end - start + 1)

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

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

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

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

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

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

Solution (Python):
s = input()

pos_A = s.find("A")
pos_Z = s.rfind("Z")

print(pos_Z - pos_A + 1)

Solution (Python):
S = input()

first_A = None
last_Z = None

for i, c in enumerate(S):
    if c == 'A' and first_A is None:
        first_A = i
    elif c == 'Z':
        last_Z = i

print((last_Z - first_A) + 1)

Solution (Python):
s = input()

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

Solution (Python):
s = input()

first_a = s.find("A")
last_z = s.rfind("Z")

print(last_z - first_a + 1)

Solution (Python):

s=input()
s_num=s.find('A')
f_num=s.rfind('Z')
print(f_num-s_num+1)

Solution (Python):
line = list(input())
count = len(line)
start = 0
for i in range(count):
  if line[i] == "A":
    start = i
    break

stop = 0
for j in range(count -1,0,-1):
  if line[j] == "Z":
    stop = count -1 - j
    break
    
answer = count - start - stop
print(answer)

Solution (Python):
s = input()
start = s.find('A')
end = s.rfind('Z')

ans = end - start +1
print(ans)

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

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

Solution (Python):

s = input()
a = 0
z = 0
while True:
  a = s.find("A")
  z = s.rfind("Z")
  if s[a:z+1][0] == "A" and s[a:z+1][-1] == "Z":
    break
print(z - a + 1)

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

Solution (Python):
import re

s = input()

result = re.search(r"A.*Z", s)
print(len(result.group(0)))

Solution (Python):
[print(len(string) - string[::-1].index("Z") - string.index("A")) for string in [input()]]

Solution (Python):
s = input()

ai = s.index('A')
zi = s[::-1].index('Z')
l = len(s)

print(l - zi - ai)

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()
a_head = 0
z_tail = -1
for i in range(len(s)):
    if s[i] == "A":
        a_head = i
        break
for i in range(len(s), 0, -1):
    if s[i - 1] == "Z":
        z_tail = i
        break
print(z_tail - a_head)

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

a_num = -1
z_num = -1

for i in range(len(s)):
    if list_s[i] == "A":
        a_num = i
        break

for j in range(len(s)):
    if list_s[j] == "Z":
        z_num = j

print(z_num - a_num + 1)

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

a_num = len(s)
z_num = -1

for i in range(len(s)):
    if list_s[i] == "A":
        if a_num > i:
            a_num = i

    if list_s[i] == "Z":
        z_num = i

print(z_num - a_num + 1)

Solution (Python):
S = input()

head = [i for i in range(0, len(S)) if S[i]=="A"]
tail = [i for i in range(0, len(S)) if S[i]=="Z"]

print(max(tail)-min(head)+1)

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

Solution (Python):
s = input()

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

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

print(last - first+1)

Solution (Python):
s = input()

for i , v in enumerate(s):
    if v == 'A':
        apos = i + 1
        break

for i , v in enumerate(s[::-1]):
    if v == 'Z':
        zpos = len(s) - i 
        break

print( zpos - apos + 1)

Solution (Python):
s = input()

for i , v in enumerate(s):
    if v == 'A':
        apos = i + 1
        break

for i , v in enumerate(s[::-1]):
    if v == 'Z':
        zpos = len(s) - i 
        break

print( zpos - apos + 1)

Solution (Python):
s = input()

for i, v in enumerate(s):
    if v == "A":
        a_pos = i
        break

for i, v in enumerate(s[::-1]):
    if v == "Z":
        z_pos = len(s) - i
        break

print(z_pos - a_pos)

Solution (Python):
s = input()

found_a = False
high = 0
low = 0

for index, word in enumerate(s):
    if found_a == False:
        if word == 'A':
            low = index
            found_a = True
    if word == 'Z':
        high = index

print(high - low + 1)

Solution (Python):
s=input()
u=10**9
p=0
for i in range(len(s)):
    if s[i]=='A':
        u=min(u,i)
    elif s[i]=='Z':
        p=max(p,i)
print(p-u+1)

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

Solution (Python):
from sys import stdin

s = stdin.readline().rstrip()
frag = 0
for i in range(len(s)):
    if s[i] == "A" and frag == 0:
        first = i
        frag = 1
    if s[i] == "Z":
        last = i
print(last-first+1)

Solution (Python):
S = input()
print(S.rindex("Z") - S.index("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()
st=0
ed=0
for i,word in enumerate(s):
    if word == "A":
        st = i
        break
for i,word in enumerate(reversed(s)):
    if word == "Z":
        ed = len(s)-i
        break
print(ed-st)

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

Solution (Python):
s=input()
rev_s = ''.join(list(reversed(s)))
for ind,moji in enumerate(s):
    if(moji=='A'):
        start=ind
        break
for ind,moji in enumerate(rev_s):
    if(moji=='Z'):
        end=ind
        break
print((len(s)-end)-start)

Solution (Python):
S = input()
start = 0
start_check = False
end = 0
for idx, val in enumerate(S):
    if val == "A" and not start_check:
        start = idx
        start_check = True
    elif val == "Z":
        end = idx

print(end - start + 1)

Solution (Python):
s = str(input())
l = -1
r = -1
for i in range(len(s)):
    if (s[i]=='A')&(l==-1):
        l=i
    if (s[len(s)-1-i]=='Z')&(r==-1):
        r=len(s)-1-i
    if (r>=0)&(l>=0):
        break
print(r-l+1)

Solution (Python):


import re

s=input()
m=re.search("A.*Z",s)
print(m.end()-m.start())

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    idx1 = S.index("A")
    S_r = S[::-1]
    idx2 = S_r.index("Z")
    idx2 = len(S) - 1 - idx2
    print(idx2-idx1+1)
if __name__ == '__main__':
    main()

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

Solution (Python):
s = input()
a = len(s)
b = 0
for x,i in enumerate(s):
  if i == "A":
    a = min(a,x)
  elif i == "Z":
    b = max(b,x)
print(b-a+1)

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

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = list(inputs[0])
    N = len(S)
    start = None
    for i in range(N):
        if S[i] == 'A':
            start = i
            break
    end = None
    for i in reversed(range(N)):
        if S[i] == 'Z':
            end = i
            break
    return end - start + 1


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Solution (Python):

s = input()

a = s.find("A")
b = s.rfind("Z")

print(b - a + 1)

Solution (Python):
s = input()

a_index = -1
z_index = 0
for i in range(len(s)):
    if s[i] == 'A' and a_index == -1:
        a_index = i
    elif s[i] == 'Z':
        z_index = i

print(z_index-a_index+1)

Solution (Python):
s = input()

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

Solution (Python):
s = input()
start = 0
stop = 0
flg = True
for i in range(len(s)):
    if s[i] == 'A' and flg:
        start = i
        flg = False
    if s[i] == 'Z':
        stop = i
print(stop-start+1)

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

Solution (Python):
s = input()

k = -1
t = -1

for i in range(len(s)):
	if s[i]=='A':
		if k < 0:
			k = i
	elif s[i]=='Z':
		if i > t:
			t = i
print(t-k+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
az = S[a:z]
print(len(az)+1)

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

Solution (Python):
line = input()
a = []
z = []
for i in range(len(line)):
    if line[i] == "A":
        a.append(i)
    elif line[i] == "Z":
        z.append(i)

print(z[-1] - a[0] + 1)

Solution (Python):
s = input()
bl = False
for i in range(len(s)):
    if s[i] == "A" and bl == False:
        cnt = 1
        bl = True
        continue
    if bl == True:
        cnt += 1
        if s[i] == "Z":
            ans = cnt
print(ans)

Solution (Python):
def main(s):
    head, tail = 0, 0

    for _s in s:
        if _s == 'A':
            break

        head += 1

    for _s in s[::-1]:
        if _s == 'Z':
            break

        tail += 1

    print(len(s) - (head + tail))


if __name__ == '__main__':
    s = input()

    main(s)

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

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

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

Solution (Python):
import re
m = input()
m_az = re.search("A.*Z", m)
print(len(m_az.group(0)))

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

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

print(Z-A)

Solution (Python):
string = input()
a_idx = 10e9
z_idx = 0
for i, char in enumerate(string):
    if (char == "A") & (i < a_idx):
        a_idx = i
    if (char == "Z") & (i > z_idx):
        z_idx = i

print(z_idx - a_idx + 1)

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

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

Solution (Python):

s = input()
judge_a = 0
judge_z = 0
a = 0
z = 0

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

print(z-a)

Solution (Python):
s = input()

start = None
for i, a in enumerate(s):
    if a == 'A':
        start = i if start is None else start
    if a == 'Z':
        end = i
print(end - start + 1)

Solution (Python):
import sys
s = input()
st=0
e=0
max=0
f=False
for i in range(len(s)):
    if s[i] == "A":
        st = i
        break

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

print(e-st+1)

Solution (Python):
import re
s=input()
rev=s[::-1]

start=0
end=0
for ind,i in enumerate(s):
    if(i=='A'):
        start=ind
        break

for ind,i in enumerate(rev):
    if(i=='Z'):
        end=len(s)-ind
        break

print(end-start)

Solution (Python):
def main():
  s = list(input())
  start = -1
  end = -1
  for i, c in enumerate(s):
    if start == -1 and c == 'A':
      start = i
    if start != -1 and c == 'Z' and end < i:
      end = i
  print(end - start + 1)

main()

Solution (Python):
s = list(str(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 + 1
    break
    
print(z - a)

Solution (Python):

import sys
input = sys.stdin.readline


S = input().rstrip()

ai = S.find("A")
zi = S.rfind("Z")

print(zi-ai+1)

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

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

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

Solution (Python):
s=input()
sento=2000000
matubi=0

for i in range(len(s)):
  if s[i] == "A":
    sento=min(i,sento)
for i in range(len(s)):
  if s[i] == "Z" and i > sento:
    matubi=max(i,matubi)
print(matubi-sento+1)

Solution (Python):
A = input()
count = 0
p = len(A)
min_=200000
max_=0
for i in range(p):
  if (A[i] == 'A'):
    min_ = min(i,min_)
  if (A[i] == 'Z'):
    max_ = max(i,max_)
print(max_-min_+1)

Solution (Python):
def examB():
    s = S()
    for i,j in enumerate(s):
        if j=="A":
            right = i
            break
    for i,j in enumerate(s[::-1]):
        if j=="Z":
            left = i
            break
    ans = len(s)-right-left
    print(ans)


import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

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

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

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

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

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

Solution (Python):

s = input()
s_dash = s[::-1]

print(len(s) - s.index('A') - s_dash.index('Z'))

Solution (Python):

s = input()
s_dash = s[::-1]

print(len(s) - s.index('A') - s_dash.index('Z'))

Solution (Python):
S = input()
posA = -1 
posZ = -1
for i in range(len(S)):
    if S[i] == 'A' and posA == -1:
        posA = i
    if S[i] == 'Z':
        posZ = i
print(posZ-posA+1)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def main():
    s = input()
    n = len(s)
    l = 0
    r = 0
    for i in range(n):
        if s[i] == 'A':
            l = i
            break
    for i in range(n)[::-1]:
        if s[i] == 'Z':
            r = i
            break
    print(r-l+1)
if __name__ == '__main__':
    main()

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

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

st = 0
ed = 0
for i in range(len(s)):
  if s[i] == "A":
    st = i
    break
for i in range(len(s)):
  if s[-i + len(s) -1] == "Z":
    ed = -i + len(s) - 1
    break
print(ed-st+1)

Solution (Python):


s = input()

sc = 0
ec = len(s)

for i in range(len(s)):
  if(s[i] == "A"):
    sc = i
    break

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

print(ec - sc + 1)

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

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

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

Solution (Python):
n = input()

a = 0
z = 0
for index, s in enumerate(n):
  if s == 'A':
    a = index
    break

for index, s in enumerate(n):
  if s == 'Z' and index > a:
    z = index

print(len(n[a:z+1]))