N = int(input()) lsA = list(map(int,input().split())) ll = [] cnt = 1 for i in range(1,N): if lsA[i-1] == lsA[i]: cnt += 1 else: ll.append(cnt) cnt = 1 ll.append(cnt) NN = len(ll) dp = [[0,0] for i in range(NN+1)] for i in range(1,NN+1): v = ll[i-1] dp[i][0] = max(dp[i-1][1],dp[i-1][0]) dp[i][1] = dp[i-1][0]+v ans = 0 for i in range(NN+1): ans = max(ans,max(dp[i])) print(ans)