#include <cstdio> #include <cstring> #define max(a,b) ((a)>(b)?(a):(b)) int a[1010], dp[1010]; int main() { int n; while (scanf("%d", &n) != EOF) { memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); dp[i] = a[i]; } int ans = dp[1]; for (int i = 2; i <= n; i++) { for (int j = 1; j < i; j++) { if (a[j] < a[i]) { dp[i] = max(dp[i], dp[j] + a[i]); } } ans = max(ans, dp[i]); } printf("%d\n", ans); } return 0; }