n = int(input()) v = [int(x) for x in input().split()] res = 0 stack = [] memo = [] for i in range(n): memo.append(set()) stack.append(0) memo[0].add(v[0]) s = v[0] res = v[0] end = False while not end: idx = stack[-1] v2 = 0 v3 = 0 if idx + 2 < n: v2 = v[idx + 2] if idx + 3 < n: v3 = v[idx + 3] if v2 != 0 and s + v2 not in memo[idx + 2]: stack.append(idx + 2) memo[idx + 2].add(s + v2) res = max(s + v2, res) s += v2 elif v3 != 0 and s + v3 not in memo[idx + 3]: stack.append(idx + 3) memo[idx + 3].add(s + v3) res = max(s + v3, res) s += v3 else: for j in range(len(stack)): vn = v[stack[-1]] idx_n = stack.pop() if len(stack) < 1: if idx_n == 0 and n >= 2: stack.append(1) s = v[1] else: end = True break idx_p = stack[-1] s -= vn if (s not in memo[idx_p + 2]) or (idx_p + 3 < n and s not in memo[idx_p + 3]): break print(res)