#include using namespace std; int N; int taste[1000] = {0}; int dp[1001] = {0}; int result = 0; void rec(int number = 0, int sum = 0){ if(number == (N - 1) || number == (N - 2)){ if(result < sum) result = sum; if(sum == 0) result = taste[number]; return; } if(dp[number] != 0 && dp[number] >= sum) return; dp[number] = sum; int i; if(number == 0 && sum == 0){ for(i = 0; i < N; ++i){ rec(i, sum + taste[i]); } } else{ for(i = number + 1; i < N; ++i){ if(i != (number + 1)) rec(i, sum + taste[i]); } } return; } int main(void){ cin >> N; int i; for(i = 0; i < N; ++i){ cin >> taste[i]; } rec(); cout << result << endl; return 0; }