#!/usr/bin/env crystal def value(n : Int32, a : Array(Int32)) idxes=Hash(Int32,Int32).new a.each_with_index{|e,i|idxes[e]=i} ret=0 1.upto(n-1){|i| idxi=idxes[i] (i+1).upto(n){|j| idxj=idxes[j] r=0 (0..n-1).each{|idxk| next if idxk==idxi || idxk==idxj next if rb[1]&&b[2]>b[1]) } ret+=[r,i,j].max if r>0 } } ret end n,m=gets.not_nil!.split.map(&.to_i) p (0..m-1).max_by{|i|value(n,gets.not_nil!.split.map(&.to_i))}