H = {} H[0] = [[0, 1, 2]] H[1] = [[0, 2, 1], [1, 0, 2]] H[2] = [[0, 1, 2], [1, 2, 0], [2, 0, 1]] H[3] = [[0, 2, 1], [1, 0, 2], [2, 1, 0]] def possible?(sb, n, sa) aa = n <= 1 ? H[n] : n % 2 == 0 ? H[2] : H[3] aa.each do |a| flg = true a.each.with_index do |j, i| if sb[j] != sa[i] then flg = false break end end return true if flg end return false end SB = gets.chomp N = gets.to_i SA = gets.chomp puts possible?(SB, N, SA) ? "FAILURE" : "SUCCESS"