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)} if tmp.empty? if count % 2 == 0 return false else return true end else tmp.each{|w| unless solution(kado,rest - w,count + 1) return false end } return true 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