import numpy as np n = int(input()) a = np.array(list(map(int, input().split())) + [0] * (3 * 3 - n % 3)) length = len(a) free, fix = 0, 0 oxo = [True, False, True] xxo = [False, False, True] oxx = [True, False, False] xox = [False, True, False] def f(array, pos): return np.sum(a[pos:pos + 3] * array) pos = 0 for i in range(length // 3): tmp_fix = max( free + f(oxo, pos), free + f(xxo, pos), fix + f(xxo, pos), ) free = max( fix + f(xox, pos), free + f(oxx, pos), free + f(xox, pos), ) fix = tmp_fix pos += 3 print(max(fix, free))