#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
int n, op[N];
long long a[N], sum[N], dp[N];
priority_queue<long long> pq;
vector<int> q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    if (i == n) break;
    char s[2];
    scanf("%s", s);
    if (s[0] == '-')
      op[i] = -1;
    else
      op[i] = 1;
  }
  int idx = 1;
  for (; idx <= n; ++idx) {
    dp[idx] = sum[idx];
    if (op[idx] == -1) break;
  }
  for (int i = idx + 1; i <= n; ++i) {
    dp[i] = dp[i - 1] + (long long)op[i - 1] * a[i];
    if (op[i - 1] == -1) {
      if (((int)q.size()) == 0)
        q.push_back(i);
      else {
        long long val = sum[i - 1] - sum[q.back() - 1];
        pq.push(dp[q.back() - 1] - val - sum[i - 1]);
      }
    }
    if (((int)pq.size()) > 0) dp[i] = max(dp[i], pq.top() + sum[i]);
  }
  printf("%lld", dp[n]);
  return 0;
}
