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

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

Solution (Python):
if __name__=="__main__":
    [s] = input().split()
    a_pos = s.find("A")
    z_pos = (len(s) - 1) - s[::-1].find("Z")

    print(z_pos - a_pos + 1)

Solution (Python):
import sys
input_lines1 = sys.stdin.readlines()
for line in input_lines1:
    strBuf = line.replace('\n', '').split(' ')
    maxValue = 0
    index = 0
    start = -1
    end = 0
    for idx in range(len(strBuf[0])) :
        if start == -1 :
            if strBuf[0][idx:idx+1] == 'A' :
                start = idx
            else:
                continue

        if strBuf[0][idx:idx+1] == 'Z' :
            if not 'Z' in strBuf[0][idx+1:] :
                end = idx
                break
print end - start + 1

Solution (Python):


def main():
    str=input()
    a,b=0,0
    l=len(str)
    
    for i in range(l):
        if(str[i]=='A'):
            a=i
            break
    for i in reversed(range(l)):
        if(str[i]=='Z'):
            b=i
            break
    print(b-a+1)
        


if __name__=="__main__":
    main()

Solution (Python):
S = input()
i = 0
for char in S:
    if char == "A":
        first = i
        break
    else:
        i += 1
n = 0
for char in S[::-1]:
    if char == "Z":
        last = n
        break
    else:
        n += 1

print(len(S[i:len(S)-n]))

Solution (Python):
s=input()
while s[0] != 'A':
  s = s[1:]
while s[-1] != 'Z':
  s = s[:-1]
print(len(s))

Solution (Python):
s = input()

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

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

Solution (Python):
import re
print(max(map(len, re.findall("A.*Z", input()))))

Solution (Python):
import re

r = re.compile(r"A.*Z")
print(max(map(len, r.findall(input()))))

Solution (Python):
s = input()
posA = s.find('A')
posZ = len(s) - s[::-1].find('Z') - 1 
print(posZ - posA + 1)

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

Solution (Python):


def main():
    a = str(input())
    print(a.rindex('Z') - a.index('A') + 1)

if __name__ == '__main__':
    main()

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

Solution (Python):
string = input()

z_idx = len(string) - string[::-1].index('Z') - 1

a_idx = string.index('A')

print (z_idx - a_idx + 1)

Solution (Python):


a = input()
start = a.find('A')
end = len(a) - a[::-1].find('Z')

print(end - start)

Solution (Python):
s = input()
w = ""
ans = ""
f = 0
for c in s:
    if c == "A":
        f = 1
    if f == 1:
        w += c
        if c == "Z":
            ans = w
ans = len(ans)
print(ans)

Solution (Python):
s = raw_input()
aId = s.index("A")
s = s[::-1]
zId = s.index("Z")
print len(s) - aId - zId

Solution (Python):
import re

m = re.search('A.*Z', input())
print(len(m.group(0)))

Solution (Python):
s = raw_input()

counter = 0
counterA = 0
counterZ = 0

flag = False

for i in range(len(s)):
    counter += 1
    if s[i] == 'A' and not flag:
        counterA = counter
        flag = True
    if s[i] == 'Z':
        counterZ = counter
        

print counterZ-counterA+1

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

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

Solution (Python):
S=raw_input()
a=S.find('A')
b=S.rfind('Z')
print(b-a+1)

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

Solution (Python):
s=raw_input()
n=len(s)
for i in xrange(n):
    if s[i]=="A":
        idx1=i
        break    
for i in xrange(n-1,0,-1):
    if s[i]=="Z":
        idx2=i
        break
print idx2-idx1+1

Solution (Python):


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

Solution (Python):
S = input()
l = S.index("A")
r = S[::-1].index("Z")
n = len(S)
print(n-l-r)

Solution (Python):
print(len(''.join(''.join(input().partition('A')[1:]).rpartition('Z')[:2])))

Solution (Python):
s = input()

a,z = 0, len(s)-1

while s[a] != 'A':
    a += 1
while s[z] != 'Z':
    z -= 1

print(z-a+1)

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

Solution (Python):
s = input()
start = s.index("A")
fin = s.rindex("Z")
ans = s[start:fin+1]
print(len(ans))

Solution (Python):
s = raw_input()
a = s.find("A")
z = s.rfind("Z")
print z - a + 1

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

Solution (Python):
s = raw_input()

s_long = len(s)
first_a_adress = -1
end_z_adress = -1
for var in range(0,s_long):
	if s[var] == 'A':
		first_a_adress = var
		break
				
for var in reversed(range(0,s_long)):
	if s[var] == 'Z':
		end_z_adress = var
		break
print end_z_adress - first_a_adress + 1

Solution (Python):
S = input()

i = 0
j = len(S) - 1

while 1:
    if S[i] == "A":
        break
    i += 1

while 1:
    if S[j] == "Z":
        break
    j -= 1

print(j - i + 1)

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

Solution (Python):
import re
print(max((len(i) for i in re.findall(r"A.+Z", input()))))

Solution (Python):
import re
def Main():
  s = input()
  
  
  
  
  
  ans = re.findall("A[A-Z]+Z", s)
  print(len(ans[0]))

  


if __name__ == '__main__':
  Main()

Solution (Python):
import re
def Main():
  s = input()
  r = re.findall("A.+Z",s)
  
  cnt = 0
  for i in r:
    cnt = max(cnt, len(i))

  print(cnt)


if __name__ == '__main__':
  Main()

Solution (Python):
import re
s = input()
r = re.findall(r"A.+Z", s)
ans = 0
for i in r:
    ans = max(ans, len(i))

print(ans)

Solution (Python):
import re
s = input()
ans = re.search("A.*Z", s).group()
print(len(ans))

Solution (Python):
s = input()
l = 1000000
r = 0
for i, c in enumerate(s):
    if c == "A":
        l = min(l, i)
    if c == "Z":
        r = i
print(r - l + 1)

Solution (Python):
s=raw_input()
print-~s.rindex("Z")-s.index("A")

Solution (Python):



s = raw_input()

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


print b-a+1

Solution (Python):
s = input()
n = len(s)
res = 0

for i in range(0, n):
    if s[i] == "A":
        j = i
        break
for i in range(0, n):
    if s[i] == "Z":
        k = i

res = k - j + 1
print(res)

Solution (Python):
s = input()


def get_z_idx(s):
    l = len(s) - 1
    for i in range(l, -1, -1):
        if s[i] == 'Z':
            z_idx = i
            break
    return z_idx


def main(s):
    a_idx = s.index('A')
    z_idx = get_z_idx(s)
    _s = s[a_idx:z_idx + 1]
    return len(_s)


print(main(s))

Solution (Python):
"""
一番左のaの位置と一番右のzの位置だけわかればよい
"""
s = input()
a = s.index('A')
z = len(s)-s[::-1].index('Z')
print(z-a)

Solution (Python):
import re
p = input()
m = re.findall(r"A.+Z",p)        
print(len(m[0]))

Solution (Python):
s = input()

f = -1
b = -1
i = 0
n = len(s) - 1

while f == -1:
    if s[i] == 'A':
        f = i
    i = i + 1

while b == -1:
    if s[n] == 'Z':
        b = n
    n = n - 1

print(b - f + 1)

Solution (Python):
import re

s = input()
slist = re.findall("A.*Z",s)

print(len(slist[0]))

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

Solution (Python):

num = [i for i in raw_input()]
result = 0

a = len(num)
z = 0

for i in range(len(num)):
    if num[i] == "Z" and i>z:
        z = i
    elif num[i] == "A" and i<a:
        a = i
temp = z-a
if temp>0:
    print(temp+1)
else:
    print(0)

Solution (Python):
input_str=input()



b=0
e=0
length=len(input_str)
for i, s in enumerate(input_str):
	if s=="A":
		b=i
		
		break
for i, s in enumerate(input_str[::-1]):
	if s=="Z":
		e=length-i
		
		break
print(e-b)

Solution (Python):
input_line = raw_input()

idx_start = 0
while input_line[idx_start] != 'A':
    idx_start += 1

idx_end = len(input_line)
while input_line[idx_end-1] != 'Z':
    idx_end -= 1

print(idx_end - idx_start)

Solution (Python):

import re
s = input()
ans = re.findall(r"A[A-Z]+Z", s)
print(len(ans[0]))

Solution (Python):
S = []
while len(S) < 1 or len(S) > 200000:
    S = raw_input()

Slist = list(S)
i=0
a = len(Slist)
z = -1
for s in Slist:
    if s == 'A':
        if a > i:
            a = i
    if s == 'Z':
        if z < i:
            z = i
    i += 1
            
if z > a:
    print z - a + 1

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

Solution (Python):
import numpy as np

s = raw_input()
l = list(s)
A = l.index("A")
l.reverse()
Z = l.index("Z")
a = len(l)
print a - Z -A

Solution (Python):
s = input()
length = len(s)

first = s.index("A")

s_rev = s[::-1]

end_rev = s_rev.index("Z")

end = (length - 1) - end_rev

print(end-first + 1)

Solution (Python):
S = input()

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

for j in range(len(S)):
    k = len(S) - j
    s2 = S[k-1:k]
    if (s2 == 'Z'):
        break

print(k-1-i+1)

Solution (Python):
s = input()

a_i = None
z_i = None
set_a = False

for i in range(len(s)):
    if (not set_a) and s[i] == 'A':
        a_i = i
        set_a = True
    if s[i] == 'Z':
        z_i = i
print(z_i - a_i + 1)

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

Solution (Python):
s = input()

Aindex = s.find("A")
Zindex = s.rfind("Z")

MaxLength = Zindex - Aindex + 1

print(MaxLength)

Solution (Python):
import re
s=raw_input()
r=re.compile("A.*Z")
print max(map(lambda s:len(s),r.findall(s)))

Solution (Python):
s = input()

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

Solution (Python):
s = input()
s = s[::-1]

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

print(max)

Solution (Python):

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

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

Solution (Python):
s = input()

a = s.index('A')
s = s[::-1]
z = s.index('Z')

print(len(s)-a-z)

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

Solution (Python):
s = input()
acnt = 999999
zcnt = 0

for i in range(len(s)):
    if s[i] == 'A':
        acnt = min(acnt, i)
    elif s[i] == 'Z':
        zcnt = max(zcnt, i)
    else:
        next
print(zcnt - acnt + 1)

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

Solution (Python):
s = raw_input()
memo1 = []
memo2 = 0
cnt = 0
for x in s:
    if x == "A":
        memo1.append(cnt)
    elif x == "Z":
        memo2 = cnt
    cnt += 1

print memo2 - memo1[0] + 1

Solution (Python):
s = raw_input()

for (i,c) in enumerate(s):
    if c == 'A':
        ia = i
        break

for (i,c) in enumerate(s[::-1]):
    if c == 'Z':
        iz = i
        break

print len(s) - iz - ia

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

Solution (Python):
import re
s = input()
matched_list = re.findall(r'A[A-Z]*Z', s)
print(max([len(m) for m in matched_list]))

Solution (Python):
s = input()
t = list(s)
u = t[:]
t.reverse()
i, j = u.index('A'), len(s)-t.index('Z')
print(j-i)

Solution (Python):
S = list(input())
a = S.index('A')
z = len(S) - 1 - S[::-1].index('Z')
print(z - a + 1)

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

Solution (Python):
S = list(input())
a = S.index('A')
b = list(reversed(S)).index('Z')
print(len(S)-b-a)

Solution (Python):

s = raw_input()
start = 0
end = 0
for i,stri in enumerate(s):
    if stri == "A":
        start = i
        break
for i,stri in enumerate(s[::-1]):
    if stri == "Z":
        end = i
        break

print (len(s)-end)-start

Solution (Python):
s = str(input())
s = list(s)
for i in range(len(s)):
    if s[i] == 'A':
        a = i
        break

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

Solution (Python):
import sys

s = next(sys.stdin).strip()
print(s.rindex('Z') - s.index('A') + 1)

Solution (Python):
S = input()

subs = 0
l = len(S)
i = 0
while i < l:
    if S[i] != "A":
        i += 1
        continue
    else:
        for j in range(l-1, i, -1):
            if S[j] == "Z":
                subs = j - i + 1
                break
        break
print(subs)

Solution (Python):



s = input()

i = s.find("A")
j = s.rfind("Z")
a = s[i:j+1]

print(len(a))

Solution (Python):
s = input()
ind_A = 0
ind_Z = 0
for i in range(len(s)):
    if (s[i] == "A"):
        ind_A = i
        break

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

print(ind_Z - ind_A + 1)

Solution (Python):
S = input()
N = len(S)
for i in range(N):
	if S[i]=="A":
		a_n = i
		break
for i in range(N-1, -1, -1):
	if S[i]=="Z":
		z_n = i
		break
print(z_n-a_n+1)

Solution (Python):
from sys import stdin

s = stdin.readline().strip()

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

Solution (Python):
s = input()

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

print(b-a+1)

Solution (Python):


s = input()
sd = s[::-1]

print(len(s) - sd.index('Z') - s.index('A'))

Solution (Python):
from sys import stdin
ans = ''
s = stdin.readline().strip()
n = len(s)
for i in xrange(n):
 if s[i]=='A':
  break
for j in xrange(n):
 if s[n-1-j]=='Z':
  break
j = n-1-j
print j-i+1

Solution (Python):

s = input()

a = None
for i in range(len(s)):
    if a is None:
        if s[i] == 'A':
            a = i
    else:
        if s[i] == 'Z':
            z = i

print(z - a + 1)

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