class Calc0197 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @before = args.shift.first @n = args.shift.first.to_i @after = args.shift.first end def calc cb = @before.split(//).map.with_index { |c, i| c == 'o' ? i : nil }.compact ca = @after.split(//).map.with_index { |c, i| c == 'o' ? i : nil }.compact if cb.size >= 2 cb = [0, 1, 2] - cb ca = [0, 1, 2] - ca end cb.size != ca.size || @n == 0 && cb != ca || cb.size != 0 && check(cb.first, ca.first) end def check(cb, ca) @n == 1 && ( [0, 2].include?(cb) && cb != ca && ca != 1 || cb == 1 && ca == 1 ) end def run calc ? 'SUCCESS' : 'FAILURE' end end puts Calc0197.new(STDIN.readlines).run if __FILE__ == $0