Problem:
Score : 200 points

Problem Statement

Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).

Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

Constraints

1 ≦ |s| ≦ 200{,}000

s consists of uppercase English letters.

There exists a substring of s that starts with A and ends with Z.

Input

The input is given from Standard Input in the following format:

s

Output

Print the answer.

Sample Input 1

QWERTYASDFZXCV

Sample Output 1

5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Sample Input 2

ZABCZ

Sample Output 2

4

Sample Input 3

HASFJGHOGAKZZFEGA

Sample Output 3

12

Solution in Scala (2.13.1) (judge verdict: Accepted)

object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  
  val s = inputs.head

  println(solve(s))

  private def solve(s: String): Int = {
    var aIndex = -1
    var zIndex = -1
    val end = s.size - 1
    (0 until end).foreach { i =>
      s(i) match {
        case 'A' if aIndex == -1 => aIndex = i
        case _ => ()
      }

      s(end - i) match {
        case 'Z' if zIndex == -1 => zIndex = end - i
        case _ => ()
      }

      if(aIndex != -1 && zIndex != -1) {
        return zIndex - aIndex + 1
      }
    }
    return -1
  }
}