let sBefore = stdin.ReadLine () let n = stdin.ReadLine () |> int let sAfter = stdin.ReadLine () let stateArray = [| "xxx" "xxo" "xox" "xoo" "oxx" "oxo" "oox" "ooo" |] let rec next (arr: bool array) count = if count = 0 then arr else let a = Array.replicate 8 false for i in 0..arr.Length-1 do if arr.[i] then let index1, index2 = match i with | 0 -> 0, 0 | 1 -> 1, 2 | 2 -> 4, 1 | 3 -> 5, 3 | 4 -> 2, 4 | 5 -> 3, 6 | 6 -> 6, 5 | _ -> 7, 7 a.[index1] <- true a.[index2] <- true next a (count-1) let firstState = Array.replicate 8 false firstState.[Array.findIndex ((=)sBefore) stateArray] <- true if n >= 2 then printfn "FAILURE" else next firstState n |> Array.get <| (Array.findIndex ((=)sAfter) stateArray) |> (fun x -> printfn "%s" (if x then "FAILURE" else "SUCCESS"))