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-----
QWERTYASDFZXCV

-----Sample Output-----
5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Difficulty: introductory

Starter code:

Solutions:
s = input()
first_a_index = s.index('A')
last_z_index = len(s) - list(reversed(s)).index('Z')
print(last_z_index - first_a_index)

s = input()
start = len(s)
end = 0
ans = 0

for i in range(len(s)):
    if s[i] == 'A':
        start = min(start , i)
    if s[i] == 'Z':
        end = max(end, i)
    ans = end - start + 1
print(ans)

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
# mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
s = input()
A_idx = s.index('A')
Z_idx = s[::-1].index('Z')
ln = len(s)
print((ln - Z_idx - A_idx))


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

import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10**9)


def si(): return input()
def ii(): return int(input())
def fi(): return float(input())
def lstr(): return input().split()
def lint(): return list(map(int, input().split()))
def lint_dec(): return list(map(lambda x:int(x) - 1, input().split()))
def lnstr(n): return [input() for _ in range(n)]
def lnint(n): return [int(input()) for _ in range(n)]
def lint_list(n): return [lint() for _ in range(n)]



############################################################
t = si()
n = len(t)
for s in range(n):
    if t[s] == 'A':
        break

for e in range(n - 1, -1, -1):
    if t[e] == 'Z':
        break

print(e - s + 1)

s=input()
S=len(s)
mi=[]
ma=[]
for i in range(S):
    if s[i]=='A':
        mi.append(i)
    elif s[i]=='Z':
        ma.append(i)
print(max(ma)-min(mi)+1)

import sys

min_a_index, max_z_index = sys.maxsize, 0

for index, c in enumerate(list(input())):
    if c == "A" and index < min_a_index:
        min_a_index = index
    if c == "Z" and index > max_z_index:
        max_z_index = index

print((max_z_index - min_a_index + 1))


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

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

print(z-a+1)

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

s = input()
a = len(s)
z = 0
for i,e in enumerate(reversed(s)):
  if e == "A":
    a = len(s) - i -1 
for i,e in enumerate(s):
  if e == "Z":
    z = i

print(z-a+1)

s = input()

first_index = s.index('A', 0)
last_index = 0

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

print(last_index - first_index + 1)

import math
# s=int(input())
b=input()
c=[]
for i in b:
    c.append(i)
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))

a1=c[c.index("A"):]
a2=[i for i, x in enumerate(a1) if x=="Z"]
print(len(a1[:a2[-1]+1]))

a=input()
for i in range(len(a)):
    if(a[i]=='A'):
        b=i
        break
for j in range(len(a)-1,-1,-1):
    if(a[j]=='Z'):
        c=j
        break
print((c-b+1))


s = list(input())

for i,j in enumerate(s):
    if j == 'A':
        a = i
        break
for i,j in enumerate(s):
    if j == 'Z':
        z = i
print(z-a+1)

s=input()
n=len(s)
t=[]
for i in range(n):
  t.append(s[n-1-i])
a=s.index('A')
z=t.index('Z')
print(n-z-a)

n = input()
a = n.find("A")
z = n.rfind("Z")
print(z-a+1)

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    S = input()
    search_string=['A','Z']
    position=[]

#Aを探す
    for i,s in enumerate(S):
        if s==search_string[0]:
            position.append(i)
            break

#Zを探す
    for r_i,r_s in enumerate(reversed(S)):
        if r_s==search_string[1]:
            position.append(len(S)-r_i)
            break

    print(position[1]-position[0])

def __starting_point():
    main()
__starting_point()

S=input()
left=0
while S[left]!='A':
    left+=1
right=len(S)-1
while S[right]!='Z':
    right-=1
print((right-left+1))


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

def resolve():
    """「A*Z」という文字列で最長の長さを出力する
    = 一番左のAと一番右のZでできる文字列
    """
    s = input()
    start_index = s.index("A")
    end_index = s.rindex("Z")
    output = end_index - start_index + 1
    print(output)

resolve()

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

s = input()
sta = []
fin = []
for i in range(len(s)):
    if s[i] == 'A':
        sta.append(i)
    elif s[i] == 'Z':
        fin.append(i)
print(max(fin)-min(sta)+1)

s = input()

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

for j, x in enumerate(s[::-1]):
    if x == "Z":
        break

print((len(s) - i - j))


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

s = str(input())
strFindA = ''
strFindZ = ''

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

for i in reversed(range(len(strFindA))):
  if strFindA[i] == "Z":
    strFindZ = strFindA[:i+1]
    break

print(len(strFindZ))

def main():
    s = input()
    start = 200000
    end = 0
    for i in range(len(s)):
        if s[i] == 'A' and start > i:
            start = i
        elif s[i] == 'Z' and end < i:
            end = i
    print(end - start + 1)



def __starting_point():
    main()
__starting_point()

s = input()

first = s.index('A')
end = s.rindex('Z')

ans = end - first + 1
print(ans)

s = input()

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

import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: list(map(int, sys.stdin.readline().split()))
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
left = s.index('A')
right = s.rindex('Z')
print((right-left+1))















s = input()
n = len(s)
a = 0
z = n - 1

for i in range(n):
    if s[i] == "A":
        a = i
        break

for i in range(n):
    if s[i] == "Z":
        z = i

print((z - a + 1))


s = input()

f = s.find('A')
l = len(s) - s[::-1].find('Z')
print(l - f)

import sys
input = sys.stdin.readline


def read():
    s = input().strip()
    return s,


def solve(s):
    a, z = 0, len(s)-1
    while s[a] != "A":
        a += 1
    while s[z] != "Z":
        z -= 1
    return z-a+1


def __starting_point():
    inputs = read()
    print((solve(*inputs)))

__starting_point()

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

s = input()

def first_A(s):
  for i in range(len(s)):
    if s[i] == "A":
      return i
    
def last_Z(s):
  for i in range(len(s)):
    if s[-(i+1)] == "Z":
      return -(i+1)+len(s)
    
print(last_Z(s) - first_A(s) + 1)

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

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

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

print(en - st + 1)

a = input()
for i in range(len(a)):
    if a[i] == "A":
        b = i
        break
for j in range(len(a)):
    if a[j] == "Z":
        c = j
print((c-b+1))


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

s=input()
b=s.index("A")
a=[i for i, x in enumerate(s) if x == 'Z']
print(a[-1]-b+1)

s = input()
a_number = 0
z_number = 0

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

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

print(z_number - a_number + 1)

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


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

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

retu = input()
kari = 0
flag = False
for i in range(len(retu)):
    if flag:
        kari += 1
        if retu [i] == 'Z':
            an = kari
    elif retu[i] == 'A':
        flag = True
        kari += 1
print(an)

s=list(input())
for i in range(len(s)):
  if s[i]=="A":
    start=i
    break
for j in reversed(range(0,len(s))):
  if s[j]=="Z":
    last=j
    break
print(last-start+1)

#53 B
data=list(input())
i=0
j=1
while data[i]!='A':
    i=i+1
while (data[-j]!='Z' and len(data)-j>i):
    j=j+1
print(len(data)-i-j+1)

s=input()
x=s.find('A')
s2=s[x:]
y=s.rfind('Z')
print(y-x+1)

S = input()
s_list = []
for n in S:
    s_list.append(n)

a = (s_list.index("A"))+1

s_list.reverse()
z = (-(s_list.index("Z")+1))

print(len(S[a:z])+2)

s = input()
size = len(s)
for i in range(size):
    if s[i] == 'A':
        head = i
        for j in range(size):
            if s[-1-j] == 'Z':
                tail = j 
                break
        break 
print(size-head-tail)

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

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


s = input()

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


S = input()
N = len(S)
a = 1
z = 1
for i in range(N):
    if S[i] == "A":
        break
    else:
        a += 1

for j in range(1, N+1):
    if S[-j] == "Z":
        break
    else:
        z += 1
ans = N - a - z + 2
print(ans)

def main():
    s = input()
    a = len(s); z = 0
    for i, t in enumerate(s):
        if t == 'A':
            a = min(a, i)
        if t == 'Z':
            z = max(z, i)
    ans = z-a+1
    print(ans)

def __starting_point():
    main()

__starting_point()

s = input()

ind_A = 0
while s[ind_A] != 'A':
    ind_A += 1
ind_Z = len(s)
while s[ind_Z - 1] != 'Z':
    ind_Z -= 1

print(ind_Z - ind_A)

a=input()
b=a[::-1]
p=0

for i in range(len(a)):
  if a[0] !='A':
    a=a[1:]
  else:
    break
    
for i in range(len(a)):
  if a[-1] !='Z':
    a=a[:-1]
  else:
    break
    
    
print(len(a))

s = input()

print((s.rindex('Z') - s.index('A') + 1))


s = input()
a_idx = None
for i, c in enumerate(list(s)):
    if c == 'A':
        a_idx = i
        break
z_idx = None
for i, c in enumerate(reversed(list(s))):
    if c == 'Z':
        z_idx = len(s) -i
        break
print(len(s[a_idx:z_idx]))

import re
s = input()
smax=0
res = re.search(r"A[A-Z]*Z",s)
print(len(res.group()))

S = input()

left = -1

for i,s in enumerate(S):
    if s == 'A':
        left = i
        break

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

if left < right:
    print(right-left+1)

s = input()
start = 0
goal = 1
while s[start] != "A":
  start += 1
while s[-goal] != "Z":
  goal += 1
print(len(s)-goal-start+1)

s = input()
x = s.find('A')
y = s.rfind('Z')
print(y-x+1)

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

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

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,-1,-1):
    if s[i]=="Z":
        z = i 
        break 
print(z-a+1)

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


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

s = list(input())
s_inv = list(reversed(s))
a = s.index('A')
b = s_inv.index('Z')
print(len(s)-a-b)

s = input()

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

s = input()

first_A_find = s.find("A")
end_Z_find = s.rfind("Z") + 1

print(end_Z_find - first_A_find)

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

s = input()
a, z = len(s), 0
for i in range(len(s)):
    if s[i] == 'A':
        a = min(i, a)
    elif s[i] == 'Z':
        z = max(i, z)

print(z-a+1)

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

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

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

s=list(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)

s = list(input())
t = s.copy()
t.reverse()
print(len(s)-t.index("Z")-s.index("A"))

s = input()

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

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

def answer(s: str) -> int:
    return s.rfind('Z') - s.find('A') + 1


def main():
    s = input()
    print((answer(s)))


def __starting_point():
    main()

__starting_point()

a=input()
for i in range(len(a)):
  if a[i]=="A":
    b=i
    break
for k in range(len(a)):
  if a[-k-1]=="Z":
    c=k
    break
print(len(a)-c-b)

s = input()
st = s.find("A")
for i in range(len(s)):
  n = len(s)-i-1
  t = s[n]
  if t == "Z":
    en = n
    break
print((en - st + 1))


s = input()

max_len = 0
past = -1
for i in range(len(s)):
    if s[i] == 'A' and past == -1:
        past = i
        continue
    if s[i] == 'Z':
        max_len = max(max_len, i - past + 1)

print(max_len)


s = input()
n = len(s)
first, last = 0,0

for i in range(n):
  b,f = i+1, n-i
  if s[-1-i] == 'A':
    first = f
  if s[i] == 'Z':
    last = b

# print(first, last)
print((last - first+1))


s = input()

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

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

print(len(s) - end - start + 1)

s = list(input())

while s[0] != 'A' or s[-1] != 'Z':
    if s[0] == 'A':
        s.pop()
    elif s[-1] == 'Z':
        s.pop(0)
    else:
        s.pop(0)
        s.pop()

print(len(s))

#!/usr/bin/env python3
import sys


def solve(s: str):
    A = min((i for i, c in enumerate(s) if c == "A"), default=len(s))
    Z = max((i for i, c in enumerate(s) if c == "Z"), default=0)
    return max(0, Z - A + 1)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    print((solve(s)))

def test():
    import doctest
    doctest.testmod()

def __starting_point():
    #test()
    main()

__starting_point()

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

s = input()
ans = ["",""]
for i in range(len(s)):
    if s[i] == "A" and ans[0] == "":
        ans[0] = i+1
    if ans[0] != "" and s[i]=="Z":
        ans[1] = i+1
print(ans[1]-ans[0]+1)

s=str(input())
for i in range(len(s)):
  if s[i]=="A":
    a=i
    break
t=s[::-1]
for j in range(len(s)):
  if t[j]=="Z":
    b=j
    break

print(len(s)-a-b)

#!/usr/bin/env python3
import sys


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

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    print((solve(s)))

def test():
    import doctest
    doctest.testmod()

def __starting_point():
    #test()
    main()

__starting_point()

s = input()

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

print(b - a + 1)

s = input()
front = s.find("A")
back = s.rfind("Z")
print(back+1 - front)

s = str(input())
a = len(s)
z = 0
for i in range(len(s)):
    if s[i] == 'A':
        a = min(a, i)
    if s[i] == 'Z':
        z = max(z, i)

print((z - a + 1))



s = input()

i = s.find("A")
j = s.rfind("Z")

print(j + 1 - i)

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

s = input()

first_index = s.index('A', 0)
last_index = 0
for i, ss in enumerate(s):
    if ss == 'Z':
        last_index = i

print(last_index - first_index + 1)

s = input()
n = len(s)

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

s = input()

first = s.find("A")
end = s.rfind("Z")

length = end - first + 1
print(length)