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

-----Sample Output-----
5

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

Difficulty: EASY

Solutions:
s = list(input())
s_inv = list(reversed(s))
a = s.index('A')
z = s_inv.index('Z')
print(len(s) - a - z)


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


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


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

def __starting_point():
	inputs = read()
	print(solve(*inputs))
__starting_point()


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


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


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


n = input()
a = n.find('A')
z = n.rfind('Z')
print(z - a + 1)


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)


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


s = input()
a = s.index('A')
z = s.rindex('Z')
print(z - a + 1)


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


s = input()
a = len(s)
z = 0
for (i, e) in enumerate(reversed(s)):
	if e == 'A':
		a = len(s) - i - 1
for (i, e) in enumerate(s):
	if e == 'Z':
		z = i
print(z - a + 1)


s = list(input())
s_inv = list(reversed(s))
a = s.index('A')
b = s_inv.index('Z')
print(len(s) - a - b)


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


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


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


S = input()
N = len(S)
a = 1
z = 1
for i in range(N):
	if S[i] == 'A':
		break
	else:
		a += 1
for j in range(1, N + 1):
	if S[-j] == 'Z':
		break
	else:
		z += 1
ans = N - a - z + 2
print(ans)


S = input()
ans = -S[::-1].find('Z') - S.find('A') + len(S)
print(ans)


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


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


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


m = input()
A = m.index('A')
Z = m.rfind('Z')
print(Z - A + 1)


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)


import re
r = re.search('A.*Z', input())
print(len(r.group()))


ss = input()
print(ss.rindex('Z') - ss.index('A') + 1)


s = input()
st = s.index('A')
en = s.rindex('Z')
print(en - st + 1)


import re
a = input()
m = a.find('A')
n = a.rfind('Z')
print(n - m + 1)


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


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


s = input()
print(len(s.split('A', 1)[1].rsplit('Z', 1)[0]) + 2)


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


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


def resolve():
	s = input()
	start_index = s.index('A')
	end_index = s.rindex('Z')
	output = end_index - start_index + 1
	print(output)
resolve()


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


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


import re
s = input()
print(len(re.findall('A.*Z', s)[0]))


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


S = input()
A = S.index('A')
Z = S[::-1].index('Z')
print(len(S) - (A + Z))


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


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)


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


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


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


S = input()
A1 = S.find('A')
A2 = S.rfind('Z')
print(A2 - A1 + 1)


import sys

def solve(s: str):
	return s.rfind('Z') - s.find('A') + 1

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	s = next(tokens)
	print(solve(s))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


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


s = input()
ind_A = 0
while s[ind_A] != 'A':
	ind_A += 1
ind_Z = len(s)
while s[ind_Z - 1] != 'Z':
	ind_Z -= 1
print(ind_Z - ind_A)


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


s = input()
a = s.index('A')
b = s.rfind('Z')
print(len(s[a:b + 1]))


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


s = input()
st = s.index('A')
end = s.rfind('Z')
print(end - st + 1)


S = input()
s_list = []
for n in S:
	s_list.append(n)
a = s_list.index('A') + 1
s_list.reverse()
z = -(s_list.index('Z') + 1)
print(len(S[a:z]) + 2)


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) - 1, -1, -1):
	if s[i] == 'Z':
		end = i
		break
print(end - begin + 1)


s = input()
print(len(range(s.find('A'), s.rfind('Z') + 1)))


s = list(input())
t = s.copy()
t.reverse()
print(len(s) - t.index('Z') - s.index('A'))


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


l = input()
a = l.index('A')
z = l[::-1].index('Z')
print(len(l) - z - a)


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


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)


n = input()
nn = n[::-1]
print(len(n) - nn.index('Z') - n.index('A'))


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


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


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


A = input()
n = A.index('A')
m = A[::-1].index('Z')
print(len(A) - n - m)


s = input()
front = s.index('A')
end = s.rindex('Z')
print(end - front + 1)


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


S = input()
print(S.rindex('Z') - S.index('A') + 1)


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


def main():
	s = input()
	start = 200000
	end = 0
	for i in range(len(s)):
		if s[i] == 'A' and start > i:
			start = i
		elif s[i] == 'Z' and end < i:
			end = i
	print(end - start + 1)

def __starting_point():
	main()
__starting_point()


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


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


import re
S = str(input())
print(S.rfind('Z') - S.find('A') + 1)


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


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


a = input()
b = a.find('A') + 1
c = a.rfind('Z') + 1
print(c - b + 1)


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


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


import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda : sys.stdin.readline().rstrip()
rs = lambda : sys.stdin.readline().split()
ri = lambda : int(sys.stdin.readline())
rm = lambda : list(map(int, sys.stdin.readline().split()))
rl = lambda : list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10 ** 9 + 7
s = rr()
left = s.index('A')
right = s.rindex('Z')
print(right - left + 1)


s = input()
l = s.index('A')
r = s.rindex('Z')
print(r - l + 1)


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)


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)


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


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)


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


S = input()
a = S.index('A')
z = S.rfind('Z')
print(z - a + 1)


N = input()
a = N.find('A')
z = N.rfind('Z')
print(z - a + 1)


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


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)


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)


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


import sys
(min_a_index, max_z_index) = (sys.maxsize, 0)
for (index, c) in enumerate(list(input())):
	if c == 'A' and index < min_a_index:
		min_a_index = index
	if c == 'Z' and index > max_z_index:
		max_z_index = index
print(max_z_index - min_a_index + 1)


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)


s = str(input())
for i in range(len(s)):
	if s[i] == 'A':
		a = i
		break
t = s[::-1]
for j in range(len(s)):
	if t[j] == 'Z':
		b = j
		break
print(len(s) - a - b)


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


s = input()
i = s.index('A')
j = s.rindex('Z')
print(j - i + 1)


S = input()
FA = S.find('A')
LZ = S.rfind('Z')
print(LZ - FA + 1)


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


s = input()
first_index = s.index('A', 0)
last_index = 0
for (i, ss) in enumerate(s):
	if ss == 'Z':
		last_index = i
print(last_index - first_index + 1)


import re
print(max(map(len, re.findall('A.*Z', input()))))


s = list(input())
while s[0] != 'A' or s[-1] != 'Z':
	if s[0] == 'A':
		s.pop()
	elif s[-1] == 'Z':
		s.pop(0)
	else:
		s.pop(0)
		s.pop()
print(len(s))


s = input()
first = s.index('A')
end = s.rindex('Z')
ans = end - first + 1
print(ans)


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


import re
s = input()
print(len(max(re.findall('A.*Z', s))))


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


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


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)


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


s = input()
first_index = s.index('A', 0)
last_index = 0
for i in range(1, len(s)):
	if s[-i] == 'Z':
		last_index = len(s) - i
		break
print(last_index - first_index + 1)


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


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


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


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)


def main():
	s = input()
	a = len(s)
	z = 0
	for (i, t) in enumerate(s):
		if t == 'A':
			a = min(a, i)
		if t == 'Z':
			z = max(z, i)
	ans = z - a + 1
	print(ans)

def __starting_point():
	main()
__starting_point()


S = input()
left = -1
for (i, s) in enumerate(S):
	if s == 'A':
		left = i
		break
right = len(S) + 1
for i in range(len(S) - 1, -1, -1):
	if S[i] == 'Z':
		right = i
		break
if left < right:
	print(right - left + 1)


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


s = input()
n = len(s)
(first, last) = (0, 0)
for i in range(n):
	(b, f) = (i + 1, n - i)
	if s[-1 - i] == 'A':
		first = f
	if s[i] == 'Z':
		last = b
print(last - first + 1)


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)


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)


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


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


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


S = input()
n = S.find('A')
m = S.rfind('Z')
print(m - n + 1)


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


from math import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
s = input()
A_idx = s.index('A')
Z_idx = s[::-1].index('Z')
ln = len(s)
print(ln - Z_idx - A_idx)


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


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


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

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

def __starting_point():
	main()
__starting_point()


import sys

def solve(s: str):
	A = min((i for (i, c) in enumerate(s) if c == 'A'), default=len(s))
	Z = max((i for (i, c) in enumerate(s) if c == 'Z'), default=0)
	return max(0, Z - A + 1)

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	s = next(tokens)
	print(solve(s))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10 ** 9)

def si():
	return input()

def ii():
	return int(input())

def fi():
	return float(input())

def lstr():
	return input().split()

def lint():
	return list(map(int, input().split()))

def lint_dec():
	return list(map(lambda x: int(x) - 1, input().split()))

def lnstr(n):
	return [input() for _ in range(n)]

def lnint(n):
	return [int(input()) for _ in range(n)]

def lint_list(n):
	return [lint() for _ in range(n)]
t = si()
n = len(t)
for s in range(n):
	if t[s] == 'A':
		break
for e in range(n - 1, -1, -1):
	if t[e] == 'Z':
		break
print(e - s + 1)


s = input()
sta = []
fin = []
for i in range(len(s)):
	if s[i] == 'A':
		sta.append(i)
	elif s[i] == 'Z':
		fin.append(i)
print(max(fin) - min(sta) + 1)


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


data = list(input())
i = 0
j = 1
while data[i] != 'A':
	i = i + 1
while data[-j] != 'Z' and len(data) - j > i:
	j = j + 1
print(len(data) - i - j + 1)


[print(s.rfind('Z') - s.find('A') + 1) for s in [input()]]


print(len(max(__import__('re').findall('A.*Z', input()))))


import re
s = input()
a = re.findall('A.*Z', s)
print(len(*a))


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


s = input()
a = s.index('A')
z = s.rfind('Z')
print(z - a + 1)


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


s = input()
n = len(s)
t = []
for i in range(n):
	t.append(s[n - 1 - i])
a = s.index('A')
z = t.index('Z')
print(n - z - a)


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)


import math
b = input()
c = []
for i in b:
	c.append(i)
a1 = c[c.index('A'):]
a2 = [i for (i, x) in enumerate(a1) if x == 'Z']
print(len(a1[:a2[-1] + 1]))


import sys
input = sys.stdin.readline

def main():
	S = input()
	search_string = ['A', 'Z']
	position = []
	for (i, s) in enumerate(S):
		if s == search_string[0]:
			position.append(i)
			break
	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])

def __starting_point():
	main()
__starting_point()