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: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
x = I()
if x < 1200:
    print("ABC")
else:
    print("ARC")
"""
#B
s = input()
n = len(s)
for i in range(n):
    if s[i] == "A":
        for j in range(i+1,n):
            s[j] == "Z":
                print(j-i+1)
                quit()
#C
"""
x = I()
ans = 2*(x//11)+1
x %= 11
if x == 0:
    ans -= 1
if x > 6:
    ans += 1
print(ans)
"""

#D
"""
n = I()
a = LI()
d = defaultdict(int)
for i in a:
    d[i] += 1
l = list(d.values())
k = len(l)+sum(l)
for i in d.keys():
    d[i] = 1
ans = sum(list(d.values()))
ans -= 1 if k%2 else 0
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
x = I()
if x < 1200:
    print("ABC")
else:
    print("ARC")
"""
#B
s = S()
n = len(s)
for i in range(n):
    if s[i] == "A":
        for j in range(i+1,n):
            s[j] == "Z":
                print(j-i+1)
                quit()
#C
"""
x = I()
ans = 2*(x//11)+1
x %= 11
if x == 0:
    ans -= 1
if x > 6:
    ans += 1
print(ans)
"""

#D
"""
n = I()
a = LI()
d = defaultdict(int)
for i in a:
    d[i] += 1
l = list(d.values())
k = len(l)+sum(l)
for i in d.keys():
    d[i] = 1
ans = sum(list(d.values()))
ans -= 1 if k%2 else 0
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Runtime Error

Solution code:
s = input()
a = z =  ''
for i, v in enumerate(s):
    if not a:
        if v == 'A':
            a = i
    if not z:
        if s[len(s) - i -1] == 'Z':
            z = len(s) - i
            
    if a >= 0 and z >= 0:
        print(z - a)
        exit()

Submission status: Runtime Error

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

x = input()

a = 0
z = 0

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

for i in range(len(x)):
    if x[-(i+1)] == "Z":
        z = len(x) - i
        break

print(len(x[a:z])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S=input()

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

Submission status: Runtime Error

Solution code:
S = input()
a = min[i for i, x in enumerate(S) if x == 'A']
z = max[i for i, x in enumerate(S) if x == 'Z']
print(z - a)

Submission status: Runtime Error

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: Runtime Error

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,-1,-1):
    if S[i] == 'Z':
        z_index = i
        break

print(N - z_index - a_index)

Submission status: Runtime Error

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

print(N - z_index - a_index)

Submission status: Runtime Error

Solution code:
import re
m = re.match(r'A.*Z', input())
print(m.end() - m.start())

Submission status: Runtime Error

Solution code:
import re
m = re.match(r'A.*Z', input())
print(m.end - m.start)

Submission status: Runtime Error

Solution code:
a = list(input())

for i in range(len(a)):
  if a[i] == "A":
    k = i
for i in range(len(a),0,-1):
  if a[i] == "Z":
    kk = i
print(kk-k+1)

Submission status: Runtime Error

Solution code:
s=input()
a=0
z=0
i=0
j=len(s)-1
while a==0:
    if s[i]=="a":
        a=1
    else:
        i+=1
while z==0:
    if s[j]=="z":
        z=1
    else:
        j-=1
print(j-i+1)

Submission status: Runtime Error

Solution code:
s=input()
a=0
z=0
i=0
j=0
while a==0:
    if s[i]=="a":
        a=1
    else:
        i+=1
while z==0:
    if s[len(s)-1-j]=="z":
        z=1
    else:
        j+=1
print(j-i+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A=input()
print(A.index("z")-A.index("a"))

Submission status: Runtime Error

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: Runtime Error

Solution code:
s = input()
a = s.index('a')
sr = s[::-1]
z = sr.index('z')
print(len(s) - a - z)

Submission status: Runtime Error

Solution code:
s = input()
a = s.index('a')
sr = s[::-1]
z = sr.index('z')
print(s[a:-z])

Submission status: Runtime Error

Solution code:
s =map(str,(raw_input()))
flg = 0
for i in range(len(s)):
  if flg==0 and s[i]=='A':
    flg += 1
  elif flg!=0 and s[i]=='Z':
    flg+=1
    if s[i+1] == 'Z':
      flg+=1
    break
  elif flg!=0:
    flg+=1
print flg

Submission status: Runtime Error

Solution code:
s = input().strip()

a = []
b = []

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

Submission status: Runtime Error

Solution code:
s = input().strip()

a = 0
b = 0

for i in s:
    if s[i] == 'A':
        a = i
    elif s[i] == 'Z':
        b = i
print(b-a+1)

Submission status: Runtime Error

Solution code:
a = input()
b = a[a.index('A'):a.rindex('z')+1]

Submission status: Runtime Error

Solution code:
def abc053_b():
    s = str(input())

    start = int(s.index('a'))
    
    for i in range(len(s), 0, -1):
        if s[i] == "z":
            return i - start


if __name__ == '__main__':
    print(abc053_b())

Submission status: Runtime Error

Solution code:
A=str(input())
a=A.index("A")
Z=[]
for i in enumerate(A):
    if i[1]=="Z":
        Z.append(i[0])
if len(Z)>=2:
    b=max(Z)
else:
    b=A.index("B")
print(len(A[a:b+1]))

Submission status: Runtime Error

Solution code:
s = input()

ans = []
flag = 0

#print(s)
#print(s[0])

for i in range(len(s)):
    if flag == 0:
        if s[i] == "A":
            flag = 1
            ans.append(s[i])

    else:
        if s[i] == "Z":
            if s[i+1] != "Z":
                flag = 0
                ans.append(s[i])
                break
            
            else:
                ans.append(s[i])

        else:
            ans.append(s[i])
        

#print(ans)

#print("".join(ans))

print(len(ans))

Submission status: Runtime Error

Solution code:
s = input()

ans = []
flag = 0

#print(s)
#print(s[0])

for i in range(len(s)):
    if flag == 0:
        if s[i] == "A":
            flag = 1
            ans.append(s[i])

    else:
        if s[i] == "Z":
            if i > len(s) - 1 or s[i+1] != "Z":
                flag = 0
                ans.append(s[i])
                break
            
            else:
                ans.append(s[i])

        else:
            ans.append(s[i])
        

#print(ans)

#print("".join(ans))

print(len(ans))

Submission status: Runtime Error

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: Runtime Error

Solution code:
s = input()

ans = 0

i = 0
while i < len(s):
    if s[i] == "A":
        num = 1
        while s[i] != "Z" and i < len(s):
            i += 1
            num += 1
        ans = max(ans, num)
    i += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = input()
lis = []
for i in range(len(a)):
    if a[i] == "A":
        while True:
            if a[i] == "Z" and a[i+1] != "Z":
                print(len(lis)+1)
                exit()
            else:
                lis.append(a[i])
                i += 1

Submission status: Runtime Error

Solution code:
a = input()
lis = []
for i in range(len(a)):
    if a[i] == "A":
        while True:
            if a[i] == "Z":
                print(len(lis)+1)
                break
            else:
                lis.append(a[i])
                i += 1

Submission status: Runtime Error

Solution code:
s = input()

start = s.index("A")

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
s = list(input())
for i in range(len(s)):
   if s[i] == "A":
      i_tmp1= i
   elif s[i] == "Z" and i >= i_tmp1:
      i_tmp2  = i

print(i_tmp2-i_tmp1+1)

Submission status: Runtime Error

Solution code:


s = input()

def drop(s):
    if s[0] != 'A':
        return drop(s[1:])
    if s[-1] != 'Z':
        return drop(s[:-1])
    return s

print(len(drop(s)))

Submission status: Runtime Error

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

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

s = input()
print(1)

Submission status: Runtime Error

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

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

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

Submission status: Runtime Error

Solution code:


     -*- coding: utf-8 -*-
     
    import sys
    import subprocess
    import json
    import time
    import math
    import re
    import sqlite3
     
    s = input()
    print(s.rfind("Z") - s.find("A") + 1)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
 -*- coding: utf-8 -*-
 
import sys
import subprocess
import json
import time
import math
import re
import sqlite3
 
s = input()
print(s.rfind('Z') - s.find('A') + 1)

Submission status: Runtime Error

Solution code:
x = int(raw_input())
print 2*(x//11) + (2 if x%11>6 else 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = raw_input()
aId = s.index("a")
s = s[::-1]
zId = s.index("z")
print len(s) - aId - zId

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
	input_str=input()
	# input_str="QWERTYASDFZXCV"
	# input_str="ZABCZ"
	# input_str="HASFJGHOGAKZZFEGA"
	b=0
	e=0
	length=len(input_str)
	for i, s in enumerate(input_str):
		if s=="A":
			b=i
			# print(b)
			break
	for i, s in enumerate(input_str[::-1]):
		if s=="Z":
			e=length-i
			# print(e)
			break
	print(e-b)

Submission status: Runtime Error

Solution code:
s = int(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: Runtime Error

Solution code:
s = raw_input()
memo1 = 0
memo2 = 0
cnt = 0
for x in s:
    if x = "A":
        memo1 = cnt
    elif x = "Z":
        memo2 = cnt
    cnt += 1

print memo2 - memo1 + 1