from collections import defaultdict def compute_parity(perm): n = len(perm) visited = [False] * n parity = 0 for i in range(n): if not visited[i]: cycle_length = 0 j = i while not visited[j]: visited[j] = True j = perm[j] cycle_length += 1 parity += cycle_length - 1 return parity % 2 def solve(): S = input().strip() N = int(input()) T = input().strip() if sorted(S) != sorted(T): print("SUCCESS") return # Build permutation by tracking positions of each character in S pos_map = defaultdict(list) for idx, char in enumerate(S): pos_map[char].append(idx) current_ptr = defaultdict(int) permutation = [] for char in T: available = pos_map[char] permutation.append(available[current_ptr[char]]) current_ptr[char] += 1 parity = compute_parity(permutation) if parity == N % 2: print("FAILURE") else: print("SUCCESS") solve()