# frozen_string_literal: true # @see https://yukicoder.me/submissions/14249 by yuki2006 # rubocop:todo Metrics/AbcSize def solve # rubocop:todo Metrics/MethodLength l = 0 r = 0 m = 0 c = Array.new(10**6 + 1, false) while r < N if c[D[r]] m = [m, r - l].max c[D[l]] = false l += 1 else c[D[r]] = true r += 1 end end [m, r - l].max end # rubocop:enable Metrics/AbcSize N = gets.to_i D = gets.chomp.split.map(&:to_i) puts solve