#include <stdio.h> int max(int a, int b) { return a > b ? a : b; } int main() { int a[1001], dp[1001], n; while (scanf("%d", &n) != EOF) { int maxinum = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } dp[0] = a[0]; for (int i = 1; i < n; ++i) { dp[i] = a[i]; for (int j = 0; j < i; ++j) { if (a[i] > a[j] && dp[j] + a[i] > dp[i]) { dp[i] = dp[j] + a[i]; } maxinum = max(maxinum, dp[i]); } } printf("%d\n", maxinum); } return 0; }