def kadomatsu original,index tmp = [] 3.times{|i| tmp.push(original[index[i]]) } if tmp.uniq != tmp || tmp.minmax == [tmp[0],tmp[2]].sort return false else return true end end def solution kado,rest,count tmp = rest.combination(3).to_a.select{|a|kadomatsu(kado,a)} flag = count % 2 if tmp.empty? if flag == 0 return false else return true end else tmp.each{|w| if flag == 0 if solution(kado,rest - w,count + 1) return true end else unless solution(kado,rest - w,count + 1) return false end end } if flag == 0 return false else return true end end end n = gets.to_i k = gets.split.map(&:to_i) range = [*0..n-1] kado = range.combination(3).to_a.select{|a|kadomatsu(k,a)} if kado.empty? puts -1 exit end kado.each{|v| if solution(k,range - v,1) puts v.join(' ') exit end } puts -1