import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
	//	int res = 0;
	//	boolean get = false;
	//	boolean getZ = false;
		int s = 0;
		int f = 0;
		for(int i = 0 ; i<input.length(); i++){
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		}
		for(int i = input.length()-1; i>=0; i--){
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		}
	//	System.out.println(f + " " + s);
		int res = f-s+1;
		if(res<=0)res = 0;
		System.out.println(res);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
	//	int res = 0;
	//	boolean get = false;
	//	boolean getZ = false;
		int s = 0;
		int f = 0;
		for(int i = 0 ; i<input.length(); i++){
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		}
		for(int i = input.length()-1; i>=0; i--){
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		}
	//	System.out.println(f + " " + s);
		int res = f-s+1;
		if(res<=0)res = 0;
		System.out.println(res);
	}
} Main public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
	//	int res = 0;
	//	boolean get = false;
	//	boolean getZ = false;
		int s = 0;
		int f = 0;
		for(int i = 0 ; i<input.length(); i++){
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		}
		for(int i = input.length()-1; i>=0; i--){
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		}
	//	System.out.println(f + " " + s);
		int res = f-s+1;
		if(res<=0)res = 0;
		System.out.println(res);
	} main {
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
	//	int res = 0;
	//	boolean get = false;
	//	boolean getZ = false;
		int s = 0;
		int f = 0;
		for(int i = 0 ; i<input.length(); i++){
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		}
		for(int i = input.length()-1; i>=0; i--){
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		}
	//	System.out.println(f + " " + s);
		int res = f-s+1;
		if(res<=0)res = 0;
		System.out.println(res);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String input = sc.nextLine(); input sc.nextLine() sc.nextLine sc int s = 0; s 0 int f = 0; f 0 for(int i = 0 ; i<input.length(); i++){
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		} int i = 0 ; int i = 0 ; i 0 i<input.length() i input.length() input.length input i++ i++ i {
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		} {
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		} if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			} input.charAt(i) == 'A' input.charAt(i) input.charAt input i 'A' {
				s = i+1;
				break;
			} s = i+1 s i+1 i 1 break; for(int i = input.length()-1; i>=0; i--){
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		} int i = input.length()-1; int i = input.length()-1; i input.length()-1 input.length() input.length input 1 i>=0 i 0 i-- i-- i {
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		} {
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		} if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			} input.charAt(i) == 'Z' input.charAt(i) input.charAt input i 'Z' {
				f = i+1;
				break;
			} f = i+1 f i+1 i 1 break; int res = f-s+1; res f-s+1 f-s f s 1 if(res<=0)res = 0; res<=0 res 0 res = 0 res 0 System.out.println(res) System.out.println System.out System System.out res String args[] args public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
	//	int res = 0;
	//	boolean get = false;
	//	boolean getZ = false;
		int s = 0;
		int f = 0;
		for(int i = 0 ; i<input.length(); i++){
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		}
		for(int i = input.length()-1; i>=0; i--){
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		}
	//	System.out.println(f + " " + s);
		int res = f-s+1;
		if(res<=0)res = 0;
		System.out.println(res);
	}
} public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
	//	int res = 0;
	//	boolean get = false;
	//	boolean getZ = false;
		int s = 0;
		int f = 0;
		for(int i = 0 ; i<input.length(); i++){
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		}
		for(int i = input.length()-1; i>=0; i--){
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		}
	//	System.out.println(f + " " + s);
		int res = f-s+1;
		if(res<=0)res = 0;
		System.out.println(res);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
	//	int res = 0;
	//	boolean get = false;
	//	boolean getZ = false;
		int s = 0;
		int f = 0;
		for(int i = 0 ; i<input.length(); i++){
			if(input.charAt(i) == 'A'){
				s = i+1;
				break;
			}
		}
		for(int i = input.length()-1; i>=0; i--){
			if(input.charAt(i) == 'Z'){
				f = i+1;
				break;
			}
		}
	//	System.out.println(f + " " + s);
		int res = f-s+1;
		if(res<=0)res = 0;
		System.out.println(res);
	}
}
