

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        } sc.hasNext() sc.hasNext sc {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        } char[] s = sc.next().toCharArray(); s sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int left = 0; left 0 while (s[left] != 'A') {
                left++;
            } s[left] != 'A' s[left] s left 'A' {
                left++;
            } left++ left int right = s.length - 1; right s.length - 1 s.length s s.length 1 while (s[right] != 'Z') {
                right--;
            } s[right] != 'Z' s[right] s right 'Z' {
                right--;
            } right-- right System.out.println(right - left + 1) System.out.println System.out System System.out right - left + 1 right - left right left 1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        }
    }
} Main


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] s = sc.next().toCharArray();
            int left = 0;
            while (s[left] != 'A') {
                left++;
            }

            int right = s.length - 1;
            while (s[right] != 'Z') {
                right--;
            }

            System.out.println(right - left + 1);
        }
    }
}
