
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int i=0;
		while(s.charAt(i)!='A')
		{
			i++;
		}
		int j=s.length()-1;
		while(s.charAt(j)!='Z')
		{
			j--;
		}
		System.out.println(s.substring(i,j+1).length());
	}

} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int i=0;
		while(s.charAt(i)!='A')
		{
			i++;
		}
		int j=s.length()-1;
		while(s.charAt(j)!='Z')
		{
			j--;
		}
		System.out.println(s.substring(i,j+1).length());
	}

} Main public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int i=0;
		while(s.charAt(i)!='A')
		{
			i++;
		}
		int j=s.length()-1;
		while(s.charAt(j)!='Z')
		{
			j--;
		}
		System.out.println(s.substring(i,j+1).length());
	} main {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int i=0;
		while(s.charAt(i)!='A')
		{
			i++;
		}
		int j=s.length()-1;
		while(s.charAt(j)!='Z')
		{
			j--;
		}
		System.out.println(s.substring(i,j+1).length());
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) String s=sc.nextLine(); s sc.nextLine() sc.nextLine sc int i=0; i 0 while(s.charAt(i)!='A')
		{
			i++;
		} s.charAt(i)!='A' s.charAt(i) s.charAt s i 'A' {
			i++;
		} i++ i int j=s.length()-1; j s.length()-1 s.length() s.length s 1 while(s.charAt(j)!='Z')
		{
			j--;
		} s.charAt(j)!='Z' s.charAt(j) s.charAt s j 'Z' {
			j--;
		} j-- j System.out.println(s.substring(i,j+1).length()) System.out.println System.out System System.out s.substring(i,j+1).length() s.substring(i,j+1).length s.substring(i,j+1) s.substring s i j+1 j 1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int i=0;
		while(s.charAt(i)!='A')
		{
			i++;
		}
		int j=s.length()-1;
		while(s.charAt(j)!='Z')
		{
			j--;
		}
		System.out.println(s.substring(i,j+1).length());
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int i=0;
		while(s.charAt(i)!='A')
		{
			i++;
		}
		int j=s.length()-1;
		while(s.charAt(j)!='Z')
		{
			j--;
		}
		System.out.println(s.substring(i,j+1).length());
	}

} Main

import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int i=0;
		while(s.charAt(i)!='A')
		{
			i++;
		}
		int j=s.length()-1;
		while(s.charAt(j)!='Z')
		{
			j--;
		}
		System.out.println(s.substring(i,j+1).length());
	}

}
