import sequtils, strutils let n = parseInt readLine stdin vs = stdin.readLine.split.map parseInt var dp = 0.repeat n dp[0] = vs[0] if n >= 2: dp[1] = vs[1] if n >= 3: dp[2] = vs[0] + vs[2] if n >= 4: for i in 3 ..< n: dp[i] = vs[i] + max(dp[i.pred 2], dp[i.pred 3]) echo max dp