N = int(input()) A = list(map(int,input().split())) katamari = [] kosu = 1#ある数字のかたまりに含まれる,その数字の個数 prev = None#直前の値 for a in A: if a == prev: kosu += 1 else: katamari.append(kosu) prev = a kosu = 1 katamari.append(kosu) katamari = katamari[1:] #print(katamari) if len(katamari) > 1: dp = [katamari[0],katamari[1]] + [0]*(len(katamari)-2)#その位置を採用したときの最大値 for i in range(2,len(katamari)): dp[i] = dp[i-2] + katamari[i] try: dp[i] = max(dp[i], dp[i-3] + katamari[i]) except IndexError: pass #print(dp) print(dp[-1]) else: print(katamari[0])