n = int(input()) a = list(map(int, input().split())) dp = {} que = [[0, 0]] def solve(): while que: # print(que, dp) i, w = que.pop(0) if dp.get(i) and dp[i] != w: continue if -1 < i - 2 < n: w += a[i - 2] for x in range(2, 4): ii = i + x dp[ii] = max(dp[ii], w) if dp.get(ii) else w if i < n: que.append([i + 2, w]) que.append([i + 3, w]) # dp[i + 2] = w # dp[i + 3] = w solve() print(max(dp.values()))