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

s_first = s.find("A")
s_last = s.rfind("Z")

print(s_last-s_first+1)

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

for i in range(size):
    if s[i] == 'A':
        aa = i
        break

for i in range(size):
    if s[size - 1 - i] == 'Z':
        zz = size - 1 - i
        break

print(zz - aa + 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)-1,-1,-1):
    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':
        formerkey=i
        break

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



print((latterkey+1)-(formerkey+1)+1)

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

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

Solution (Python):
s=input()
a_lst=[]
z_lst=[]
count =0
for i in s:
    count += 1
    if i=="A":
        a_lst.append(count)
    elif i=="Z":
        z_lst.append(count)
print(int(z_lst[-1]-a_lst[0])+1)

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

Solution (Python):
S = input()

i = S.index("A")
j = S.rindex("Z")

print(j + 1 - i)

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

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

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

switch = 0 
all = len(s)
aC = 0
bC = 0
ans = 0
aC = s.index('A')
s = s[::-1]
bC = s.index("Z")
ans = (all - bC) - aC

print(ans)

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

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

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

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

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) - z - a)

Solution (Python):
s = input()

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

Solution (Python):
S = input()
start_flag = False
z_count = S.count("Z")
start = 200001
end = 200001
for i in range(len(S)):
    if S[i] == "A" and start_flag == False:
        start_flag = True
        start = i
    elif S[i] == "Z":
        if z_count == 1 and start_flag == True:
            end = i
            break
        else:
            z_count -= 1
print(end-start+1)

Solution (Python):
s = input()

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

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

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

for i in s:
    if i == 'A':
        break
    start += 1

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

print(end - start)

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

Solution (Python):
string = input()
N = len(string)

for i in range(0,N):
	if(string[i] == "A"):
		a = i
		break

for i in range(0,N):
	if(string[N-1-i] == "Z"):
		z = N-1-i
		break

print(z - a + 1)

Solution (Python):
import sys


S = str(input())

L = len(S)
ans = ""
begin = L
end = 0
for i in range(L):
    if(S[i] == "A" and begin == L):
        begin = i
    elif(S[i] == "Z" and begin != L):
        end = i+1

print(end - begin)

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

Solution (Python):
a=list(input())
t=[]
for i in range(len(a)-1,-1,-1):
    t.append(a[i])
print(len(a)-t.index("Z")-a.index("A"))

Solution (Python):


s = input()

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

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': break
start = i

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

print(end-start+1)

Solution (Python):
s=input()
print(len(s[s.find('A'):s.rfind("Z")+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):
x = input()
print(x.rfind('Z')-x.find('A')+1)

Solution (Python):
S = input()

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

print(z-a+1)

Solution (Python):
S = str(input())
for i in range(len(S)):
    if S[i] == "A":
        start = i
        break
for i in range(len(S)):
    if S[len(S)-1-i]  == "Z":
        end = len(S)-i
        break
print(end-start)

Solution (Python):
[print(s.rfind('Z') - s.find('A') + 1) for s in [input()]]

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

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

Solution (Python):
ss = input()

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

Solution (Python):
s=input()

length=len(s)

flag1=0
flag2=0
for i in range(length):
  if s[i]=='A' and flag1==0:
    start=i
    flag1=1


for j in range(-1,start-length,-1):
  if s[j]=='Z' and flag2==0:
    end=j
    flag2=1
    
print(length-start+end+1)

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

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

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

Solution (Python):
s = input()

a = 0
for n, i in enumerate(reversed(s)):
    if i == "Z":
        a = len(s) - n
        break

b = 0
for n, i in enumerate(s):
    if i == "A":
        b = n
        break

print(a-b)

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

Solution (Python):
str_s = input()

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

Solution (Python):
import sys

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

Solution (Python):
S=input()
N=len(S)

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

Solution (Python):
s = list(input())
findA = 0
findZ = 0
ans = 0
ansz = 0
for i in range(len(s)):
    if(s[i] == 'A' and findA==0):
        ans = i
        findA+=1
    if(s[len(s) - i-1] == 'Z' and findZ==0):
        ansz = len(s)-i
        findZ+=1
print(ansz - ans)

Solution (Python):
s = input()
l = s.find("A")
r = s.rfind("Z")

print(r - l + 1)

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

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

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

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

Solution (Python):
s = input()
t = s[::-1]
rf = rb = 0 
for i in range(len(s)):
    if s[i] =="A":
        rf = i
        break
for i in range(len(s)):
    if t[i] =="Z":
        rb = len(s)-i-1
        break
print(rb-rf+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()
a_i = [i for i in range(len(s)) if s[i]=="A"]
z_i = [i for i in range(len(s)) if s[i]=="Z"]
print(max(z_i) - min(a_i) + 1)

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

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

    if flag == 1 and s[i] == 'Z':
        end = i
print(end - start + 1)

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

Solution (Python):
S = input()

a = S.find('A')
cnt = 1
for s in S[::-1]:
  cnt -= 1
  if(s == 'Z'):
    break
z = len(S) + cnt
print(len(S[a:z]))

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):
s = list(input())
min = 200000
max = 0

for i in range(len(s)):
    if s[i] == 'A':
        if min > i:
            min = i
    if s[-i] == 'Z' and i != 0:
        if max < len(s) - i:
            max = len(s) - i

print(max-min+1)

Solution (Python):




def atozString(dataStr) :

	rangeFirstToEnd = range(0,len(dataStr),1)
	rangeEndToFirst = range(len(dataStr)-1,-1,-1)
	firstA = 0
	lastZ = len(dataStr)
	for i in rangeFirstToEnd:
		if dataStr[i] == 'A':
			firstA = i
			break

	for i in rangeEndToFirst:
		if dataStr[i] == 'Z':
			lastZ = i
			break

	answerInt = lastZ-firstA+1
	return answerInt


if __name__ == '__main__':
	inputLine = input()
	inputStr = inputLine
	ans=atozString(inputStr)
	print(ans)

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

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'):
        t = i
        break

for j in range(len(s)):
    if(s[j] == 'Z'):
        b = j

print([b-t+1,t-b+1][b<t])

Solution (Python):
s = input()
start = 0
goal = 0
p = 0
for i in range(len(s)):
    if s[i] == "A" and p == 0:
        start = i
        p = 1
    if s[i] == "Z":
        goal = i
print(goal - start + 1)

Solution (Python):



def main():
    """Function."""
    s = str(input())
    s = list(s)

    amin = s.index("A")
    zmax = max([i for i, x in enumerate(s) if x == "Z"])
    print(zmax-amin+1)


if __name__ == "__main__":
    main()

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

a = []
b = []

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

Solution (Python):
s = input()

idx_of_a = idx_of_z = -1
for i in range(len(s)):
    if s[i] == 'A' and idx_of_a == -1:
        idx_of_a = i
    elif s[i] == 'Z' and i > idx_of_z:
        idx_of_z = i

print(idx_of_z - idx_of_a + 1)

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

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

Solution (Python):
s = raw_input()
print len(s) - "".join(reversed(s)).index('Z') - s.index('A')

Solution (Python):
s = input()

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

print(idx_of_z - idx_of_a + 1 if idx_of_a < idx_of_z else 0)

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

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

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

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

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

Solution (Python):
s=input()
a=200000
z=0
b=[]
for i in range(len(s)):
    if(s[i]=="A" and a>=i):
        b.append(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):
s=input()
print(len(s)-s[::-1].index('Z')-s.index('A'))

Solution (Python):
def abc053_b():
    s = str(input())

    start = s.index('A')
    end = 0
    for i in range(len(s) - 1, 0, -1):
        if s[i] == "Z":
            return i - start + 1


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

Solution (Python):
s = input()

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

ans = len(s) - fir - las

print(ans)

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

Solution (Python):

s = input()

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

for i, x in enumerate(s[::-1]):
    if x == "Z":
        i_z = len(s) - (i + 1)
        break

print(i_z - i_a + 1)

Solution (Python):

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

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    S = input()

    ai, zi = 0, len(S) - 1

    while S[ai] != "A":
        ai += 1

    while S[zi] != "Z":
        zi -= 1

    print(zi - ai + 1)

main()

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

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

Solution (Python):
str_line = [i for i in input()]
a_place = []
z_place = []
result1 = 0
result2 = 10000000
for i, stri in enumerate(str_line):
    if stri == "A":
        a_place.append(i)  
for i, stri in enumerate(str_line):
    if stri == "Z":
        z_place.append(i)   
for i in z_place:
    if i >= result1:
        result1 = i
for i in a_place:
    if i <= result2:
        result2 = i
print(result1 - result2 + 1)

Solution (Python):
s = input().rstrip()
ai = s.find('A')
zi = s.rfind('Z')
n = 0
if ai != -1 and zi != -1:
    n = zi - ai + 1

print(n)

Solution (Python):
s=list(input())
an=0
zn=0
for i in range(len(s)):
    if s[i]=='A':
        an=i
        break

for i in range(len(s)):
    if s[i]=='Z':
        if zn<i:
            zn=i

print(zn-an+1)

Solution (Python):
s=input()

firstA = s.find('A')
lastZ = s.rfind('Z')

print(lastZ - firstA + 1)

Solution (Python):
a = list(input())
b = a.index("A")
a.reverse()
c = len(a) - a.index("Z")

print(c-b)

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

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

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()
i = s.index('A')
j = s.rindex('Z')
print(j - i + 1)

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

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

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

print(t - s + 1)

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

Solution (Python):


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

Solution (Python):
text = input()
a_list = []
z_list = []
for i, x in enumerate(text):
    if x == "A":
        a_list.append(i)
    if x == "Z":
        z_list.append(i)

a_z_len = max(z_list) - min(a_list) + 1
print(a_z_len)

Solution (Python):
s = input()
a = s.split('A')
z = s.split('Z')
start = len(a[0])
end = len(z[-1])
print(len(s)-start-end)

Solution (Python):


s=input()

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

Solution (Python):


""" 文字列から 'A***Z' のような文字列を抜き出す """

s = input()
list_s = list(s)

test = False

def length_AZ(l):
    """ 最初の'A'と最後の'Z'の位置の差を返す関数"""
    len_l = len(l)
    index_A = []
    index_Z = []

    for i in range(len_l):
        if l[i] == 'A':
            index_A.append(i)
        elif l[i] == 'Z':
            index_Z.append(i)

    if test:
        print('index_A =', index_A)
        print('index_Z =', index_Z)

    return max(index_Z) - min(index_A) + 1


def main():
    """ 答えを出力する """
    print(length_AZ(list_s))


if __name__ == '__main__':
    main()

Solution (Python):
s=input()

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

Solution (Python):
s = list(input())
a = s.index("A")
z = max([x for x in range(a,len(s)) if s[x] == "Z"])
print(z-a+1)

Solution (Python):
a = list(input())
b = a.index("A")
c = [i for i,j in enumerate(a) if j == "Z"]
print(max(c) - b + 1)

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

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

Solution (Python):
from sys import stdin

best = 0
cnt = 0
flg = False


def main():
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            calc(tmp)
        elif tmp != '\r':
            break

    print(best)


def calc(v: chr):
    global best
    global cnt
    global flg

    if v == 'A':
        flg = True
    if flg:
        cnt += 1
    if flg and v == 'Z':
        best = cnt


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin


def main():
    s = input()

    best = 0
    cnt = 0
    flg = False

    for v in s:
        if v == 'A':
            flg = True
        if flg:
            cnt += 1
        if flg and v == 'Z':
            best = cnt

    print(best)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin


def main():
    s = next_str()

    best = 0
    cnt = 0
    flg = False

    for v in s:
        if v == 'A':
            flg = True
        if flg:
            cnt += 1
        if flg and v == 'Z':
            best = cnt

    print(best)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
s = input()
L = len(s)
for i in range(L):
    if s[i] == 'A':
        A = i
        break
for i in range(L-1,-1,-1):
    if s[i] == 'Z':
        Z = i
        break
print(Z-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):

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

Solution (Python):
A=str(input())
a=A.index("A")
Z=[]
for i in enumerate(A):
    if i[1]=="Z":
        Z.append(i[0])
if len(Z)>=2:
    b=max(Z)
else:
    b=A.index("Z")

print(len(A[a:b+1]))

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

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

Solution (Python):
s = input()

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

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

print(len(s[sta:end+1]))

Solution (Python):
S = list(input())
ind_A = S.index('A')
ind_Z = [index for index, x in enumerate(S) if x == 'Z']

print(ind_Z[-1]-ind_A+1)

Solution (Python):
s = input()
count = 0
while s[count] != "A":
  count += 1
discount = -1
while s[discount] != "Z":
  discount -= 1
print(len(s) - count + discount +1)

Solution (Python):
s = input()

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

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

Solution (Python):

s= input()

listA= list(s)
listB = list(s)
listB.reverse()

index=0
while index < len(listA):
    if listA[index] == "A":
        break
    else:
        index+=1

index2 =0
while index2 < len(listB):
    if listB[index2] == "Z":
        break
    else:
        index2+=1

print(len(listB)-1-index2-index+1)

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

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

i = 0
while i<n:
  if s[i] == "A":
    break
  i += 1
j=n-1
while j>0:
  if s[j] == "Z":
    break
  j -= 1
print(j-i+1)

Solution (Python):
s = input()

flag = 0

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 = str(input())
print(s.rindex("Z") - s.index("A") + 1)

Solution (Python):
S = input()
f = 200001
l = -1
for i, c in enumerate(S):
    if(c == "A"):
        f = min(f, i)
    if(c == "Z"):
        l = max(l, i)

print(l-f+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
  if s[i] == 'Z' and z < i:
    z = i
print(z-a+1)

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

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
S = input()
for i,s in enumerate(S):
    if s == 'A':
        a = i
        break

for i,s in enumerate(S):
    if s == 'Z':
        b = i
print(b - a +1)

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

Solution (Python):
s = input()
L = []
M = []
for i in range(len(s)):
  if (s[i] == 'A'):
    L.append(i)
for j in range(len(s)):
  if (s[j] == 'Z'):
    M.append(j)
print(max(M)-min(L)+1)

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

Solution (Python):
S = input()

ai = 200001
zi = 0

for i in range(len(S)):
  if S[i] == "A":
    ai = min(ai,i)
  elif S[i] == "Z":
    zi = max(zi,i)
    

print(zi-ai+1)

Solution (Python):
s = input()
flag = False
start, end = 0, 0
for i, elem in enumerate(s):
    if elem == "A" and not(flag):
        flag = True
        start = i
    if elem == "Z" and flag:
        end = i
print(end - start + 1)

Solution (Python):
s=list(input())
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':
        b=i
        break
print(b-a+1)

Solution (Python):
s=input()
for a,b in enumerate(s):
  if b=='A':break
  x=a
for c,d in enumerate(reversed(s)):
  if d=='Z':break
  y=c
print(len(s)-a-c)

Solution (Python):
s = input()

r = 0
l = 0
flag = True
for i in range(len(s)):
  if flag and s[i] == 'A':
    r = i
    flag = False
  if s[i] == 'Z':
    l = i


print(l-r+1)

Solution (Python):
S=input()

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

Solution (Python):
s = input()

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

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

print(b-a+1)

Solution (Python):

import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

s = ns()

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

print(zi - ai + 1)

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

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

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

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

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

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

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

a = s.index('A')
b = list(reversed(s)).index('Z')

print(n-a-b)

Solution (Python):
A = input()
N = len(A)

for i in range(N):
    if A[i] == 'A':
        S = i
        break
for i in range(N):
    if A[N-i-1] == 'Z':
        E = i
        break
print(N - S - E)

Solution (Python):
S = list(input())
Z_max = [i for i, x in enumerate(S) if x == 'Z']
print(len(S[S.index('A'):max(Z_max)+1]))

Solution (Python):
s = input()

start = s.index("A")

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

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

Solution (Python):
s=input()

count=0
i=0
A=0
while count==0:
    if s[i]=='A':
        count+=1
        A=i
    i+=1

count2=0
j=len(s)-1
Z=0
while count2==0:
    if s[j]=='Z':
        count2+=1
        Z=j
    j-=1

print(Z-A+1)

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

a_index = 0
z_index = 0
max_z_index = 0

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

for j in range(len(s)):
    if j <= a_index:
        continue
    else:
        if s[j] == "Z":
            z_index = j
            max_z_index = max(max_z_index, z_index)

print(max_z_index - a_index + 1)

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

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

for j in range(len(s)):
    if s[j] == 'Z':
        zIndex = j

print(zIndex-aIndex+1)

Solution (Python):

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

print(len(s)-a-b)

Solution (Python):


def main():
    s = list(input())
    start = s.index('A')
    s.reverse()
    end = len(s) - s.index('Z')
    print(end - start)

if __name__ == '__main__':
    main()

Solution (Python):


def main():
    s = 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)

if __name__ == '__main__':
    main()