#include #include #include #include #include #include using namespace std; int n = 0; int nums[1001]; int b[1001][30100]; int ans = 0; void dfs(int i, int sum, bool judge) { if (i == n) { ans = max(ans, sum); /*cout << i << " " << ans << endl;*/ return; } if(b[i][sum] !=0){ return; } dfs(i + 1, sum, false); b[i+1][sum] =1; if (!judge) { dfs(i + 1, sum + nums[i], true); /* b[i+1][sum+nums[i]] =1;*/ }/* else { dfs(i + 1, sum, false); }*/ return; } int main() { cin >> n; int tmp = 0; for (int i = 0; i < n; i++) { cin >> tmp; nums[i] = tmp; } dfs(0, 0, false); cout << ans << endl; return 0; }