#include <bits/stdc++.h>
using namespace std;
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)(1e9 + 7);
long long N;
long long A[200000] = {};
char op[200000] = {};
pair<long long, long long> ma(long long l);
pair<long long, long long> mi(long long l);
pair<long long, long long> mi(long long l) {
  if (0) {
    cerr << "\"mi\""
         << " "
         << "mi" << endl;
  };
  long long ret = A[l];
  long long tmp = A[l];
  long long min_index = l;
  for (long long i = (l + 1); i < (N); i++) {
    if (op[i] == '-') {
      pair<long long, long long> res = ma(i);
      tmp -= res.first;
      i = res.second;
    } else {
      tmp += A[i];
    }
    if (tmp <= ret) {
      ret = tmp;
      min_index = i;
    }
    if (0) {
      cerr << "i"
           << " " << i << endl;
    };
    if (0) {
      cerr << "tmp"
           << " " << tmp << endl;
    };
    if (0) {
      cerr << "ret"
           << " " << ret << endl;
    };
  }
  return make_pair(ret, min_index);
}
pair<long long, long long> ma(long long l) {
  if (0) {
    cerr << "\"ma\""
         << " "
         << "ma" << endl;
  };
  long long ret = A[l];
  long long tmp = A[l];
  long long max_index = l;
  for (long long i = (l + 1); i < (N); i++) {
    if (op[i] == '-') {
      pair<long long, long long> res = mi(i);
      tmp -= res.first;
      i = res.second;
    } else {
      tmp += A[i];
    }
    if (tmp >= ret) {
      ret = tmp;
      max_index = i;
    }
    if (0) {
      cerr << "i"
           << " " << i << endl;
    };
    if (0) {
      cerr << "tmp"
           << " " << tmp << endl;
    };
    if (0) {
      cerr << "ret"
           << " " << ret << endl;
    };
  }
  return make_pair(ret, max_index);
}
long long solve() {
  pair<long long, long long> res = ma(0);
  long long ret = res.first;
  while (res.second < N) {
    res = ma(res.second + 1);
    ret += res.first;
  }
  return ret;
}
signed main() {
  cin >> N;
  cin >> A[0];
  for (long long i = (1); i < (N); i++) cin >> op[i] >> A[i];
  cout << solve() << endl;
  return 0;
}
