#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4 ;
long long mem[5002][5002];
vector<long long > a(N) ;
int n ;
long long dp(int idx,int rem){
if (idx==n)return 0;
long long &ret=mem[idx][rem];
if (~ret)return ret;
long long op=0;
if (rem>=idx+1)
op= max(op, dp(idx,rem-idx-1)+a[idx]);
op= max(op,dp(idx+1,rem));
return ret=op;
}
int main() {
ios_base::sync_with_stdio(),cin.tie(0),cout.tie(0) ;
cin>>n;
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
mem[i][j]=-1;
}
}
cout<<dp(0,n)<<'\n';
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMWU1ICsgNCA7CmxvbmcgbG9uZyBtZW1bNTAwMl1bNTAwMl07CnZlY3Rvcjxsb25nIGxvbmcgPiBhKE4pIDsKaW50IG4gOwpsb25nIGxvbmcgZHAoaW50IGlkeCxpbnQgcmVtKXsKICAgIGlmIChpZHg9PW4pcmV0dXJuIDA7CiAgICBsb25nIGxvbmcgJnJldD1tZW1baWR4XVtyZW1dOwogICAgaWYgKH5yZXQpcmV0dXJuIHJldDsKICAgIGxvbmcgbG9uZyBvcD0wOwogICAgaWYgKHJlbT49aWR4KzEpCiAgICAgICAgb3A9IG1heChvcCwgZHAoaWR4LHJlbS1pZHgtMSkrYVtpZHhdKTsKICAgIG9wPSBtYXgob3AsZHAoaWR4KzEscmVtKSk7CiAgICByZXR1cm4gcmV0PW9wOwp9CmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygpLGNpbi50aWUoMCksY291dC50aWUoMCkgOwogICAgY2luPj5uOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICBjaW4+PmFbaV07CiAgICB9CiAgICBmb3IgKGludCBpID0gMDsgaSA8PSBuOyArK2kpIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8PSBuOyArK2opIHsKICAgICAgICAgICAgbWVtW2ldW2pdPS0xOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQ8PGRwKDAsbik8PCdcbic7CiAgICByZXR1cm4gMCA7Cn0K