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: Time Limit Exceeded

Solution code:
s = input()

count = []

for i in range(len(s)):
    if s[i] == "A":
        for j in range(i+1,len(s)):
            if s[j] == "Z":
                count.append(j-i+1)
print(max(count))

Submission status: Time Limit Exceeded

Solution code:
c = input()
s = []
for i in c:
    s.append(i)

list_a = []
list_z = []

while "A" in s:
    list_a.append(s.index("A"))
    s[s.index("A")] = "b"

while "Z" in s:
    list_z.append(s.index("Z"))
    s[s.index("Z")] = "v"

answer = list_z[-1] - list_a[0] + 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()

ans = 0

for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        if s[i:j][0] == "A" and s[i:j][-1] == "Z":
            if len(s[i:j]) > ans:
                ans = len(s[i:j])

print(ans)

Submission status: Time Limit Exceeded

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

def main():

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

    ans = 0
    count = 0

    for i in range(n):
        if listS[i] == 'A':
            for j in range(i, n):
                count += 1
                if listS[j] == 'Z':
                    if ans < count:
                        ans = count
            
            count = 0
            
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

while True:
  if s[0] == "A":
    break
  else:
    del s[0]
    
while True:
  if s[-1] == "Z":
    break
  else:
    del s[-1]
    
print(len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
n = len(s)
c = 0

for i in range(n-1):
    t = []
    if s[i] == "A":
        t = s[i:]
        for j in range(1,len(t)):
            if t[j] == "Z":
                l = j+1
                if l > c:
                    c = l


print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

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

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

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


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

    S = iss()
    s,e = 0,0

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

    print(len(S) - s - e)




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
x = []
tmp1 = []
tmp2 = []
for i in range(0,len(s)):
  if(s[i] == "A"):
    tmp1.append(i)
  if(s[i] == "Z"):
    tmp2.append(i)
    #x.append(len(s[tmp1:tmp2]))

for i in range(0,len(tmp1)):
  for j in range(0,len(tmp2)):
    x.append(abs(tmp1[i] - tmp2[j])+1)
print(max(x))

Submission status: Time Limit Exceeded

Solution code:
s = input()
x = []

for i in range(0,len(s)):
  for j in range(i,len(s)):
    if(s[i] == "A" and s[j] =="Z"):
      x.append(len(s[i:j+1]))
      
print(max(x))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
w = str(input())
#print(len(w))
la = []
lz =[]
ans = []
for i in range(len(w)):
  if w[i] == 'A':
    la.append(i)
  elif w[i] == 'Z':
    lz.append(i)
for i in range(len(la)):
  for j in range(len(lz)):
    a = lz[j] - la[i] + 1
    ans.append(a)

print(max(ans))

Submission status: Time Limit Exceeded

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)

for i in range(len(a)):
    for j in range(len(z)):
        if abs(z[j]-a[i]+1)>=ans:
            ans=abs(z[j]-a[i]+1)

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(l):
    if s[i]=="A":
        for j in range(i+1, l):
            if s[j]=="Z":
                if j-i+1>=ans:
                    ans=j-i+1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

l = len(s)
ans = 0
tmp = 0

for i in range(l-1):
    if s[i] == 'A':
        count = 1
        for j in range(i+1, l):
            count += 1
            if s[j] == 'Z':
                tmp = count

        ans = max(ans, tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
data = []
for i in range(len(s)):
    if s[i] == 'A':
        
        for j in range(i+1,len(s)):
           
            if s[j] == 'Z':
                data.append(j-i+1)
print(max(data))

Submission status: Time Limit Exceeded

Solution code:
s = [i for i in input()]
while s[0]!='A':
    s.pop(0)
while s[-1]!='Z':
    s.pop(-1)
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
s=input()

s = list(s)

ans = 0

for i in range(len(s)-1):
    if s[i] != 'A': continue
    for j in range(i+1,len(s)):
        if s[j] == 'Z':
            ans = max(ans, j-i+1)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
li = []
for i in range(len(s)):
    for j in range(len(s)):
        if s[i] == "A" and s[j] == "Z" and i < j:
            li.append(j - i + 1)
print(max(li))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

a_ind = [i for i, v  in enumerate(s) if v == "A"]
z_ind = [i for i, v in enumerate(s) if v == "Z"]
z_ind = [i for i in z_ind if i > min(a_ind)]

ans = z_ind[-1] - a_ind[0] + 1

print(ans)

Submission status: Time Limit Exceeded

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

def main():
    s = input()
    a_indexes = [i for i, c in enumerate(s) if c == "A"]
    z_indexes = [i for i, c in enumerate(s) if c == "Z"]
    max_length = 0
    for a_index in a_indexes:
        for z_index in z_indexes:
            if z_index - a_index > max_length:
                max_length = z_index - a_index
    print(max_length + 1)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()

anslist = []

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

betweenLength = []
for i in range(len(s)):
    if s[i] == 'A':
        for j in range(len(s)):
            if i < j and s[j] == 'Z':
                betweenLength.append(len(s[0:j]) + 1 - len(s[0:i]))

print(max(betweenLength))

Submission status: Time Limit Exceeded

Solution code:
mylist = list(input())
count = len(mylist)

for i in range(count):
    if mylist[0]=="A":
        count = len(mylist)
        for j in range(count,-1,-1):
            if mylist[j-1]=="Z":
                break
            else:
                mylist.pop()
    else:
        mylist.pop(0)

count = len(mylist)
print(count)

Submission status: Time Limit Exceeded

Solution code:
mylist = list(input())
count = len(mylist)

for i in range(count):
    if mylist[0]=="A":
        break
    else:
        mylist.pop(0)

count = len(mylist)

for j in range(count,-1,-1):
    if mylist[j-1]=="Z":
        break
    else:
        mylist.pop()
count = len(mylist)
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
mylist = list(s)
count = len(mylist)

for i in range(count):
    if mylist[0]=="A":
        break
    else:
        mylist.pop(0)

count = len(mylist)

for j in range(count,-1,-1):
    if mylist[j-1]=="Z":
        break
    else:
        mylist.pop()
count = len(mylist)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = list(inputs[0])
    max_len = None
    for i, c1 in enumerate(S):
        if c1 == "A":
            end_z = None
            for j, c2 in enumerate(S[i:]):
                if c2 == "Z":
                    end_z = j + i
            if end_z is not None:
                l = end_z - i
                if max_len is None or max_len < l:
                    max_len = l
    return max_len + 1


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ls = [char for char in s]
while True:
    if ls[0] != 'A':
        ls.pop(0)
    else:
        break
while True:
    if ls[-1] != 'Z':
        ls.pop(-1)
    else:
        break

print(len(ls))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
a_index = [i for i, x in enumerate(s) if x == 'A']
z_index = [i for i, x in enumerate(s) if x == 'Z']
distance = []

for i in a_index:
    for j in z_index:
        dis = abs(i-j)
        distance.append(dis)

print(max(distance)+1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

for i in range(len(s)):
    if s[i] == "A":
        a = i
        for j in range(len(s)):
            if s[j] == "Z":
                z = j+1
                if ans < len(s[a:z]):
                    ans = len(s[a:z])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = []

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
idx = ['s', 'e']
for i in range(len(s)):
    if s[i] == 'A' and idx[0] == 's':
        idx[0] = i
        if idx[0] != 's' and idx[1] != 'e':
            break
    if s[::-1][i] == 'Z' and idx[1] == 'e':
        idx[1] = -i
        if idx[0] != 's' and idx[1] != 'e':
            break
if idx[1] == 0:
    print(len(s[idx[0]:]))
else:
    print(len(s[idx[0]:idx[1]]))

Submission status: Time Limit Exceeded

Solution code:
s=input()
left,right=0,0
for i in s:
    if i=="A":
        left = s.index(i)
    elif i=="Z":
        right = s[::-1].index(i)
print(len(s)- right-left)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(str(input()))
pos_A = []
pos_Z = []
for i in range(len(s)):
  if s[i] == 'A':
    pos_A.append(i)
  elif s[i] == 'Z':
    pos_Z.append(i)

max_len = -1
for i in pos_A:
  for j in pos_Z:
    if i < j:
      if max_len < j - i + 1:
        max_len = j - i + 1
print(max_len)

Submission status: Time Limit Exceeded

Solution code:
s=input()
can=0
mayor=0
for i in range(len(s)):
  can=0
  can3=0
  can2=0
  if s[i]=="A":
    posicion=i
    a=len(s[posicion:])
    for i in range(len(s)-posicion):
      posicion2=i+posicion
      #print(s[i])
      if s[i+posicion]=="Z":
        if posicion2==a:
          can+=1
          break
        else:
          for i in range(len(s)-posicion2):   
            #if s[i+posicion2]=="Z":          
             # can+=1
            #else:
            if s[i+posicion2]!="Z":
              can2+=1
              #print("sdasd")
              #print(i+posicion,len(s)-posicion2)
              if i+posicion2==len(s)-1:
                can2=0
            else:
              can3+=1
          can3=can3+can2
        break 
      #elif s[i+posicion]=="Z":
        #can+=1
        #break
      elif i+posicion==len(s)-1 and s[i+posicion]!="Z":
        can=0
      else:
        can+=1
  can=can+can3
  if can>mayor:
    mayor=can
print(mayor)
'''
a=len(s[posicion:])

for i in range(len(s)-posicion):
  posicion2=i+posicion
  #print(s[i])
  if s[i+posicion]=="Z":
    if posicion2==a:
      can+=1
      break
    else:
      for i in range(len(s)-posicion2):   
        if s[i+posicion2]=="Z":          
          can+=1
        else:
          break
    break 
  #elif s[i+posicion]=="Z":
    #can+=1
    #break
  elif i+posicion==len(s)-1 and s[i+posicion]!="Z":
    can=0
  else:
    can+=1
print(can)
'''

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt_max = 0
for i, s_item in enumerate(s):
  if s_item == 'A':
    cnt = 1
    for ss_item in s[i+1:]:
      cnt += 1
      if ss_item == 'Z':
        if cnt > cnt_max:
          cnt_max = cnt

print(cnt_max)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
x=[]
for i in range(len(s)):
    for j in range(1,len(s)):
        if s[i]=="A" and s[j]=="Z":
           x.append(int(j-i+1))
print(max(x))

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=s.find("A")
z0=s.count("Z")
for i in range (z0-1):
    s=s[:s.find("Z")]+"a"+s[s.find("Z")+1:]
z=s.find("Z")
print(z-a+1)

Submission status: Time Limit Exceeded

Solution code:
# ABC053B - A to Z String
s = list(input())
while s[0] != 'A':
    s.pop(0)
while s[-1] != 'Z':
    s.pop()
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()

index_A = [n+1 for n, v in enumerate(S) if v == "A"]
index_Z = [n+1 for n, v in enumerate(S) if v == "Z"]

ans = 0
for i in range(len(index_A)):
    for j in range(len(index_Z)):
        if ans < index_Z[j] - index_A[i]:
            ans = index_Z[j] - index_A[i]
            
print(ans+1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
x=0
y=0
while x==0:
  if s[0]!="A":
    del s[0]
  else:
    x=1
while y==0:
  if s[-1]!="Z":
    del s[-1]
  else:
    y=1
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
for i in range(N):
    if S[i] == 'A':
        a_index = i
        break
for i in range(N):
    if S[::-1][i] == 'Z':
        z_index = i
        break

print(N - z_index - a_index)

Submission status: Time Limit Exceeded

Solution code:
s_list = list(input())
res = 0
for i,s1 in enumerate(s_list):
    if s1 == 'A':
        for j,s2 in enumerate(s_list[i:],i):
            if s2 == 'Z':
                res = max(res,len(s_list[i:j+1]))
print(res)

Submission status: Time Limit Exceeded

Solution code:
s_list = list(input())
res = 0
for i in range(len(s_list)):
    if s_list[i] == 'A':
        for j in range(i,len(s_list)):
            if s_list[j] == 'Z':
                res = max(res,len(s_list[i:j+1]))
print(res)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
l = []
x = []
for i in range(len(s)):
    for j in range(len(s)-1,0,-1):
        if s[i] == "A":
            l.append(i)
            if s[j] == "Z":
                x.append(j)
print(max(x)-min(l)+1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# B_A to Z String
import sys

s = input()

def getNum(s) :
    for i in range(len(s)):
        for j in reversed(range(len(s))):
            if s[i] == 'A' and s[j] == 'Z' :
                res = j - i + 1
                return res
print(getNum(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
temp = 0
for n, _ in enumerate(s):
    if s[n] == "A":
        for j, _ in enumerate(s[n:]):
            if s[n + j] == "Z":
                temp = j + 1
        ans = max(ans, temp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
str_line = [i for i in input()]
a_place = []
z_place = []
result = 0
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:
    for j in a_place:
        if i-j+1 >= result:
            result = i-j+1
print(result)

Submission status: Time Limit Exceeded

Solution code:
s = input()

maxlen = 0
for i, char_1 in enumerate(s):
  for j, char_2 in enumerate(s):
    if char_1=='A' and char_2=='Z' and maxlen < j - i + 1:
      maxlen = j - i + 1
print(maxlen)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = 0
e = 0
ans = 0
for k in range(len(S)-1):
    if S[k]=="A":
        s = k
        e = k+1
        for l in range(k+1,len(S)):
            if S[l]=="Z":
                e = max(e,l)
    ans = max(ans,e-s+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def getZ_index(input_list):
    for index, i in enumerate(reversed(input_list)):
        if i == 'Z':
            return len(input_list) - index
    return 0


lis = list(input())
max_num = 0
for index, i in enumerate(lis):
    if i == 'A':
        if 'Z' in lis[index: len(lis)]:
            max_num = max(max_num, getZ_index(
                lis[index: len(lis)]))
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
s=list(input()+"a")
n=len(s)-1
list=[]
for i in range(n):
    if s[i]=="A":
        for j in range(i+1,n+1):
            if s[j]=="Z" and s[j+1]!="Z":
                list.append(j-i+1)
print(max(list))

Submission status: Time Limit Exceeded

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

s = rls()
a = 0
z = 0
for i in range(len(s)):
    if(s[i] == "A"):
        a = i
        break
for i in range(len(s[::-1])):
    if(s[::-1][i] == "Z"):
        z = len(s) - i
        break
print(z-a)

Submission status: Time Limit Exceeded

Solution code:
s = input()
aindex, zindex = None, None
for i in range(len(s)):
    if s[i] == 'A' and aindex == None:
        aindex = i
    if s[::-1][i] == 'Z' and zindex == None:
        zindex = len(s)-i
    if aindex != None and zindex != None:
        break

print(zindex-aindex)

Submission status: Time Limit Exceeded

Solution code:
s = input()
tmp = 0
for idx, n in enumerate(s):
	if n=='A': 
		for idxx, nn in enumerate(s[-1:idx:-1]):
			if nn=='Z':
				tmp = max((len(s)-idxx)-idx, tmp)
		
print(tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
S=len(s)
mi=[]
ma=[]
for i in range(S):
    if s[i]=='A':
        mi.append(i)
    elif s[i]=='Z':
        ma.append(i)
print(max(ma)-min(mi)+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
strFindA = ''
strFindZ = ''

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

for i in reversed(range(len(strFindA))):
  if strFindA[i] == "Z":
    strFindZ = strFindA[:i+1]
    break

print(len(strFindZ))

Submission status: Accepted

Solution code:
s = input()

first = s.index('A')
end = s.rindex('Z')

ans = end - first + 1
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

for i,j in enumerate(s):
    if j == 'A':
        a = i
        break
for i,j in enumerate(s):
    if j == 'Z':
        z = i
print(z-a+1)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = 0
z = n - 1

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

for i in range(n):
    if s[i] == "Z":
        z = i

print(z - a + 1)

Submission status: Accepted

Solution code:
s = input()

first = s.find("A")
end = s.rfind("Z")

length = end - first + 1
print(length)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

i = s.find("A")
j = s.rfind("Z")

print(j + 1 - i)

Submission status: Accepted

Solution code:
def answer(s: str) -> int:
    return s.rfind('Z') - s.find('A') + 1


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
retu = input()
kari = 0
flag = False
for i in range(len(retu)):
    if flag:
        kari += 1
        if retu [i] == 'Z':
            an = kari
    elif retu[i] == 'A':
        flag = True
        kari += 1
print(an)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    S = input()
    search_string=['A','Z']
    position=[]

#Aを探す
    for i,s in enumerate(S):
        if s==search_string[0]:
            position.append(i)
            break

#Zを探す
    for r_i,r_s in enumerate(reversed(S)):
        if r_s==search_string[1]:
            position.append(len(S)-r_i)
            break

    print(position[1]-position[0])

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
st = s.find("A")
for i in range(len(s)):
  n = len(s)-i-1
  t = s[n]
  if t == "Z":
    en = n
    break
print(en - st + 1)

Submission status: Accepted

Solution code:
s = list(input())

for i in range(len(s)):
    if s[i] == "A":
        A = i
        break
for i in range(len(s)):
    if s[i] == "Z" and i > A:
        B = i

    
print(B - A + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()
print(a.rindex("Z")-a.index("A")+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(1, len(s) + 1):
   if s[(-1) * i] == 'Z':
      end = i
      break

print(len(s) - end - start + 1)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()
len = len(S)
start = len
end = 0
for i in range(len):
  if(S[i] == "A"):
    temp_start = i+1
    start = min(start,temp_start)
  if(S[i] == "Z"):
    temp_end = i+1
    end = max(end,temp_end)
print(end-start+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
S=S[::-1]
for i in range(len(S)):
  if S[i]=="Z":
    end = len(S)-i
    break
print(end-start)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

for j, x in enumerate(s[::-1]):
    if x == "Z":
        break

print(len(s) - i - j)

Submission status: Accepted

Solution code:
s = input()
a_number = 0
z_number = 0

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

for j in reversed(range(len(s))):
    if s[j] == 'Z':
        z_number = j
        break

print(z_number - a_number + 1)

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 = input()
a_idx = None
for i, c in enumerate(list(s)):
    if c == 'A':
        a_idx = i
        break
z_idx = None
for i, c in enumerate(reversed(list(s))):
    if c == 'Z':
        z_idx = len(s) -i
        break
print(len(s[a_idx:z_idx]))

Submission status: Accepted

Solution code:
s=input()
x=s.find('A')
s2=s[x:]
y=s.rfind('Z')
print(y-x+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()
b=a[::-1]
p=0

for i in range(len(a)):
  if a[0] !='A':
    a=a[1:]
  else:
    break
    
for i in range(len(a)):
  if a[-1] !='Z':
    a=a[:-1]
  else:
    break
    
    
print(len(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

max_len = 0
past = -1
for i in range(len(s)):
    if s[i] == 'A' and past == -1:
        past = i
        continue
    if s[i] == 'Z':
        max_len = max(max_len, i - past + 1)

print(max_len)

Submission status: Accepted

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

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

Submission status: Accepted

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


def read():
    s = input().strip()
    return s,


def solve(s):
    a, z = 0, len(s)-1
    while s[a] != "A":
        a += 1
    while s[z] != "Z":
        z -= 1
    return z-a+1


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

Submission status: Accepted

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

for i in range(len(s)):
    if s[i] == 'A':
        start = min(start , i)
    if s[i] == 'Z':
        end = max(end, i)
    ans = end - start + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
first_a_index = s.index('A')
last_z_index = len(s) - list(reversed(s)).index('Z')
print(last_z_index - first_a_index)

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 = input()
size = len(s)
for i in range(size):
    if s[i] == 'A':
        head = i
        for j in range(size):
            if s[-1-j] == 'Z':
                tail = j 
                break
        break 
print(size-head-tail)