n = int(input()) a = list(map(int, input().split())) if n == 0: print(0) exit() # Segment the array into blocks of consecutive same values blocks = [] current_val = a[0] current_length = 1 for num in a[1:]: if num == current_val: current_length += 1 else: blocks.append(current_length) current_val = num current_length = 1 blocks.append(current_length) # Apply dynamic programming similar to the House Robber problem prev_no = 0 prev_yes = 0 for length in blocks: new_no = max(prev_no, prev_yes) new_yes = prev_no + length prev_no, prev_yes = new_no, new_yes print(max(prev_no, prev_yes))