import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();

    Pattern p = Pattern.compile("^[^A]*(A.*Z)[^Z]*$");
    Matcher m = p.matcher(a);
    if (m.find()) {
      System.out.println(m.group(1).length());
    }
  }
} import java.util.Scanner; Scanner java.util import java.util.regex.Matcher; Matcher java.util.regex import java.util.regex.Pattern; Pattern java.util.regex public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();

    Pattern p = Pattern.compile("^[^A]*(A.*Z)[^Z]*$");
    Matcher m = p.matcher(a);
    if (m.find()) {
      System.out.println(m.group(1).length());
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();

    Pattern p = Pattern.compile("^[^A]*(A.*Z)[^Z]*$");
    Matcher m = p.matcher(a);
    if (m.find()) {
      System.out.println(m.group(1).length());
    }
  } main {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();

    Pattern p = Pattern.compile("^[^A]*(A.*Z)[^Z]*$");
    Matcher m = p.matcher(a);
    if (m.find()) {
      System.out.println(m.group(1).length());
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc Pattern p = Pattern.compile("^[^A]*(A.*Z)[^Z]*$"); p Pattern.compile("^[^A]*(A.*Z)[^Z]*$") Pattern.compile Pattern "^[^A]*(A.*Z)[^Z]*$" Matcher m = p.matcher(a); m p.matcher(a) p.matcher p a if (m.find()) {
      System.out.println(m.group(1).length());
    } m.find() m.find m {
      System.out.println(m.group(1).length());
    } System.out.println(m.group(1).length()) System.out.println System.out System System.out m.group(1).length() m.group(1).length m.group(1) m.group m 1 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();

    Pattern p = Pattern.compile("^[^A]*(A.*Z)[^Z]*$");
    Matcher m = p.matcher(a);
    if (m.find()) {
      System.out.println(m.group(1).length());
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();

    Pattern p = Pattern.compile("^[^A]*(A.*Z)[^Z]*$");
    Matcher m = p.matcher(a);
    if (m.find()) {
      System.out.println(m.group(1).length());
    }
  }
} Main
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();

    Pattern p = Pattern.compile("^[^A]*(A.*Z)[^Z]*$");
    Matcher m = p.matcher(a);
    if (m.find()) {
      System.out.println(m.group(1).length());
    }
  }
}
