class Yukicoder def initialize s1 = gets.chomp.chars n = gets.to_i s2 = gets.chomp.chars success = true success &= s1.sort == s2.sort if success && (s1 & s2).size == 2 o_diff = (s1.index('o') - s2.index('o')).abs x_diff = (s1.index('x') - s1.index('x')).abs diff = [o_diff, x_diff].max success &= diff <= n if n == 1 && ([s1,s2].include?(%w(o x o)) || [s1,s2].include?(%w(x o x))) success &= diff > 0 end end if success puts "FAILURE" else puts "SUCCESS" end end end Yukicoder.new