package no197; import java.util.Scanner; public class Main { /* * 123 * 132 * 213 * 231 * 312 * 321 */ static int[][] perm = {{1,2,3},{1,3,2},{2,1,3},{2,3,1},{3,1,2},{3,2,1}}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] bef = sc.next().toCharArray(); long n = sc.nextLong(); char[] aft = sc.next().toCharArray(); int[][] a = {{0,1,1,0,0,0},{1,0,0,0,1,0},{1,0,0,1,0,0},{0,0,1,0,0,1},{0,1,0,0,0,1},{0,0,0,1,1,0}}; int[][] x = new int[6][6]; for(int i=0;i<6;i++) { x[i][i] = 1; } while(n > 0) { if (n % 2 == 1) { x = mul(x,a); } a = mul(a,a); n /= 2; } LOOP: for(int i=0;i<6;i++) { if (x[0][i] == 1) { for(int j=0;j<3;j++) { if (bef[j] != aft[perm[i][j]-1]) { continue LOOP; } } System.out.println("FAILURE"); return; } } System.out.println("SUCCESS"); } static int[][] mul(int[][] a,int[][] b) { int n = a.length; int[][] c = new int[n][n]; for(int i=0;i