# Here your code ! N=gets.to_i @ks=gets.split.map(&:to_i) # p @ks @memo={} def go(mask, first) # puts "start: mask=#{mask}" if @memo[mask] != nil return @memo[mask] end result = false (0...N).each{|a| if(mask[a]) next end mask[a]=true (a+1...N).each{|b| if(mask[b]) next end mask[b]=true (b+1...N).each{|c| if(mask[c]) next end mask[c]=true #puts "c: mask=#{mask}, a,b,c=#{a}, #{b}, #{c}" if @ks[a]==@ks[b] || @ks[b]==@ks[c] || (@ks[b]!=([@ks[a],@ks[b],@ks[c]]).max && @ks[b]!=([@ks[a],@ks[b],@ks[c]]).min) mask[c]=nil next end ret = go(mask, false) if ret == false result = true if first puts [a,b,c].join(" ") exit end end mask[c]=nil } mask[b]=nil } mask[a]=nil } # puts "end: mask=#{mask}, result=#{result}" @memo[mask]=result return result end go(Array.new(N,nil), true) puts -1