import strutils, sequtils, algorithm, math var n = readLine(stdin).parseInt() vSeq = readLine(stdin).split(' ').map(parseInt) dp = newSeq[int](1002) dp[0] = vSeq[0] if n > 1: dp[1] = vSeq[1] if n > 2: dp[2] = max(dp[0] + vSeq[2], dp[1]) for i in countup(3, n - 1): dp[i] = max(dp[i - 3] + vSeq[i], dp[i - 2] + vSeq[i], dp[i - 1]) echo(dp[n - 1])