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:
#文字列ｓのうちA～Zまでを取り出す
s = list(input())
sa = s.index("A")
m = [i for i, x in enumerate(s) if x == 'Z']

mz = int(m[-1])+1

p = (s[sa:mz])
print(len(p))

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

s = readChar()

a = s.index("A")
b = len(s)-+s[::-1].index("Z")

print(b-a)

Submission status: Accepted

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

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

print(y-x+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s= list(input())
Ai=[n for n, v in enumerate(s) if v=="A"]
Zi=[n for n, v in enumerate(s) if v=="Z"]

print(max(Zi)-min(Ai)+1)

Submission status: Accepted

Solution code:
s = str(input())
a = s.find("A")
z = s.rfind("Z")
print(z-a+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:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def AtoZ(s) : 
  for i in range(len(s)) : 
    if s[i] =='A' : 
      addr_a = i
      break
  for j in range(len(s)) : 
    if s[len(s) - j - 1] == 'Z' : 
      addr_z  = len(s) - j - 1
      break
      
  return addr_z - addr_a + 1

s = input()

print(AtoZ(s))

Submission status: Accepted

Solution code:
s = input()
t,e = 0,0
for i in range(len(s)):
    if s[i] =='A':
        t = i
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#AtoZString
import re
s = str(input())
S = (re.findall('A+[a-zA-z]+Z', s))
ss = S[0]
print(len(ss))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

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

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

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

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
a=s.index("A")
for i in range(n,0,-1):
  if s[i-1]=='Z':
    z=i
    break
sum=z-a
print(sum)

Submission status: Accepted

Solution code:
S = input()
flag=False
for i in range(len(S)):
  if S[i]=="A" and flag==False:
    start = i
    flag=True
    
  if S[i]=="Z" and flag:
    end = i
    
print(end-start+1)

Submission status: Accepted

Solution code:
s = input()
start = 0
stop = 0
for i in range(len(s)):
  if s[i] == 'A':
    start = i
    break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

idx_a = 200000
idx_z = 0
for i in range(len(s)):
	if s[i] == "A":
		idx_a = min(idx_a,i)
		#print(idx_a)
	if s[i] == "Z":
		idx_z = max(idx_z,i)
		#print(idx_z)

print(len(s[idx_a:idx_z])+1)

Submission status: Accepted

Solution code:
S = input()
S_reverce = S[::-1]

for n,s in enumerate(S):
    if s == 'A':
        A_num = n + 1
        break
for n,s in enumerate(S_reverce):
    if s == 'Z':
        Z_num = len(S) - n
        break
        
ans = Z_num - A_num + 1
print(ans)

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

Submission status: Accepted

Solution code:
s = input()

st = 0
ed = 0
sl = len(s)
for i in range(sl):
    if s[i] == "A":
        st = i
        break
for i in reversed(range(sl)):
    if s[i] == "Z":
        ed = i
        break
print(sl - st - (sl-ed) + 1)

Submission status: Accepted

Solution code:
S = input()
a = []
z = []
for i, s in enumerate(S):
    if s == 'A':
        a.append(i + 1)
    elif s == 'Z':
        z.append(i + 1)

print(max(z) - min(a) + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = 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()
start=0
end=len(S)+1
for s in S:
    start+=1
    if s=="A":
        break
for s in S[::-1]:
    end-=1
    if s=="Z":
        break
print(end-start+1)

Submission status: Accepted

Solution code:
#B
s = input()
A = s.index("A")
Z = s[::-1].index("Z")
print(max(0,len(s)-1-Z-A+1))

Submission status: Accepted

Solution code:
import re
s = input()
r = re.compile(r"A[A-Z]*Z")
t = re.findall(r,s)
u = map(len, t)
print(max(u))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = input()

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

Submission status: Accepted

Solution code:
s = input()

for i in range(len(s)):
    if s[i] == "A":
        start = i
        break
for j in range(len(s)):
    if s[j] == "Z":
        last = j

print(len(s[start:last+1]))

Submission status: Accepted

Solution code:
s = input()
Aid = 0
Zid = 0

for i in range(len(s)):
  if s[i] == "Z":
    Zid = i
for i in range(len(s)):
  if s[len(s)-i-1] == "A":
    Aid = len(s)-i-1

print(Zid - Aid +1)

Submission status: Accepted

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

for i in range(N):
    if s[i] == 'A':
        lt = i
        break

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

print(rt - lt + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
s = input()
m = -1
for i in range(len(s)):
    if s[i] == 'A' and m == -1:
        m = i
    elif s[i] == 'Z' and m != -1:
        n = i - m + 1
print(n)

Submission status: Accepted

Solution code:
s = input()

start = -1
end = -1
for index,i in enumerate(s):
  if i == "A":
    start = index
    break
for index,i in enumerate(list(reversed(s))):
  if i == "Z":
    end = len(s) - index
    break
if end == -1 or start == -1:
  print(1)
else:
  print(end -start)

Submission status: Accepted

Solution code:
s = list(input())
start = s.index('A')
s.reverse()
end = len(s) - s.index('Z')

print(end - start)

Submission status: Accepted

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

l = 0
r = 0

for i in range(n):
    if s[i] == 'A':
        l = i
        break

for i in reversed(range(n)):
    if s[i] == 'Z':
        r = i
        break

ans = len(s[l:r + 1])
print(ans)

Submission status: Accepted

Solution code:
import re


print(len(re.search(r"A.*Z", input()).group()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
N = len(s)
for i in range(N):
  if s[i] == 'A':
    left = i
    break
    
for i in range(N):
  if s[N-1-i] == 'Z':
    right = N-1-i
    break
    
print(right - left + 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()
N = len(s)
for i in range(N):
  if s[i] == 'A':
    left = i
    break
    
for i in range(N):
  if s[N-1-i] == 'Z':
    right = N-1-i
    break
    
print(right - left + 1)

Submission status: Accepted

Solution code:
S = input()
k = 0
st = 2000000
gl = 0
for i in range(len(S)):
  if S[i] == "A":
    if st > k:
      st = k
  k += 1
  if S[i] == "Z":
    if gl < k:
      gl = k
print(gl - st)

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
 
ai = S.find("A")
zi = S.rfind("Z")
 
print(zi-ai+1)

Submission status: Accepted

Solution code:
S = input()
A = sorted([i for i, x in enumerate(S) if x == 'A'])
Z = sorted([i for i, x in enumerate(S) if x == 'Z'])
print(Z[-1] - A[0] + 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)
 
# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
 
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
 
 
# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
 
 
# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d
 
# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr
 
# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)
 
# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)
 
# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)
 
# 素数判定
 
 
 
# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
 
    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P
 
# 同じものを含む順列
def permutation_with_duplicates(L):
 
    if L == []:
        return [[]]
 
    else:
        ret = []
 
        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))
 
        for i in S:
 
            data = L[:]
            data.remove(i)
 
            for j in permutation_with_duplicates(data):
                ret.append([i] + j)
 
        return ret
 
 
s= input()
f=s.index("A")
l=len(s)-1-s[::-1].index("Z")
print(l-f+1)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
a = 0
f = 0
z = 0

for i in range(l):
    if s[i] == "A":
        if f == 0:
            a = i
            f = 1
        else:
            pass
    elif s[i] == "Z":
        z = i
    else:
        pass

print(z-a+1)

Submission status: Accepted

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()
    A, Z = MAX, 0

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
r_s = s[::-1]

if r_s.index("Z")==0:
    print(len(s[s.index("A"):]))
else:
    print(len(s[s.index("A"):-r_s.index("Z")]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

for i, c in enumerate(s[::-1]):
    if c == 'Z':
        z_index = i
        break
print(len(s[a_index:len(s)-z_index]))

Submission status: Accepted

Solution code:
s = input()
i = 0
j = len(s) - 1
t1 = []
t2 = []

while True:
  #print(i,j)
  if(s[i] == "A"):
    t1.append(i)
    #print(t1)
  if(s[j] == "Z"):
    t2.append(j)
  if(len(t1) != 0 and len(t2) != 0):
    break
  i += 1
  j -= 1
  
print(t2[0]-t1[0] +1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = 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()
 
for i in range(len(s)):
    if s[i] == 'A':
        a = i
        break
for i in range(-1,-len(s),-1):
    if s[i] == 'Z':
        b = len(s) + i
        break
 
print(b-a+1)

Submission status: Accepted

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

#print(s.rfind('Z'))  #2
#print(s.find('A'))  #0
print(t)

Submission status: Accepted

Solution code:
from sys import stdin
def S(): return stdin.readline().rstrip()

s = S()

h = 0
while s[h] != 'A':
    h += 1

e = len(s)-1
while s[e] != 'Z':
    e -= 1

print(e-h+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(z-a+1)

Submission status: Accepted

Solution code:
s = input()

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

print(b-a+1)

Submission status: Accepted

Solution code:
s = input()
start = 1000000
end = 0

for i in range(len(s)):
    #print(s[i])
    if s[i] == 'A' and start > i:
        start = i
        #print(start)
    elif s[i] == 'Z' and end < i:
        end = i

print(end - start + 1)

Submission status: Accepted

Solution code:
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    s = input()
    s = list(s)
    init = -1
    end = len(s)
    for i in range(len(s)):
        if s[i]=='A' and init==-1:
            init = i
        if s[i]=='Z':
            end = i
    print(end-init+1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re

s = input()
x = ""
for i,k in enumerate(s):
    if k == "A":
        x = s[i:][::-1]
        for j,t in enumerate(x):
            if t == "Z":
                x = x[j:]
                break
        break
                
print(len(x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

a = len(s) + 1
z = -1

for i in range(len(s)):
    if s[i] == "A":
        a = min(a, i)
    if s[i] == "Z":
        z = max(z, i)

print(len(s[a:z+1]))

Submission status: Accepted

Solution code:
s = input()
t = s[::-1]

print(len(s)-s.find("A")-t.find("Z"))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    s = input()
    n = len(s)
    start, end = 0, 0
    for i, char in enumerate(s):
        if char == 'A':
            start = i
            break
    for i in range(n-1, -1, -1):
        if s[i] == 'Z':
            end = i
            break
    print(end - start + 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

start = -1
end = -1
for i, s in enumerate(S):
    if s == "A" and start == -1:
        start = i
    if s == "Z" and start != -1:
        end = i

if start != -1 and end != -1:
    print(end - start + 1)

Submission status: Accepted

Solution code:
S = str(input())

def Main(S):
    ans = 0
    candidate = 0
    flag = False
    for c in S:
        if c == 'A':
            flag = True
        if flag:
            candidate += 1
            if c == 'Z':
                ans = candidate
    return ans
            
    
res = Main(S)
print(res)

Submission status: Accepted

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