stdin.ReadLine().ToCharArray() |> Array.indexed |> Array.fold(fun (mem,counter,maxLen) (idx,c) -> let counter = match c with |'A' -> counter + 1 | _ -> counter - 1 match Map.containsKey counter mem with | true -> (mem, counter, (max maxLen (idx - mem.[counter]))) | _ -> ((mem.Add(counter,idx)), counter, maxLen)) (Map.ofList[0,-1],0,0) |> fun (_,_,maxLen) -> printfn "%i" maxLen