def lscan; gets.split.map(&:to_i); end n = gets.to_i aa = lscan.reverse p [0, aa.each_with_index.map{|a,i| a == n ? -1 : n - i}.reduce(:+)].max