n = int(input()) a = list(map(int, input().split())) l = [] i = 0 while i < n: cnt = 1 while i < n - 1 and a[i] == a[i + 1]: cnt += 1 i += 1 l.append(cnt) i += 1 m = len(l) dp = [[0] * (m + 1) for _ in range(2)] dp[0][0] = 0 for i in range(m): dp[1][i + 1] = dp[0][i] + l[i] dp[0][i + 1] = max(dp[0][i], dp[1][i]) print(max(dp[0][m], dp[1][m]))