import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) dpz = [0]*N dpm = [0]*N dpz[0] = 1 for i in range(1, N): ap = A[i-1] an = A[i] if ap == an: dpz[i] = 1 + max(dpz[i-1], dpm[i-1]) dpm[i] = max(dpz[i-1], dpm[i-1]) else: dpz[i] = 1 + dpm[i-1] dpm[i] = max(dpz[i-1], dpm[i-1]) print(max(dpm[N-1], dpz[N-1]))