n = int(input()) if n == 0: print(0) exit() a = list(map(int, input().split())) # Step 1: Split into groups of consecutive same values groups = [] current_val = a[0] current_count = 1 for num in a[1:]: if num == current_val: current_count += 1 else: groups.append((current_val, current_count)) current_val = num current_count = 1 groups.append((current_val, current_count)) # Step 2: Calculate same_max from collections import defaultdict value_sum = defaultdict(int) for val, cnt in groups: value_sum[val] += cnt same_max = max(value_sum.values()) if value_sum else 0 # Step 3: Calculate indep_max using dynamic programming prev_no = 0 prev_yes = 0 for num in a: current_no = max(prev_no, prev_yes) current_yes = prev_no + 1 prev_no, prev_yes = current_no, current_yes indep_max = max(prev_no, prev_yes) # Determine the result print(max(same_max, indep_max))