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



Sample input:
QWERTYASDFZXCV


Sample output:
5

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  s=str(input())
  print(s.rfind("Z") - s.find("A") + 1)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
  s=str(input())
  l=len(s)
  f=None
  e=None
  for i in range(l):
    if s[i]=='A':
      f=i
      break
  for i in range(1,l):
    if s[-i]=='Z':
      e=l-i
      break
  print(e-f+1)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
st=200000
for i in range(len(s)):
  if s[i]=="A" and st>i:
    st=i
  elif s[i]=="Z":
    en=i
print(en-st+1)

Submission status: Accepted

Solution code:
s =str(input())
for i in range(len(s)):
    if s[i]=='A':
        a=i
        break
for j in reversed(range(len(s))):
    if s[j]=='Z':
        b=j
        break
print(b-a+1)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
for i in range(N):
    if S[i] == 'A':
        start = i
        break
for i in range(N-1,0,-1):
    if S[i] == 'Z':
        end = i
        break

print(end-start+1)

Submission status: Accepted

Solution code:
def solve():
  S = input()
  a = S.find('A')
  z = S[::-1].find('Z')
  ans = len(S)-a-z
  return ans
print(solve())

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
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) - 1, -1, -1):
    if s[i] == 'Z':
        right = i
        break
print(right - left + 1)

Submission status: Accepted

Solution code:
string = input()
for i, s in enumerate(string):
    if s == "A":
        start = i
        break
    
l = len(string)
for i, s in enumerate(string[::-1]):
    if s == "Z":
        end = l - i
        break
print(end - start)

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    s = s_input()

    start_index = s.find('A')

    s = s[::-1]

    end_index = len(s) - s.find('Z') - 1 

    print(end_index - start_index + 1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
st = s.index('A')
gl = [i for i,x in enumerate(s)if x == 'Z']

print(len(s[st:max(gl)])+1)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
for i in range(n):
    if s[i]=="A":
        start=i
        break
for i in range(n):
    if s[i]=="Z":
        goal=i
ans=goal-start
print(ans+1)

Submission status: Accepted

Solution code:
S=list(input())
a=S.index("A")
n=len(S)
for i in range(n):
  if S[n-1-i]=="Z":
    k=n-1-i
    break
print(k-a+1)

Submission status: Accepted

Solution code:
s=input()
t,b=0,len(s)-1
while s[t]!='A':
	t+=1
while s[b]!='Z':
	b-=1
print(b-t+1)

Submission status: Accepted

Solution code:
s=input()
first=-1
last=0
for i in range(len(s)):
    if s[i]=="A":
        first=i
        break
for j in range(len(s)-1,-1,-1):
    if s[j]=="Z":
        last=j
        break

print(j-i+1)

Submission status: Accepted

Solution code:
s = input()
rs = s[::-1]
a = s.find('A')
z = rs.find('Z')
z = len(s)-z
count = z - a 
print(count)

Submission status: Accepted

Solution code:
S=[x for x in input()]
T=S[::-1]
start=0
end=0
for i in range(len(S)):
  if S[i]=='A':
    start=i
    break
for i in range(len(T)):
  if T[i]=='Z':
    end=i
    break
    
print(len(S)-end-start)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

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

    print(idx_z - idx_a + 1)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
s=input()
while s[0]!="A":
  s=s[1:]
while s[-1]!="Z":
  s=s[:-1]
print(len(s))

Submission status: Accepted

Solution code:
def resolve():
    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)
resolve()

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S=list(input())
length=len(S)
start=S.index('A')
M=list(reversed(S))
finish=M.index('Z')

print(length-start-finish)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main():

    s = input()
    listS = list(s)
    n = len(listS)

    aIndex = 0
    zIndex = 0

    for i in range(n):
        if listS[i] == 'A':
            aIndex = i
            break

    for i in range(n):
        if listS[-(i + 1)] == 'Z':
            zIndex = n - i
            break

    ans = zIndex - aIndex

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
A_index = s.index('A')
s_r = list(reversed(s))
s_reverse = ''.join(s_r)
Z_index = s_reverse.index('Z')
ans = (len(s_reverse)-Z_index-1) - A_index + 1
print(ans)

Submission status: Accepted

Solution code:
#-------------
s = 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)
    
min_A = min(A)
max_Z = max(Z)
print(max_Z-min_A+1)

Submission status: Accepted

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

s = rs()
f = True
for i in range(len(s)):
    if f and s[i] == 'A':
        a = i
        f = False
    if s[i] == 'Z':
        z = i
print(z - a + 1)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ma = n+1
mz = -1
for i in range(0 , n):
	if s[i]=='A':
		ma = min(ma, i)
	if s[i]=='Z':
		mz = max(mz, i)

if ma>mz:
	print(0)
else:
	print(mz-ma+1)

Submission status: Accepted

Solution code:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

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

Submission status: Accepted

Solution code:
din = str(input())
length = len(din)
first_A = -1
last_Z = -1
for i in range(length):
    if (din[i] == 'A' and first_A == -1):
        first_A = i
    elif din[i] == 'Z':
        last_Z = i
print(last_Z-first_A+1)

Submission status: Accepted

Solution code:
s=input()
st=s.index("A")
s=list(s)
s.reverse()
en=s.index("Z")
print(len(s)-st-en)

Submission status: Accepted

Solution code:
s=str(input())
d=s.index('A')
e=s[::-1]
f=len(s)-e.index('Z')
print((f-d))

Submission status: Accepted

Solution code:
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(z[-1]-a[0]+1)

Submission status: Accepted

Solution code:
s=input()
ans=False
for i,v in enumerate(s):
    if ans==False:
        if v=="A":
            a=i
            ans=True
    else:
        if v=="Z":
            z=i
print(z-a+1)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    s = readline().strip()

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

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
a = len(s)
b = 0
for i in range(len(s)):
  if s[i] == "A":
    a = min(a, i)
  if s[i] == "Z":
    b = max(b,i)
res = b-a+1
print(res)

Submission status: Accepted

Solution code:
s=input()
 
ds=list(s)
 
 
c1=0
while ds[c1]!='A':
  c1+=1
 
c2=-1
while ds[c2]!='Z':
  c2-=1
 
print(len(s[c1:c2])+1)

Submission status: Accepted

Solution code:
from collections import deque
s=input()

ds=deque(s)
flag=True

while ds[0]!='A' or ds[-1]!='Z':
  if ds[0]!='A':
    ds.popleft()
  if ds[-1]!='Z':
    ds.pop()
print(len(ds))

Submission status: Accepted

Solution code:
s = input()

a_index = s.find('A')
z_index = s.rfind('Z')
new_s = s[a_index:z_index+1]
print(len(new_s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = open(0).read().rstrip()

import re
m = re.search(r'A.*Z',s)

print(m.end() - m.start())

Submission status: Accepted

Solution code:
sn = input()
r_sn = list(reversed(sn))
print(len(sn[sn.index("A"):len(sn)-r_sn.index("Z")]))

Submission status: Accepted

Solution code:
def main():
    s  = input()
    ind_a = 0
    ind_z = 0
    for i in range(len(s)):
        if(s[i]=="A"):
            ind_a = i
            break
    for i in range(len(s)-1,-1,-1):
        if(s[i]=="Z"):
            ind_z = i
            break



    print(ind_z-ind_a+1)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
rs = s[::-1]
x = s.index('A')
y = rs.index('Z')
print(len(s)-y-x)

Submission status: Accepted

Solution code:
s=input()
num1=[]
num2=[]
for i in range(len(s)):
    if s[i]=="A":
        num1.append(i)
    elif s[i]=="Z":
        num2.append(i)

print(max(num2)-min(num1)+1)

Submission status: Accepted

Solution code:
MM = input()
listM = list(MM)
xx = len(listM)
saisyo =0
saigo  =xx
xx = len(listM)
for i in range(0,xx-1,1):
  
  if listM[i]=='A':
    saisyo = i
    
    break
for i in range(xx-1,0,-1):
  
  if listM[i]=='Z':
    saigo = i
    
    break
ans = saigo -saisyo
print(ans+1)

Submission status: Accepted

Solution code:
S = input()
aPosition = S.find('A')
zPosition = S.rfind('Z')
print(zPosition - aPosition + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
#Aの探索
for i in range(len(S)):
    if S[i] == "A":
        S = S[i:]
        break

#Zの探索
if S[-1] == "Z":
    print(len(S))
    exit()
for i in range(1, len(S)+1):
    if S[-i] == "Z":
        S = S[:-i+1]
        break
print(len(S))

Submission status: Accepted

Solution code:
s = input()
A = float("inf")
Z = -1
for i in range(len(s)):
    if s[i] == "A":
        A = min(A, i)
    elif s[i] == "Z":
        Z = max(Z, i)
print(Z - A + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

left = s.find("A")
right = s.rfind("Z")

print(right - left + 1)

Submission status: Accepted

Solution code:
s = input()

rs  = s[::-1]

inds = 0
indrs = 0

for i in range(len(s)):
    if s[i] == "A":
        inds = i
        break
    
for j in range(len(rs)):
    if rs[j] == "Z":
        indrs = j
        break

indrs = len(s) - indrs

print(abs(indrs - inds))

Submission status: Accepted

Solution code:
s = list(input())
start = 0
end = 0
len_s = len(s)
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)

Submission status: Accepted

Solution code:
n = str(input())
s = 0
e = 0
for i in range(0, len(n)):
    if n[i] == 'A':
        s = i
        break
for i in range(len(n) - 1, 0, -1):
    if n[i] == 'Z':
        e = i
        break
print(int(e - s + 1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

answer = 0
a = 0
z = 0

words = list(s)

for num in range(len(words)):
    if words[num] == 'A':
        a = num
        break

for num in range(len(words)):
    if words[num] == 'Z':
        z = num

answer = z - a + 1

print(answer)

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    S = input().strip()
    return S.rindex('Z')-S.index('A')+1


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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':
    z = len(s) - 1 - i
    break
print(z - a + 1)

Submission status: Accepted

Solution code:
import re
s = input()
num = len(s)
s = re.sub('A[A-Z]*Z', '', s)
print(num-len(s))

Submission status: Accepted

Solution code:
import sys
s = input()
for i in range(len(s) - 1):
    if s[i] == 'A':
        left = i
        break
for i in range(len(s) - 1, -1, -1):
    if s[i] == 'Z':
        print(i - left + 1)
        sys.exit()

Submission status: Accepted

Solution code:
S = input()
f=0
l=0
for i in range(len(S)):
    if(S[i] =="A"):
        f = i+1
        break
for j in range(len(S)-1,0,-1):
    if(S[j] == "Z"):
        l = j+1
        break
print(l-f+1)

Submission status: Accepted

Solution code:
s = input()

st = s.find("A")
ed = s.rfind("Z")

print(ed-st+1)

Submission status: Accepted

Solution code:
s = list(input())

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

   
print((tmp2+1)-tmp1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
print(s.rfind("Z") - s.find("A") + 1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

S = input().rstrip('\n')
print(S.rfind("Z") - S.find("A") + 1)

Submission status: Accepted

Solution code:
s = input()
for i, st in enumerate(s):
    if st=='A':
        start = i
        break
for i, st in enumerate(s):
    if st=='Z':
        end = i
print(end-start+1)

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

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

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

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

Submission status: Accepted

Solution code:
s=input()

#Aのインデックス
num_a=s.index("A")

#Zのインデックス
num_z=len(s)-1-s[::-1].index("Z")

print(num_z-num_a+1)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s = input()

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

ans = right - left + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s_start = 0
s_end = 0
count = 0

# 文字列sを右から探索できるように逆順に変換する
s_reverse = s[::-1]
# print(s_reverse)

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

# カウンタcountを逆順用に変更（降順）
count = len(s) - 1

for j in s_reverse:
    if j == 'Z':
        s_end = count
        break
    count -= 1

ans = s_end - s_start + 1
print(ans)

Submission status: Accepted

Solution code:
s=input()
N=len(s)

ind_a=0
ind_z=0
for i in range(N):
    if s[i]=="A":
        ind_a=i
        break
for i in range(1,N+1):
    if s[-i]=="Z":
        ind_z=N-i
        break

print(ind_z-ind_a+1)

Submission status: Accepted

Solution code:
s=input()

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

print(z-a+1)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()
s = S.index('A')
e = [i for i, x in enumerate(S) if x == 'Z']

print(max(e) - s + 1)

Submission status: Accepted

Solution code:
s = input()

anum = 0
while s[anum] != "A":
    anum += 1
znum = len(s)-1
while s[znum] !="Z":
    znum -= 1

print(znum - anum +1)

Submission status: Accepted

Solution code:

S = str(input())
l = len(S)
st = 0
en = 0
for i in range(l):
    if S[i] == 'A':
        st = i
        break
for j in range(l-1,-1,-1):
    #print(j)
    if S[j] == 'Z':
        en = j
        break
#print(st,en)
print(en-st+1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

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

print(z - a + 1)

Submission status: Accepted

Solution code:
S = input()
a = 0
x = 0
j = 0
for i in range(len(S)):
    if S[i] == "A" and a == 0:
        a = 1
    if a == 1:
        j += 1
    if S[i] == "Z" and a == 1:
        x = j
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
ans = 0
cnt = 0
left = 200005
right = 0
for i in range(len(s)):
    if (s[i]=='A') : 
        left = min(left, i)
    if (s[i]  == "Z") :
        right = max(right, i)
print(right - left+1)

Submission status: Accepted

Solution code:
# import sys;input = lambda : sys.stdin.readline()
s = input()
A, Z = None, None
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    s = input()
    a = []
    z = []
    for i, c in enumerate(s):
        if c == 'A':
            a.append(i)
        if c == 'Z':
            z.append(i)
    
    print(z[-1]-a[0]+1)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()




"""

4
1 2
2 4
1 3
3
2 2 4
4 5 6

6
1 2
2 3
3 4
4 5
4 6
3
3 5 6
2 17 31 5 11

"""

Submission status: Accepted

Solution code:
S=input()
A=S.index("A")
Z=S[::-1].index("Z")
print(len(S)-(A+Z))

Submission status: Accepted

Solution code:
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':
        e = i
        break
print(e - b + 1)

Submission status: Accepted

Solution code:
s=input()
a,b=0,0
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]))

Submission status: Accepted

Solution code:
S = list(input())
s = 0
g = len(S) -1
while S[s] != "A":
    s += 1
while S[g] != "Z":
    g -= 1
print(g-s+1)

Submission status: Accepted

Solution code:
s = list(str(input()))

f = ''
for i in s:
  if f == '':  
    if i == 'A':
      f = s.index(i)
  else:
    break  

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

print(e - int(f) + 1)

Submission status: Accepted

Solution code:
s=input()
s_r=s[::-1]

f=s.index("A")
l=s_r.index("Z")
l_r=len(s)-1-l


print(l_r-f+1)

Submission status: Accepted

Solution code:
s=input();i=s[::-1].index("Z");
if i==0:
  i=len(s)
else:
  i=-i
print(len(s[s.index("A"):i]))

Submission status: Accepted

Solution code:
S = input()
T = S[::-1]

for n in range(len(S)):
  if S[n]=="A":
    a=n
    break

for m in range(len(T)):
  if T[m]=="Z":
    z=len(S)-m
    break
    
print(z-a)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

s = list(str(input()))

a_start = 0
z_end = 0

# A の探索
for i in range(len(s)):
    if s[i] == 'A':
        a_start = i
        break

# Z の探索
for i in reversed(range(len(s))):
    if s[i] == 'Z':
        z_end = i
        break

print(len(s[a_start:z_end+1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

ans = 0
count = 0
flag = False
for s in S:
    if flag:
        count += 1
        if s == "Z":
            ans = count
    else:
        if s == "A":
            flag = True
            count += 1

print(ans)

Submission status: Accepted

Solution code:
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
    if c == 'Z':
        last_Z = i
 
print(last_Z-first_A+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
start_i, end_i = 0, 0
a_flag = True

for i, c in enumerate(s):
  if c == 'A' and a_flag:
    start_i = i
    a_flag = False
  if c == 'Z':
    end_i = i
    
print(end_i - start_i + 1)

Submission status: Accepted

Solution code:
s = input()

a = s.find('A')
#print(a)
z = 0
for i in range(len(s)):
  if s[i] == 'Z':
    z = i
#print(z)
print(z-a+1)

Submission status: Accepted

Solution code:
s = input()
amin = 10000000000
amax = -1

for i, j in enumerate(s):
    if j=="A":
        amin = min(amin, i)
    elif j=="Z":
        amax = max(amax, i)
    
print(amax-amin+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

a=[]
b=[]

for i in range(len(s)):
    if s[i]=="A":
        a.append(i)
    elif s[i]=="Z":
        b.append(i)

x=min(a)
y=max(b)

print(y-x+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
    if c == 'Z':
        last_Z = i

print(last_Z-first_A+1)

Submission status: Accepted

Solution code:
s = str(input())
a = 0
b = 0
for i in range(len(s)+1):
    if s[i] == "A":
        a = i+1
        break
    else:
        pass
for i in reversed(range(len(s))):
    if s[i] == "Z":
        b = i+1
        break
    else:
        pass
print(b - a + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
f1=0
f2=0
ok=True
for i in range(len(s)):
    if s[i]=='A' and ok:
        ok=False
        f1=i
    if s[i]=='Z': f2=i
print(f2-f1+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

print(z-a+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(str(input()))

front = s.index("A")
s.reverse()
back = s.index("Z")

print(len(s)-front-back)

Submission status: Accepted

Solution code:
import sys
import re
s = str(input())
if len(s) < 0 or len(s) > 200000:
    sys.exit()

array_str = re.findall(r'A.*Z', s)
max = 0
for I in array_str:
    if len(I) > max:
        max = len(I)
print(max)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


s = input()
print(len(s) - list(reversed(s)).index("Z") - s.index("A"))


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
count = 0
for i in s:
    if (i == 'A'):
        break
    count += 1
for i in s[::-1]:
    if (i == 'Z'):
        break
    count += 1
print(len(s) - count)

Submission status: Accepted

Solution code:
S=input()
start=0
last=0
for i in range(len(S)):
    if S[i]=='A':
        start=i
        break

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

Submission status: Accepted

Solution code:
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(max(z) - min(a) + 1)

Submission status: Accepted

Solution code:
s = str.upper(input())

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


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

Submission status: Accepted

Solution code:
s = list(input())
Z_place = 0
A_place = s.index('A')

for i in s[:A_place:-1]:
     if i != 'Z':
        Z_place += 1
     else:
         break

print(len(s) - (A_place + Z_place))

Submission status: Accepted

Solution code:
s = input()
l = len(s)

i = 0
while s[i] != "A":
    i += 1

j = 1
while s[l-j] != "Z":
    j += 1

print(l-j-i+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
l = len(S)
r = -1

for i, s in enumerate(S):
    if s == 'A':
        l = min(l, i)
    if s == 'Z':
        r = max(r, i)

print(r - l + 1)

Submission status: Accepted

Solution code:
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-l+1)

Submission status: Accepted

Solution code:
import sys
s = str(input())

for i in range(len(s)):
  if s[i]=="A":
    for j in range(1,len(s)):
      if s[-1*j]=="Z":
        print(len(s)-i-j+1)
        sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
print(  abs( min([ k for k,v in enumerate(S) if v == "A" ])  - max([ k for k,v in enumerate(S) if v == "Z" ]) ) +1 )

Submission status: Accepted

Solution code:
s = list(input())
a = int(s.index("A"))
del s[:a]

list_z = [i for i, x in enumerate(s) if x =="Z"]
z = max(list_z)
del s[len(s):z:-1]
print(len(s))

Submission status: Accepted

Solution code:
S = input()

def findPos(s,char):
  l = []
  for i in range(len(s)):
    if s[i] == char:
      l.append(i)
  return l

A_pos = findPos(S,"A")
Z_pos = findPos(S,"Z")
print(max(Z_pos)-min(A_pos)+1)

Submission status: Accepted

Solution code:
s=input()
i=s.find('A')
j=s.rfind('Z')

print(abs(i-j)+1)

Submission status: Accepted

Solution code:
s = input()
aidx = -1
zidx = -1
for i in range(len(s)):
  if aidx == -1 and s[i] == 'A':
    aidx = i
  if zidx == -1 and s[len(s)-1-i] == 'Z':
    zidx = len(s)-1-i
  if aidx != -1 and zidx != -1:
    break
print(zidx-aidx+1)