let sBefore = stdin.ReadLine () let n = stdin.ReadLine () |> int let sAfter = stdin.ReadLine () let rec next (stateSet: string Set) count = if count = 0 then stateSet else let mutable s = Set.empty for i in stateSet do s <- s.Add <| string i.[1] + string i.[0] + string i.[2] s <- s.Add <| string i.[0] + string i.[2] + string i.[1] next s (count-1) next (Set.empty.Add sBefore) n |> Set.contains sAfter |> (fun x -> printfn "%s" (if x then "FAILURE" else "SUCCESS"))