N = int(input()) A = list(map(int,input().split())) l = [] l.append(1) for i in range(1,N): if A[i] == A[i-1]: l[-1] += 1 else: l.append(1) n = len(l) dp = [[0] * 2 for _ in range(n)] dp[0][1] = l[0] for i in range(1,n): dp[i][0] = max(dp[i-1][1],dp[i-1][0]) dp[i][1] = dp[i-1][0] + l[i] print(max(dp[-1]))