import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length(), i=0, j=0;
		for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break;
		for (j=0; j<len; j++) if (s.charAt(j)=='A') break;
		System.out.println(j>i ? 0 : (i-j)+1);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

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

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length(), i=0, j=0;
		for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break;
		for (j=0; j<len; j++) if (s.charAt(j)=='A') break;
		System.out.println(j>i ? 0 : (i-j)+1);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

} Main static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length(), i=0, j=0;
		for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break;
		for (j=0; j<len; j++) if (s.charAt(j)=='A') break;
		System.out.println(j>i ? 0 : (i-j)+1);
		sc.close();			
	} solve {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length(), i=0, j=0;
		for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break;
		for (j=0; j<len; j++) if (s.charAt(j)=='A') break;
		System.out.println(j>i ? 0 : (i-j)+1);
		sc.close();			
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String s = sc.next(); s sc.next() sc.next sc int len = s.length() len s.length() s.length s i=0 i 0 j=0; j 0 for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break; i=len-1; i=len-1 i len-1 len 1 i>=0 i 0 i-- i-- i if (s.charAt(i)=='Z') break; if (s.charAt(i)=='Z') break; s.charAt(i)=='Z' s.charAt(i) s.charAt s i 'Z' break; for (j=0; j<len; j++) if (s.charAt(j)=='A') break; j=0; j=0 j 0 j<len j len j++ j++ j if (s.charAt(j)=='A') break; if (s.charAt(j)=='A') break; s.charAt(j)=='A' s.charAt(j) s.charAt s j 'A' break; System.out.println(j>i ? 0 : (i-j)+1) System.out.println System.out System System.out j>i ? 0 : (i-j)+1 j>i j i 0 (i-j)+1 (i-j) i j 1 sc.close() sc.close sc public static void main(String args[]) {
		solve();
	} main {
		solve();
	} solve() solve String args[] args public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length(), i=0, j=0;
		for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break;
		for (j=0; j<len; j++) if (s.charAt(j)=='A') break;
		System.out.println(j>i ? 0 : (i-j)+1);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

} public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length(), i=0, j=0;
		for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break;
		for (j=0; j<len; j++) if (s.charAt(j)=='A') break;
		System.out.println(j>i ? 0 : (i-j)+1);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

} Main
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length(), i=0, j=0;
		for (i=len-1; i>=0; i--) if (s.charAt(i)=='Z') break;
		for (j=0; j<len; j++) if (s.charAt(j)=='A') break;
		System.out.println(j>i ? 0 : (i-j)+1);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}