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:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Submission status: Accepted

Solution code:
s=list(input())
a=len(s)+1
z=0
for i in range(len(s)):
    if a==len(s)+1 and s[i]=="A":
        a=i
    elif s[i]=="Z":
        z=i
    else:
        pass
print(z-a+1)

Submission status: Accepted

Solution code:
S = input()
def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
print(my_index_multi(S, "Z")[-1] - my_index_multi(S, "A")[0] + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
t = 0
z = 0
for i in range(0,len(S)):
  if(t == 0)and(S[i] == 'A'):
    a = i
    t += 1
  if(S[i] == 'Z') and i > z:
    z = i
print(z-a+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
w = input()

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

Submission status: Accepted

Solution code:
s = input()
x = 0
y = 0
ans = 1

for c in s:
    if c == "A":
        break
    x += 1
  
for c in s[::-1]:  
    if c == "Z":
        break
    y += 1

print(len(s)-x-y)

Submission status: Accepted

Solution code:
s = input()

flg=-1
max = 0
for i in range(len(s)):
    if s[i]=="A" and flg==-1:
        a_index = i
        flg=1
        continue
    if s[i]=="Z":
        z_index = i

print((z_index-a_index)+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
	s = input()
	a = float('inf')
	z = 0
	for i in range(len(s)):
		if s[i] == 'A':
			a = min(a, i)
		if s[i] == 'Z':
			z = max(z, i)
	print(z - a + 1)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

start = 0
end = len(s)-1
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()
ca = 0
cz = 0

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s = input()
ca = []
cz = []
ans = 0
for i in range(len(s)):
    if s[i] == "A":
        ca.append(i)
    if s[i] == "Z":
        cz.append(i)
ans = max(cz)-min(ca)+1
print(ans)

Submission status: Accepted

Solution code:
s = input()
Aplace = len(s)-1
Zplace = 0
for i in range(len(s)):
    if s[i]=='A':
        Aplace = min(Aplace, i)
    elif s[i]=='Z':
        Zplace = max(Zplace, i)
print(Zplace-Aplace+1)

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip()

pos_a = s.find('A')
pos_z = s.rfind('Z')

print(pos_z - pos_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)-1-i
    break
print(end-start+1)

Submission status: Accepted

Solution code:
def resolve():
	s = list(input())
	b = -1
	e = -1
	for i in range(len(s)):
		if s[i] == 'A' and b < 0:
			b = i
		if s[i] == 'Z':
			e = i
	if b == -1 or e == -1:
		print(0)
	else:
		print(e-b+1)
resolve()

Submission status: Accepted

Solution code:
def main():
    S = input()
    L, R = 1001001, 0
    for i in range(len(S)):
        if S[i] == 'A' and L > i:
            L = i
        if S[i] == 'Z' and R < i:
            R = i
    print(R - L + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re
s = input()
r = re.compile(r'A.*Z')
q = r.search(s)
print(len(q.group()) if q != None else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
l=len(s)
a=[]
z=[]
ans=0
for i in range(l):
    if s[i]=="A":
        a.append(i)
    elif s[i]=="Z":
        z.append(i)

ans=(max(z)-min(a)+1)

print(ans)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s = input()

ans = 0
tmp = 0
flag = 0

for i, j in enumerate(s):
    if flag == 0 and j == 'A':
        tmp = i
        flag = 1
    elif flag == 1 and j == 'Z':
        ans = max(ans, i-tmp+1)
        flag = 2
    elif flag == 2:
        if j == 'Z':
            ans = max(ans, i-tmp+1)
        elif j == 'A':
            flag = 1

print(ans)

Submission status: Accepted

Solution code:
sss = input()
min_a = 0
max_s = 0
for i in range(len(sss)):
    if sss[i] == 'A':
        min_a = i
        break
# for i in range(len(sss)-1, 0, -1):
for i in reversed(range(len(sss))):
    if sss[i] == 'Z':
        max_s = i
        break
print(max_s - min_a + 1)

Submission status: Accepted

Solution code:
s=input()

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

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()

idxA = S.find("A") + 1
idxB = len(S) - S[::-1].find("Z")

ans = idxB - idxA + 1
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
s = list(input())
count_head = 0
count_tail = 0
for i in range(len(s)):
    if s[i] == "A":
        count_head = i
        break

for j in range(len(s)-1, count_head-1, -1):
    if s[j] == "Z":
        count_tail = j
        break

print(count_tail - count_head + 1)

Submission status: Accepted

Solution code:
s = str(input())
k = 1
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:
s = input()
a_index = s.find("A")
z_index = s.rfind("Z")
print(z_index - a_index + 1)

Submission status: Accepted

Solution code:
s = input()

a = 0
z = 0

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

for i in range(len(s)-1, 0, -1):
    char = s[i]
    if s[i] == "Z":
        z = i
        break

print(z - a + 1)

Submission status: Accepted

Solution code:
list_S = list(input())
s = -1
e = -1
for i in range(len(list_S)):
    if list_S[i] == "A":
        s = i
        break

list_S.reverse()

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

print(e - s)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc053/tasks/abc053_b
s = input()
a_index = s.find("A")
z_index = s.rfind("Z")
print(z_index - a_index + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

s1 = s
s2 = s[::-1]

start = 0
end = 0

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

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

print(end - start)

Submission status: Accepted

Solution code:
s = str(input())

cnt_A=0
cnt_Z=0
max=0
N=len(s)
for i in s:
	if i!='A':
		cnt_A+=1
	else:
		break

for i in range(-1,-200000,-1):
	if s[i]!='Z':
		pass
	else:
		break
#print(cnt_A)
#print(i)

print(N+(i+1)-cnt_A)

Submission status: Accepted

Solution code:
s = input()
ap = 0
zp = len(s)
for i in range(len(s)):
    if s[i] == 'A':
        ap = i
        break
    
for i in range(len(s)):
    if s[len(s)-i-1] == 'Z':
        zp = len(s)-i-1
        break

print(zp-ap+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
li = []
a = 0
cnt = 0
for i in range(len(S)):
    if a == 0 and S[i] == "A":
        a = 1
        cnt += 1
    elif a == 1 and S[i] == "Z":
        cnt += 1
        li.append(cnt)
    elif a == 1:
        cnt += 1
print(max(li))

Submission status: Accepted

Solution code:
s = input()

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

print(j - i + 1)

Submission status: Accepted

Solution code:
import re
regex = re.compile(r'A.*Z')

ans = 0
for res in regex.finditer(input()):
    ans = max(ans, len(res.group()))
    # print(res.group())

print(ans)

Submission status: Accepted

Solution code:
s = input()
a_j = True
z = 0
for i in range(len(s)):
    if s[i] == 'A' and a_j == True:
        a = i
        a_j = False
    elif s[i] == 'Z':
        z = i
        
print(z-a+1)

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

Solution code:
import re
s = input()
m = re.search(r'A.*Z', s)
print(len(m.group()))

Submission status: Accepted

Solution code:
s=input()
Acnt=[];Zcnt=[]
for i in range(len(s)):
    if(s[i]=='A'):
        Acnt.append(i)
    elif(s[i]=='Z'):
        Zcnt.append(i)
print(Zcnt[-1]-Acnt[0]+1)

Submission status: Accepted

Solution code:
s = input()

start = min(i for i, x in enumerate(s) if x == 'A')
end = max(j for j, y in enumerate(s) if y == 'Z')

print(end-start+1)

Submission status: Accepted

Solution code:
S = input()
resA=0
resZ=0
for i in range(1,len(S)+1):
	if S[i-1]=='A' and resA==0:
		resA=i
	elif S[i-1]=='Z':
		resZ=i
if resA !=0 and resZ !=0:
	print(resZ-resA+1)
else:
	print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
Nreverse = N[::-1]
for i in range(len(N)):
    if N[i] == "A":
        Initial = i+1
        break
for j in range(len(Nreverse)):
    if Nreverse[j] == "Z":
        Final = len(N)-j
        break

print(Final - Initial +1)

Submission status: Accepted

Solution code:
s = input()
start,end = 0,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 = list(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)
print(max(Z)-min(A)+1)

Submission status: Accepted

Solution code:
m = input()

A = m.index("A")
Z = m.rfind("Z")

print(Z-A+1)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    s=list(input())
    ss=[]
    for i in range(len(s)):
        ss.append([s[i],i])
    ss.sort()
    print(ss[-1][1]-ss[0][1]+1)

Submission status: Accepted

Solution code:
def myAnswer2(s:str) -> int:
   return len(s)-s[::-1].index("Z") - s.index("A")

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

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def myAnswer(s:str) -> int:
   start = 0
   end = 0
   for n,string in enumerate(s):
      if(string =="A"):
         start = n
         break
   for n,string in enumerate(s[::-1]):
      if(string == "Z"):
         end = len(s) - n
         break
   return end - start





def modelAnswer():
   tmp=1
def main():
   s = (input())
   print(myAnswer(s))

if __name__ == '__main__':
   main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
s=deque(list(input()))
while True:
    if s[0]!="A":
        s.popleft()
    else:
        break
while True:
    if s[-1]!="Z":
        s.pop()
    else:
        break

print(len(s))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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()
a, z = 0, 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

inda=-1
indz=0
for i in range(len(s)):
  if s[i] =="A" and inda==-1:
    inda=i
  if s[i]=="Z":
    indz=i
print(indz-inda+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)):
    if s[len(s)-i-1] == 'Z':
        end = i
        break
    
print(len(s) - start - end)

Submission status: Accepted

Solution code:
s = input()

l = s.index('A')
r = s.rindex('Z')

print(r-l+1)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = ns()

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

print(z - a + 1)

Submission status: Accepted

Solution code:

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

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

ans = max(0,r-l)
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

print(z - a + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

A = []
Z = []
for i, si in enumerate(s):
    if si == 'A':
        A.append(i)
    elif si == 'Z':
        Z.append(i)

print(max(Z) - min(A) + 1)

Submission status: Accepted

Solution code:
s = input()
lis_A = []
lis_z = []

for num,moji in enumerate(s):
    if 'A' == moji:
        lis_A.append((num,moji))
    elif 'Z' == moji:
        lis_z.append((num,moji))

print(max(lis_z)[0] - min(lis_A)[0] + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

a = [n for n,v in enumerate(s) if v == "A"]
z = [n for n,v in enumerate(s) if v == "Z"]

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

print(y-b+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
s = input()

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

print(len(m.group()))

Submission status: Accepted

Solution code:
s=input()
m=s.find("A")
n=s.rfind("Z")
if m<n:
    ans=(n-m)+1
    print(ans)
else:
    pass

Submission status: Accepted

Solution code:
# 2020/04/12
# AtCoder Beginner Contest 053 - B

# Input
s = input()

# Search 'A'
for i in range(len(s)):
    if s[i] == 'A':
        aidx = i
        break
    
# Search 'Z'
for i in range(len(s)-1, -1, -1):
    if s[i] == 'Z':
        zidx = i
        break

ans = zidx - aidx + 1

# Output
print(ans)

Submission status: Accepted

Solution code:
s = input()

k = s[::-1]

for i in range(len(s)):
    if s[i]=='Z':
        z_num = i 
    if k[i]=='A':
        a_num = i

ans = a_num + z_num + 2 - len(s)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    s = input().rstrip()

    idx_A = s.find("A")
    idx_Z = (len(s) - 1) - s[::-1].find("Z")
    ans = idx_Z - idx_A + 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
s = input()
n = len(s)
left = 0
flag1 = True
right = n
flag2 = True
for i in range(n):
    if s[i] == "A" and flag1:
        left = i
        flag1 = False
    if s[n - i - 1] == "Z" and flag2:
        right = n - i - 1
        flag2 = False
# print("right =", right)
# print("left =", left)
print(right - left + 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,1,-1):
    if s[i] == 'Z':
        end = i
        break
print(len(s[start:end+1]))

Submission status: Accepted

Solution code:
string = input()
index = -1
for i in range(len(string)): 
        if string[i] == "Z": 
            index = i 
w = string.index("A")
z = string[w:index+1]
print(len(z))

Submission status: Accepted

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    a = S.find('A')
    z = S.rfind('Z')
    print(z - a + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
a = None
z = None
for i in range(len(s)):
  j = len(s)-1-i
  if a == None and s[i] == 'A':
    a = i
  if z == None and s[j] == 'Z':
    z = j
s = z - a + 1
# print("a,z,s",a,z,s)
print(s)

Submission status: Accepted

Solution code:
s = input()
ans = 0
tmp_ans = 0
flag = False

for char in s:
    if not flag:
        if char == "A":
            flag = True
            tmp_ans += 1
    else:
        tmp_ans += 1
        if char == "Z":
            ans = tmp_ans

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import sys
readline = sys.stdin.buffer.readline
#K,S=map(int, readline().split())
#S=list(readline())
S=input()

#print(S)
i=S.index('A')
#print(i)

S1 = S[::-1]

j=(S1.index('Z'))
j=len(S)-j
#print(S1)
#print(j)
#print(len(S)-j)
print(j-i)

Submission status: Accepted

Solution code:
s = input()

import re
pattern = r'A.*Z'
match = re.findall(pattern, s)

cnt = len(match[0])
print(int(cnt))

Submission status: Accepted

Solution code:
import itertools
s = list(input())
s1 = list(itertools.dropwhile(lambda x: x != 'A',s))
s2 = list(itertools.dropwhile(lambda x: x != 'Z',s1[::-1]))
print(len(s2))

Submission status: Accepted

Solution code:
s = input()
a = s.index('A')
zl = [i for i, x in enumerate(s) if x == 'Z']
z = zl[len(zl)-1]
print(z-a+1)

Submission status: Accepted

Solution code:
import re
a=input()
m=a.find("A")
n=a.rfind("Z")
print(n-m+1)

Submission status: Accepted

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

for i in range(n):
    if s[i]=="A":
        top=i
        break
q=s[::-1]

for i in range(n):
    if q[i]=="Z":
        bottom=n-i-1
        break
        
print(bottom-top+1)

Submission status: Accepted

Solution code:
s = input()
l = 0
r = 0
seen = False
for i in range(len(s)):
  if not seen and s[i] == 'A':
    l = i
    seen = True
  elif s[i] == 'Z':
    r = i
print(r-l+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,a,-1):
    if s[i] == 'Z':
        z = i
        break
print(z-a+1)

Submission status: Accepted

Solution code:
# ABC 053: B – A to Z String
s = input()
start = s.index('A')
end = s[::-1].index('Z')
print(len(s[start:len(s) - end]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s = list(input())
a=0
b=0
frag=True
for i in range(len(s)):
    if (s[i]=='A')and frag :
        a=i  
        frag=False
    elif s[i]=='Z':
        b=i
# print(a)
# print(b)
print(b-a+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
x = len(s)
y = 0
z = 0
a = x - 1
while(y <= x):
  if (s[y] == "A"):
    z = y
    break
  y += 1
while(y <= x):
  if (s[a]  == "Z"):
    print(str(a - z + 1))
    break
  a -= 1
  y += 1

Submission status: Accepted

Solution code:
s=list(input())
start=s.index("A")
end=[i for i, x in enumerate(s) if x == "Z"]
print(end[-1] - start + 1)

Submission status: Accepted

Solution code:
s=input()
ans=0
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 = input()

A_index = 0
Z_index = 0

for i in range(len(S)):
    if S[i] == 'A':
        A_index = i
        break
        
        
for i in range(len(S)-1, 0, -1):
    if S[i] == 'Z':
        Z_index = i
        break
        
print(len(S[A_index:Z_index+1]))

Submission status: Accepted

Solution code:
s =input()
A=0
Z=0

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

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

Submission status: Accepted

Solution code:
S = input()
s = [i for i in S]
a = S.find('A')
b = S.rfind('Z') - (a-1)
del s[:a]
del s[b:]
print(len(s))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = list(input())

ans1 = 0
ans2 = 0

for i in range(len(a)):
		if a[i] == 'A':
			ans1 = i
			break
for j in reversed(range(len(a))):
		if a[j] == 'Z':
			ans2 = j
			break

print(ans2 - ans1 +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(input())
a = s.index('A')
s.reverse()
b = s.index('Z')
print(len(s)-a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

s = list(s)

memo1=10000000000000000000000

ans = 0

for i in range(len(s)):
    if s[i] == 'A':
        memo1=min(memo1, i)
    if s[i] == 'Z':
        memo2=i
print(memo2-memo1+1)

Submission status: Accepted

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