type at = A | C | N | E;;

let is_lowercase = function
  | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h'
  | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p'
  | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x'
  | 'y' | 'z' -> true
  | _ -> false;;

let on string index =
  if String.length string == index + 1 then E
  else if index == 0 then A
  else if index >= 2 && ((String.length string) - index) >= 2 then C
  else N

let valid string =
  let rec validate string index c_state =
    match (on string index, string.[index], c_state) with
    | (E, _, true) -> "AC"
    | (A, 'A', _) -> validate string (index + 1) c_state
    | (C, 'C', false) -> validate string (index + 1) true
    | (C, c, true) when c != 'C' -> validate string (index + 1) true
    | (N, 'C', _) -> "WA"
    | (N, c, _) when is_lowercase c -> validate string (index + 1) c_state
    | (_, _, _) -> "WA"
  in validate string 0 false;;

read_line() |> valid |> print_endline
