gets a = gets.split.map(&:to_i) l = 0 h = {} #前回出現位置 max = 0 a.each_with_index do |n, r| l = [l, h[n] + 1].max if h[n] m = r - l + 1 max = m if m > max h[n] = r end puts max