import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		if(str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1){
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		}
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		if(str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1){
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		}
	}
} Main public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		if(str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1){
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		if(str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1){
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String str = scanner.nextLine(); str scanner.nextLine() scanner.nextLine scanner if(str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1){
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		} str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1 str.indexOf("A") != -1 str.indexOf("A") str.indexOf str "A" -1 1 str.lastIndexOf("Z") != -1 str.lastIndexOf("Z") str.lastIndexOf str "Z" -1 1 {
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		} System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length()) System.out.println System.out System System.out (str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length() (str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length (str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)) str.substring str (str.indexOf("A")) str.indexOf str "A" str.lastIndexOf("Z")+1 str.lastIndexOf("Z") str.lastIndexOf str "Z" 1 String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		if(str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1){
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		}
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		if(str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1){
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		}
	}
} Main
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		if(str.indexOf("A") != -1 && str.lastIndexOf("Z") != -1){
			System.out.println((str.substring((str.indexOf("A")),str.lastIndexOf("Z")+1)).length());
		}
	}
}