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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
S = inputS()
N = len(S)
for i in range(N):
  if S[i] == "A":
    a = i
    break
for i in range(N)[::-1]:
  if S[i] == "Z":
    z = i
    break

print(z-a+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

for ind, i in enumerate(s):
    if i == 'A':
        num1 = ind
        break

for ind, i in enumerate(s):
    if i == 'Z':
        num2 = ind

print(num2 - num1 + 1)

Submission status: Accepted

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

abc053_b()

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = end - start + 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

def solve(s):
    maximum = 0
    a = 0
    counting = False
    for i in s:
        if i == "A":
            counting = True
        
        if counting == True:
            a += 1
        
        if i == "Z" and counting == True:
            maximum = a
    
    print(maximum)
        

solve(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
print(len(s[s.find('A'):s.rfind('Z')+1]))

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()
a = float('inf')
z = 0
for i, c in enumerate(s):
    if c == 'A':
        a = min(i, a)
    elif c == 'Z':
        z = max(i, z)
print(z - a + 1)

Submission status: Accepted

Solution code:
s = str(input())

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

print(z-a+1)

Submission status: Accepted

Solution code:
s = input()
a = []
z = []
for index,ss in enumerate(s):
	if ss == "A":
		a.append(index)
	elif ss == "Z":
		z.append(index)
print((z[-1]-a[0])+1)

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()
start = -float('inf')
best_length = -float('inf')
for i,w in enumerate(s):
  if w=='A' and start < 0:
    start = i
  elif w=='Z' and start >= 0:
    length = i - start + 1
    if length > best_length:
      best_length = length
print(best_length if best_length > 0 else 0)

Submission status: Accepted

Solution code:
l=list(input())
a_l =[i for i,x in enumerate(l) if x=='A']
z_l =[i for i,x in enumerate(l) if x=='Z']
if z_l[-1]-a_l[0] > 0:
    print(z_l[-1]-a_l[0]+1)

Submission status: Accepted

Solution code:
s = input()
ans = 0
tmp = 0
flg = 0
for i in range(len(s)):
  if s[i] == 'A' and flg == 0:
    ans += 1
    flg = 1
  elif flg == 1 and s[i] == 'Z':
    flg = 2
    ans += 1
  elif flg == 1:
    ans += 1
  elif flg == 2 and s[i] == 'Z':
    ans += tmp+1
    tmp = 0
  elif flg == 2:
    tmp += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())

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

Submission status: Accepted

Solution code:
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
a=input()
A=0
Z=0
Adone=False
for i in range(len(a)):
    if(a[i]=='A' and not Adone):
        A=i 
        Adone=True
    elif(a[i]=='Z'):
        Z=i 
ans=Z-A+1
print(ans)

Submission status: Accepted

Solution code:
s = input()
top, last = 0, 0
for i, c in enumerate(s):
    if c == 'A':
        top = i
        break

for j, c in enumerate(s[::-1]):
    if c == 'Z':
        last = len(s) - j
        break
print(last - top)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s = input()

a_index = s.index("A")
z_index = int()
for i in range(len(s)):
    if s[i] == "Z":
        z_index = i

ans = z_index - a_index + 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    s = list(input())

    n = len(s)
    start = -1
    for i in range(n):
        if s[i] == 'A' and start == -1:
            start = i
        if s[i] == 'Z':
            end = i

    ans = end - start + 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = list(map(str, input().rstrip()))

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

for i, s in enumerate(S[::-1]):
    if s=="Z":
        end = i
        break

print(len(S[start:len(S)-end]))

Submission status: Accepted

Solution code:
s = 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 = input()
i = s.find("A")
j = s.rfind("Z")

print(j-i+1)

Submission status: Accepted

Solution code:
s = input()

ans_a = s.index("A")
ans_z = s.rfind("Z")

print(ans_z - ans_a + 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()

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

print(z - a + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC053 B

def main():
    s = input()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
L = len(s)
for i in range(L):
    if s[i] == 'A':
        break
for j in range(1, L):
    if s[-j] == 'Z':
        break
print(L - i - j + 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()
a = s.find("A")
z = s.rfind("Z")
print(len(s[a:z+1]))

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def main():
    s = input()
    n = len(s)
    l = 0
    r = n - 1
    while l < n and s[l] != 'A':
        l += 1
    while r >= 0 and s[r] != 'Z':
        r -= 1
    print(r - l + 1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()
A = ''
Z = ''
for i, s in enumerate(S):
    i += 1
    if A == '':
        if s == 'A':
            A = i
    if not A == '':
        if s == 'Z':
            Z = i
print(Z - A + 1)

Submission status: Accepted

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

print(lz[-1] - la[0] + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

i=0
while i<len(S):
    if S[i]=='A':
        break  
    i+=1  
j=1
while j<=len(S):
    if S[-j]=='Z':
        break
    j+=1

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

Submission status: Accepted

Solution code:
def main():
    s = input()

    a_index = []
    z_index = []

    for i, ss in enumerate(s):
        if ss == 'A':
            a_index.append(i)
        elif ss == 'Z':
            z_index.append(i)
    print(max(z_index)-min(a_index)+1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = str(input())
a = 200000
z = 0
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 = input()
print(len(S[S.find('A'):S.rfind('Z')+1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
A1=0
A2=0
for i in range(len(s)):
    if s[i]=='A':
        A1=i
        break
    else:
        continue
for t in range(len(s)-1,1,-1):
    if s[t]=='Z':
        A2=t
        break
    else:
        continue
print(A2-A1+1)

Submission status: Accepted

Solution code:
s=input()
for i in range(len(s)):
    if s[i]=="A":
        x=i#"A"のインデックス番号
        break
for i in range(1,len(s)):
    if s[-i]=="Z":
        y=len(s)-i#"Z"のインデックス番号
        break
ans=y-x+1
print(ans)

Submission status: Accepted

Solution code:
s = input()

a = s.index("A")
b = s[::-1].index("Z")

print(len(s) - b - a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

first = s.find('A')
last = s.rfind('Z')

print(len(s[first:last+1]))

Submission status: Accepted

Solution code:
s = input()

n = len(s)

for a in range(0, n):
    if s[a] == 'A':
        start = a
        break

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

print(end+1-start)

Submission status: Accepted

Solution code:
s = input()
ls = len(s)
for i in range(ls):
  if s[i]=="A":
    firstA = i
    break
for i in range(ls):
  if s[ls-1-i]=="Z":
    lastZ = ls-i
    break
print(lastZ-firstA)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

S = input()

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:
s = input()
i, j = 0, len(s)-1
while True:
  if s[i] == 'A':
    break
  i += 1
  
while True:
  if s[j] == 'Z':
    break
  j -= 1
  
print(j-i+1)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s = input()

A_list = []
Z_list = []

for i, char in enumerate(s, 1):
    if char == "A":
        A_list.append(i)

for i, char in enumerate(s, 1):
    if char == "Z":
        Z_list.append(i)

print(int(max(Z_list) - min(A_list) + 1))

Submission status: Accepted

Solution code:

s = input()

A = [i for i, x in enumerate(s) if x == "A"]
Z = [i for i, x in enumerate(s) if x == "Z"]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = -1
z = 0
for i, c in enumerate(input()):
  if c == "A" and a == -1: a = i
  if c == "Z": z = i

print(z-a+1)

Submission status: Accepted

Solution code:
S = input()

a = None
z = None
for i in range(len(S)):
    if a is None and S[i] == "A":
        a = i

    if z is None and S[~i] == "Z":
        z = len(S) - i

print(z - a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
start = 0
end = 0

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

for x in reversed(s):
    if x == 'Z':
        break
    else:
        end += 1

print(len(s) - start - end)

Submission status: Accepted

Solution code:
s=input()
a=len(s)
z=0
for i in range(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:
import sys
def input(): return sys.stdin.readline().strip()

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

Submission status: Accepted

Solution code:
s = input()

st = None
en = None
for i in range(len(s)):
    if st is None and s[i] == 'A':
        st = i
    if en is None and s[-i-1] == 'Z':
        en = -i - 1
print(len(s[st:en]) + 1)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc053/tasks/abc053_b

s = input()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
print(len(s)-''.join(reversed(s)).find('Z')-s.find('A'))

Submission status: Accepted

Solution code:
import re
s = input()
print(len(max(re.findall(r"A.*Z", s))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=list(input().rstrip())
for i in range(len(s)):
    if s[i]=="A":
        st=i
        break
for i in range(len(s)):
    if s[i]=="Z":
        stop=i
print(stop-st+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    s = input()
    for i,c in enumerate(s):
        if c == "A":
            a_pointer = i+1
            break

    for i,c in enumerate(s):
        if c == "Z":
            b_pointer = i+1
            continue
    print(b_pointer - a_pointer +1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

sl = list(s)

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

print (en-st+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Ans2=0
for index in reversed(range(0,len(s))):
    if s[index]=="Z":
        Ans2=index
        break
        
print(Ans2-Ans1+1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    s = input()

    loc_A = min([i for i, x in enumerate(s) if x == 'A'])
    loc_Z = max([i for i, x in enumerate(s) if x == 'Z'])
    print(loc_Z - loc_A + 1)


main()

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    s =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = s.rfind('Z')-s.find('A')+1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

a = S.index("A")
b = [i for i, x in enumerate(S) if x == 'Z']
c = 0
for i in range(len(b)):
    if c <= b[i]:
        c  = b[i]
print(c-a+1)

Submission status: Accepted

Solution code:
import re
S = str(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    n = input()
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    s = n.index("A")

    emax=0
    for i in range(len(n)):
        if n[i] == "Z":
            emax = i

    print(emax - s +1)


resolve()

Submission status: Accepted

Solution code:
#Beginner 053 C
s = str(input())
L = len(s)

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

for j in reversed(range(L)):
    if s[j] == "Z":
        break

print(j-i+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

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

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

Submission status: Accepted

Solution code:
I = lambda: map(int, input().rstrip().split())
s = input()
flag = 1
for i in range(len(s)):
    if s[i] == "A" and flag == 1:
        start = i
        flag = 0
    elif s[i] == "Z":
        end = i
print(end - start + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

s = input()[:-1]

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:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    s = IS()
    n = len(s)
    l = r = 0
    for i,si in enumerate(s):
        if si == 'A':
            l = i
            break
    for i,si in enumerate(s[::-1]):
        if si == 'Z':
            r = n-i
            break
    print(r-l)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

s=input()

flag=False
cnt=1
ans=0
for i in range(len(s)):
    if flag:
        cnt+=1
        if s[i]=='Z':
            ans=cnt
    else:
        if s[i]=='A':
            flag=True
print(ans)

Submission status: Accepted

Solution code:
def resolve():
	s = input()
	a = len(s) - 1
	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()

f = s.find('A')
r = s.rfind('Z')

print(r-f+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    import re
    S = input()
    A = min([m.start() for m in re.finditer("A", S)])
    Z = max([m.start() for m in re.finditer("Z", S)])
    print(Z-A+1)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
start = end =  float("Inf")

flag = False
for i in range(len(S)):
    if S[i] == "A" and not flag:
        start = i
        flag = True
    if S[i] == "Z" and flag:
        end = i + 1

print(len(S[start:end]))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()

    flg = False
    idx_A = 0
    idx_Z = -1
    for idx, i in enumerate(s):
        if i == "A" and not flg:
            idx_A = idx
            flg = True

        if i == "Z" and flg:
            idx_Z = idx

    print(max(0, idx_Z - idx_A + 1))


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

flag = 0
pos_a, pos_z = 1, 1
length = 0

for i, ltr in enumerate(s, 1):
  if ltr == 'A' and flag == 0:
    pos_a = i
    flag = 1
  elif ltr == 'Z' and flag == 1:
    pos_z = i
    if pos_z - (pos_a -1) > length:
      length = pos_z - (pos_a -1)
    else:
      flag = 0

print(length)

Submission status: Accepted

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

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

for i in range(len(s)):
    if sr[i] == 'Z':
        right = i
        break

print(len(s) - right - left)

Submission status: Accepted

Solution code:
S = input()
ans = 0

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

print(ans)

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(end - start + 1)

Submission status: Accepted

Solution code:
s = str(input())
j = 0
f = 0
e = 0
for i in range(len(s)):
    if s[i] == "A" and j == 0:
        j = 1
        f = i
    elif s[i] == "Z":
        e = i
print(e - f + 1)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    S = input()
    L = len(S)
    for i in range(L):
        if S[i] == 'A':
            left = i
            break
    for i in range(L-1,0,-1):
        if S[i] == 'Z':
            right = i
            break
    print(right-left+1)

if __name__ == '__main__':
    main()