import sequtils,strutils,math var N = stdin.readline.parseInt V = stdin.readline.split.map(parseInt) dp : array[1002,array[2,int]] for i,v in V: dp[i + 1][0] = max(dp[i]) dp[i + 1][1] = dp[i][0] + v echo max(dp[N])