N=gets.to_i Ks=gets.chomp.split.map(&:to_i) $memo = [] $ans = -1 def rec j return if $memo[j] != nil $memo[j] = false ns = [] (0...N).each{|i| if (j & (1 << i)) == 0 ns << i end } for cs in ns.combination(3) ok=false if Ks[cs[0]] < Ks[cs[1]] and Ks[cs[1]] > Ks[cs[2]] ok=true end if Ks[cs[0]] > Ks[cs[1]] and Ks[cs[1]] < Ks[cs[2]] ok=true end if ok j2 = j | (1<