Problem:


Score : 200 points

Problem Statement

Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).

Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

Constraints

1 ≦ |s| ≦ 200{,}000

s consists of uppercase English letters.

There exists a substring of s that starts with A and ends with Z.

Input

The input is given from Standard Input in the following format:

s

Output

Print the answer.

Sample Input 1

QWERTYASDFZXCV

Sample Output 1

5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Sample Input 2

ZABCZ

Sample Output 2

4

Sample Input 3

HASFJGHOGAKZZFEGA

Sample Output 3

12



Sample input:
QWERTYASDFZXCV


Sample output:
5

Submission status: Accepted

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

i = 0
while i<n:
  if s[i] == "A":
    break
  i += 1
j=n-1
while j>0:
  if s[j] == "Z":
    break
  j -= 1
print(j-i+1)

Submission status: Accepted

Solution code:
s = input()

flag = 0

a = 200000
z = 0

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

    elif s[i] == "Z" and z < i:
        z = i

print(z - a + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
f = 200001
l = -1
for i, c in enumerate(S):
    if(c == "A"):
        f = min(f, i)
    if(c == "Z"):
        l = max(l, i)

print(l-f+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
for i,s in enumerate(S):
    if s == 'A':
        a = i
        break

for i,s in enumerate(S):
    if s == 'Z':
        b = i
print(b - a +1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

ai = 200001
zi = 0

for i in range(len(S)):
  if S[i] == "A":
    ai = min(ai,i)
  elif S[i] == "Z":
    zi = max(zi,i)
    
#print(S[ai:zi+1])
print(zi-ai+1)

Submission status: Accepted

Solution code:
s = input()
flag = False
start, end = 0, 0
for i, elem in enumerate(s):
    if elem == "A" and not(flag):
        flag = True
        start = i
    if elem == "Z" and flag:
        end = i
print(end - start + 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,0,-1):
    if s[i]=='Z':
        b=i
        break
print(b-a+1)

Submission status: Accepted

Solution code:
s=input()
for a,b in enumerate(s):
  if b=='A':break
  x=a
for c,d in enumerate(reversed(s)):
  if d=='Z':break
  y=c
print(len(s)-a-c)

Submission status: Accepted

Solution code:
s = input()

r = 0
l = 0
flag = True
for i in range(len(s)):
  if flag and s[i] == 'A':
    r = i
    flag = False
  if s[i] == 'Z':
    l = i


print(l-r+1)

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

Solution code:
s = input()

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

b = 0
for i in range(len(s)):
    if s[i] == "Z":
        b = i

print(b-a+1)

Submission status: Accepted

Solution code:
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

s = ns()

ai = s.index("A")
zi = len(s) - s[::-1].index("Z") - 1

print(zi - ai + 1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

a = s.index('A')
b = list(reversed(s)).index('Z')

print(n-a-b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
Z_max = [i for i, x in enumerate(S) if x == 'Z']
print(len(S[S.index('A'):max(Z_max)+1]))

Submission status: Accepted

Solution code:
s = input()

start = s.index("A")

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

count=0
i=0
A=0
while count==0:
    if s[i]=='A':
        count+=1
        A=i
    i+=1

count2=0
j=len(s)-1
Z=0
while count2==0:
    if s[j]=='Z':
        count2+=1
        Z=j
    j-=1

print(Z-A+1)

Submission status: Accepted

Solution code:
s = list(input())

a_index = 0
z_index = 0
max_z_index = 0

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

for j in range(len(s)):
    if j <= a_index:
        continue
    else:
        if s[j] == "Z":
            z_index = j
            max_z_index = max(max_z_index, z_index)

print(max_z_index - a_index + 1)

Submission status: Accepted

Solution code:
s = list(input())

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

for j in range(len(s)):
    if s[j] == 'Z':
        zIndex = j

print(zIndex-aIndex+1)

Submission status: Accepted

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

print(len(s)-a-b)

Submission status: Accepted

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

def main():
    s = list(input())
    start = s.index('A')
    s.reverse()
    end = len(s) - s.index('Z')
    print(end - start)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    s = input()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = z = 0
f = True
for i, s in enumerate(input()):
  if f and s == 'A': 
    a = i
    f = not f
  elif s == 'Z':
    z = i
print(z - a + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

s = input()

print(max([len(text) for text in re.findall("A.*Z", s)]+[0]))

Submission status: Accepted

Solution code:
s = input()
a_idx, z_idx = 200000, 0

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

Submission status: Accepted

Solution code:
# input
s = input()

i = 0

while s[i] != 'A':
    i += 1

j = len(s) - 1

while s[j] != 'Z':
    j -= 1

ans = j - i + 1
print(ans)

Submission status: Accepted

Solution code:
S=list(input())

l=len(S)

for i in range(l):
    if S[i]=="A":
        a=i
        break

for i in range(l-1,-1,-1):
    if S[i]=="Z":
        b=i
        break

print(b-a+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
ans = s.rfind('Z') - s.find('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()
l = s.index("A")
r = s[::-1].index("Z")
print(len(s)-r-l)

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:
def main():
    S = input()
    S_start = S.find("A")
    S_fin = S.rfind("Z")
    if S_start != -1 and S_fin != -1:
        print(S_fin - S_start + 1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    s = input()


    flag = 0
    t = ""
    u = ""

    for i in s:
        if i == "A":
            flag = 1
        if flag == 1:
            t += i

    flag = 0

    for i in t[::-1]:
        if i == "Z":
            flag = 1
        if flag ==1:
            u += i

    print(len(u))

if __name__ == "__main__":
        main()

Submission status: Accepted

Solution code:
s = input()

flag = False
start = 0
end = 0
for i in range(len(s)):
    if not flag and s[i] == 'A':
        start = i
        flag = True
    if s[i] == 'Z':
        end = i
print(end - start + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input()
b = ""
c=""
counterf=0
counter =0


for x in a:
    if x == "A":
        b+=x
        counterf +=1
    elif counterf >=1:
        b+=x
        
for x in b[::-1]:
    if x == "Z":
        c+=x
        counter+=1
    elif counter >=1:
        c+=x
print(len(c))

Submission status: Accepted

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

s = input()

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

Submission status: Accepted

Solution code:
atoz = list(input())
A_num = 0
Z_num = 0
for i, j in enumerate(atoz):
    if j == "A" and A_num == 0:
        A_num = i + 1
    elif j == "Z" and A_num < i:
        Z_num = i + 1
    else:
        pass
    
print(Z_num - A_num+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
string = input()

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

Submission status: Accepted

Solution code:
S = list(input())

first_clock = 0
last_clock = 0
F_count = 0
L_count = 0
count = -1

for i in S:
    count += 1
    if i == "A" and first_clock == 0:
        F_count = count
        first_clock = 1
    if i == "Z":
        L_count = count

else:
    print(L_count - F_count + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=raw_input()
L=len(s)
prefix=suffix=0
for i in xrange(L):
  if s[i]=='A': break
  prefix += 1
for i in xrange(L):
  if s[L-1-i]=='Z': break
  suffix += 1
print L-prefix-suffix

Submission status: Accepted

Solution code:
s = input()

for i, s_i in enumerate(s):
    if s_i == 'A':
        start = i
        break

for i, s_i in enumerate(s[::-1]):
    if s_i == 'Z':
        end = len(s) - i
        break

print(end - start)

Submission status: Accepted

Solution code:
s = input()

num_A = 0
num_Z = 0

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

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

print(num_Z - num_A + 1)

Submission status: Accepted

Solution code:
import re
print(len(re.search('A\w*Z',input()).group(0)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
slist = list(s)
slr = slist[::-1]
slen = len(s)
ans1 = 0
ans2 = 0
for i in range(0,slen+1):
    if slist[i] == 'A':
        ans1 = i
        break
    else:
        pass
for j in range(0,slen+1):
    if slr[j] == 'Z':
        ans2 = slen - j
        break
    else:
        pass
print(ans2 - ans1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
Aindex = s.find("A")
Zindex = -1
for index,character in enumerate(s[Aindex:]):
    if character == "Z":
        Zindex = index + Aindex
print(len(s[Aindex:Zindex+1]))

Submission status: Accepted

Solution code:
s = input()

length = len(s)

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

for i in range(length):
    if s[length-i-1] == "Z":
        end = length-i-1
        break

print(end-begin+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=0
l=0
n=0
for i in list(input().strip()):
  n+=1
  if i=="A" and s==0:
    s=n
  if i=="Z" and s>=1:
    l=n
print(l-s+1)

Submission status: Accepted

Solution code:
s = input()
i = 0
while i < len(s) and s[i] != "A":
    i += 1

j = len(s) - 1
while j > 0 and s[j] != "Z":
    j -= 1

print(j - i + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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)):
    if s[len(s)-1-i] == "Z":
        b = len(s)-1-i
        break
print(b-a+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str = input('')
start = -1
end = -1
for x in range(len(str)):
  if str[x] == 'A' and start == -1:
    start = x
  elif str[x] == 'Z':
    end = x
print(end - start + 1)

Submission status: Accepted

Solution code:
s = input()

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

z_idx = len(s)
for j in range(len(s)-1, -1, -1):
    if s[j] == 'Z':
        z_idx = j
        break

print(z_idx-a_idx+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

start = 0
end = len(s) - 1

while True:
    if s[start] == "A":
        break
    start += 1
    
while True:
    if s[end] == "Z":
        break
    end -= 1
    
print(end - start + 1)

Submission status: Accepted

Solution code:
strings = list(input())

num_a = 0
num_z = 0
flag = 0
for i in range(len(strings)):
    if strings[i]=='A' and flag==0:
        num_a = i
        flag = 1
    if strings[i]=='Z':
        num_z = i
x = num_z-num_a+1
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

s = arr_data[0][0]


print(s.rfind("Z")-s.find("A")+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]:
    if S[i]=="Z":
        end = i
        break
        
print(end-start+1)

Submission status: Accepted

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

print Z - A + 1

Submission status: Accepted

Solution code:
a = input()
b = len(a)
aa = 0
zz = 0
for i in range(b-1,-1,-1):
    if a[i] == 'Z':
        zz = i
        break
for i in range(b):
    if a[i] == 'A':
        aa = i
        break

print(zz-aa+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    s = list(input())
    a_position = s.index('A')
    z_position = len(s) - s[::-1].index('Z') - 1

    print(z_position - a_position + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

start = -1
end = -1

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

for i, s in enumerate(reversed(S)):
    if s == 'Z':
        end = len(S) - i
        break

print(end - start)

Submission status: Accepted

Solution code:
S=input()
N=len(S)
x=0
y=N-1
p=True
q=True
for i in range(N):
  if S[i]=="A" and p:
    x=i
    p=False
  if S[N-i-1]=="Z" and q:
    y=N-i-1
    q=False
print(y-x+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s=input()
begin=0
end=0
for i in range(len(s)):
    if(s[i]=="A"):
        begin=i
        break

for i in range(len(s)):
    if(s[-1*(i+1)]=="Z"):
        end=len(s)-i
        break
print(end-begin)

Submission status: Accepted

Solution code:
s = input().strip()
print(s.rindex('Z') - s.index('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)
    elif S[i]=="Z":
        Z.append(i)

print(Z[-1]-A[0]+1)

Submission status: Accepted

Solution code:
a = list(input())
cou = len(a)
b = 0
c = -1
while a[b] != "A":
    cou -= 1
    b += 1
while a[c] != "Z":
    cou -= 1
    c -= 1
print(cou)

Submission status: Accepted

Solution code:
s = input()
isAdd = False
l = -1
r = -1
for i in range(len(s)):
    if s[i] == 'A' and l == -1: l = i
    if s[len(s)-1-i] == 'Z' and r == -1: r = len(s)-1-i

print(r-l+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
s = input()
ma = re.search(r"A.+Z", s)
print(len(ma.group()))

Submission status: Accepted

Solution code:

s = input()

while True:
    if s[0] != 'A':
        s = s[1:]
        continue
    if s[-1] != 'Z':
        s = s[:-1]
        continue
    break

print(len(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    """
    |s| <= 2 * 10 ** 5
    """
    s = input()

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

    for i, c in enumerate(s[start + 1:], start + 1):
        if c == "Z":
            end = i

    ans = end - start + 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
print(len(input().lstrip("BCDEFGHIJKLMNOPQRSTUVWXYZ").rstrip("ABCDEFGHIJKLMNOPQRSTUVWXY")))

Submission status: Accepted

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

print(goal - start + 1)

Submission status: Accepted

Solution code:
val =input()
res = val.find("A")
res2 = len(val) - val[::-1].find("Z")
print(res2-res)

Submission status: Accepted

Solution code:
def main():
    S = list(input())
    A = []
    Z = []
    for x in range(len(S)):
        if S[x] == "A":
            A.append(x)
        elif S[x] == "Z":
            Z.append(x)

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve():
    s = list(input())
    posi_A = s.index("A")
    s.reverse()
    posi_Z = s.index("Z")

    print( (len(s) - posi_Z) - posi_A)


solve()

Submission status: Accepted

Solution code:
s = input()
a_pos = s.index("A")
z_pos = s.rindex('Z')

print(z_pos + 1 - a_pos)

Submission status: Accepted

Solution code:
import re
S = input()
print(max(len(it.group()) for it in re.finditer("A[A-Z]*Z", S)))

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 = float('inf')
z = -1
 
s = input()
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()

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

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

print(len(s)-cnt_Z-cnt_A)

Submission status: Accepted

Solution code:
a = 10**9
z = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s = input()
    max_len = -1
    idx_a, idx_z = [], []
    for i in range(len(s)):
        if s[i] == 'A':
            idx_a.append(i)
        if s[i] == 'Z':
            idx_z.append(i)
    print(max(idx_z)-min(idx_a)+1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

Solution code:
def solution():
	a = raw_input()
		
	aIdx = 0
	zIdx = 0
	maxLength = 0
	hasSet = False
	for i in range(len(a)):
		if a[i] == 'A' and not hasSet:
			aIdx = i
			hasSet = True
		
		if a[i] == 'Z':
			zIdx = i 

	print zIdx - aIdx + 1

solution()

Submission status: Accepted

Solution code:
s = input()

indexA = 0
indexZ = len(s)

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

s = s[::-1]

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

print(indexZ - indexA)

Submission status: Accepted

Solution code:
import re
s = input()
a = re.search(r"A.+Z", s)
print(len(a.group()))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    S = input()
    A = 2 ** 100
    Z = 2 ** 100
    res = 0
    for x,y in enumerate(S):

        if y == 'A':
            A = min(A,x)
        if y == 'Z':
            Z = x
            res = max(res, (Z - A) + 1)
    print (res)

Submission status: Accepted

Solution code:
import sys
inp = sys.stdin.read().strip()
ctr, maks = -1, 0
for idx in range(len(inp)):
	if inp[idx] == 'A' and ctr == -1:
		ctr = 1
	else:
		if ctr != -1: ctr += 1
		if inp[idx] == 'Z':
			maks = max(ctr, maks)
print maks