import java.util.*; /** * Created by poly on 11/29/14. */ public class Main { static Set cand(Set set) { Set list = new HashSet(); for (String s : set) { String a = "" + s.charAt(1) + s.charAt(0) + s.charAt(2); String b = "" + s.charAt(0) + s.charAt(2) + s.charAt(1); list.add(a); list.add(b); } return list; } public static void main(String[] argv) { Scanner scanner = new Scanner(System.in); String before = scanner.next(); int n = scanner.nextInt(); String after = scanner.next(); if (n == 0) { if (after.equals(before)) { System.out.println("FAILURE"); } else { System.out.println("SUCCESS"); } return; } Set input = new HashSet(); input.add(before); Set one = cand(input); if (n % 2 == 1) { if (one.contains(after)) { System.out.println("FAILURE"); } else { System.out.println("SUCCESS"); } return; } Set two = cand(one); if (two.contains(after)) { System.out.println("FAILURE"); } else { System.out.println("SUCCESS"); } } }