import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	int a = 0;
      	int z = s.length()-1;
      	while (a<z){
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        }
        System.out.println(z - a + 1);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	int a = 0;
      	int z = s.length()-1;
      	while (a<z){
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        }
        System.out.println(z - a + 1);
	}
} Main public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	int a = 0;
      	int z = s.length()-1;
      	while (a<z){
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        }
        System.out.println(z - a + 1);
	} main {
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	int a = 0;
      	int z = s.length()-1;
      	while (a<z){
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        }
        System.out.println(z - a + 1);
	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) String s = scn.next(); s scn.next() scn.next scn int a = 0; a 0 int z = s.length()-1; z s.length()-1 s.length() s.length s 1 while (a<z){
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        } a<z a z {
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        } if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            } s.charAt(a)=='A' && s.charAt(z)=='Z' s.charAt(a)=='A' s.charAt(a) s.charAt s a 'A' s.charAt(z)=='Z' s.charAt(z) s.charAt s z 'Z' {
                break;
            } break; if(s.charAt(a) != 'A') a++; s.charAt(a) != 'A' s.charAt(a) s.charAt s a 'A' a++ a if(s.charAt(z) != 'Z') z--; s.charAt(z) != 'Z' s.charAt(z) s.charAt s z 'Z' z-- z System.out.println(z - a + 1) System.out.println System.out System System.out z - a + 1 z - a z a 1 String[] args args public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	int a = 0;
      	int z = s.length()-1;
      	while (a<z){
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        }
        System.out.println(z - a + 1);
	}
} public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	int a = 0;
      	int z = s.length()-1;
      	while (a<z){
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        }
        System.out.println(z - a + 1);
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	int a = 0;
      	int z = s.length()-1;
      	while (a<z){
            if(s.charAt(a)=='A' && s.charAt(z)=='Z'){
                break;
            }
            if(s.charAt(a) != 'A') a++;
            if(s.charAt(z) != 'Z') z--;
        }
        System.out.println(z - a + 1);
	}
}