n = int(input()) if n == 0: print(0) exit() arr = list(map(int, input().split())) last_occurrence = {} max_length = 0 left = 0 for right in range(n): current = arr[right] if current in last_occurrence: # Ensure left pointer moves to the right of the last occurrence of current left = max(left, last_occurrence[current] + 1) # Update the last occurrence of the current element last_occurrence[current] = right # Calculate the current window length and update max_length current_length = right - left + 1 if current_length > max_length: max_length = current_length print(max_length)