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=list(input())
print(len(s)-s.index('A')-s[::-1].index('Z'))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())

max = 0
i = 0
while i < len(s):
    if s[i] == 'A':
        b = i
        i += 1
        while i < len(s):
            if s[i] == 'Z':
                e = i
                max = e - b +1
                i += 1
            else:
                i += 1
    else:
        i += 1
print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 27 01:23:46 2019

@author: yuta
"""

def atoz(s):
    index_a = s.find('A')
    index_z = len(s) - 1 - s[::-1].find('Z')
    x = index_z - index_a + 1
    if x >= 2:
        print(x)

atoz(input())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
a=s.index('A')
ans=0
for i in range(a,len(s)):
  if s[i]=='Z':
    ans=i-a+1 if ans < i-a+1 else ans
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""AtCoder"""

s = input()

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

Submission status: Accepted

Solution code:
s = list(input())
if len(s) == 1:
    print(0)
    exit()
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(end - start + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s=str(input())
atoz=[]
for i in range(len(s)):
	if(s[i]=="A"):
		a=i
		break
#print(a)


for i in range(a,len(s)):
	atoz.append(s[i])

s_l=list(atoz)
#print(s_l)

r_s=[]
s_l_kep=s_l
for i in (reversed(s_l)):
	#print(i)
	if(i!="Z"):
		s_l.pop()
#		print(s_l)
	else:
		break
#	r_s.append(i)
#print(s_l)
str_s_l=''.join(s_l)
#print(str_s_l)
print(len(str_s_l))

Submission status: Accepted

Solution code:
s = list(input())

A_lst = []
for i in range(0, len(s)):
    if s[i] == "A":
        A_lst.append(i)

Z_lst = []
for i in range(0, len(s)):
    if s[i] == "Z":
        Z_lst.append(i)
        
A = min(A_lst)
Z = max(Z_lst)



ans = 0

for i in range(A, Z + 1):
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
s=input()
ans=0
for i in range(len(s)):
    if s[i] == 'A':
        for j in range(len(s)-1,0,-1):
            if s[j] == 'Z':
                if ans < abs(i-j):
                    ans = abs(i-j)
                break

print(ans+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = raw_input()

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

Submission status: Accepted

Solution code:
s = input()

num = len(s)

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

for j in range(0, num):
    if s[j] == 'A':
        break

print(i - j + 1)

Submission status: Accepted

Solution code:
def fun():
     print('ac')
     print('AC')
     print('ACAC')
     print('ac')
     print('aacc')
ls=input()
k=0
s=0
kai=len(ls)
for i in range(len(ls)):
     if ls[i]=='A':
          if kai>i:
               kai=i
     if ls[i]=='Z':
          if i>s:
               s=i
print(s-kai+1)

Submission status: Accepted

Solution code:
s = input()

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

print(s_last-s_first+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(j + 1 - i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

switch = 0 #カウント開始、0でオフ1でオン
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# A,B,C = [int(n) for n in input().split()]
# N = int(input())
S = str(input())
# T = 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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B_A to Z String

s = input()

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

Submission status: Accepted

Solution code:
# ABC 053
s = input()
#print(s,len(s))#
for i in range(len(s)):
    if s[i]=='A': break
start = i
#print(start)#
for i in range(len(s)-1,0, -1):
    #print(i)#
    if s[i]=='Z': break
end = i
#print(end)#
print(end-start+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ss = input()

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

Submission status: Accepted

Solution code:
s=input()
#print(s)
length=len(s)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str_s = input()

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(r - l + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
print(s.rfind("Z")-s.find("A")+1)
#コピペです

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest053-B
#  https://beta.atcoder.jp/contests/abc053/tasks/abc053_b

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

ans = len(s) - fir - las

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
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))


# Binary converter
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


# Width First Search (+ Distance)
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


# Depth First Search (+Distance)
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

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

print(lastZ - firstA + 1)

Submission status: Accepted

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

print(c-b)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
##ABC 053 B

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
s=input()

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

Submission status: Accepted

Solution code:
#! /usr/bin/python3
# A to Z String
""" 文字列から '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()

Submission status: Accepted

Solution code:
s=input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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()
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 = s.find('A')
Z = s.rfind('Z')
print(Z-A+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

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