#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e15;
long long dp2[505][505];
long long dp[505][505];
char sign[505];
int arr[505];
int n;
void solve() {
  scanf("%d", &n);
  assert(n <= 500);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
    if (i < n) {
      scanf(" %c", &sign[i]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    dp[i][i] = dp2[i][i] = arr[i];
  }
  for (int len = 2; len <= n; ++len) {
    for (int l = 1; l + len - 1 <= n; ++l) {
      int r = l + len - 1;
      for (int i = l; i <= r; ++i) {
        if (i == l || sign[i - 1] == '+') {
          dp[l][r] += arr[i];
          dp2[l][r] += arr[i];
        } else {
          dp[l][r] -= arr[i];
          dp2[l][r] -= arr[i];
        }
      }
      for (int i = l; i < r; ++i) {
        if (sign[i] == '-') {
          dp[l][r] = max(dp[l][r], dp[l][i] - dp2[i + 1][r]);
          dp2[l][r] = min(dp2[l][r], dp2[l][i] - dp[i + 1][r]);
        }
      }
    }
  }
  printf("%lld", dp[1][n]);
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
