#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 101 * 1001, MOD = 1e9 + 7, sq = 333;
long long a[MAXN];
char ch[MAXN];
long long dp[1055][1055][2];
long long solve(long long n) {
  for (long long i = 0; i < n; i++)
    dp[i][i + 1][0] = a[i], dp[i][i + 1][1] = -a[i];
  for (long long l = 2; l <= n; l++) {
    for (long long i = 0; i + l <= n; i++) {
      long long j = i + l;
      dp[i][j][0] = a[i] + dp[i + 1][j][0];
      if (a[i] < 0)
        for (long long k = i + 2; k <= j; k++)
          dp[i][j][0] = max(dp[i][j][0], a[i] + dp[i + 1][k][1] + dp[k][j][0]);
      dp[i][j][1] = -a[i] + dp[i + 1][j][1];
      if (a[i] < 0)
        for (long long k = i + 2; k <= j; k++)
          dp[i][j][1] = max(dp[i][j][1], -a[i] + dp[i + 1][k][0] + dp[k][j][1]);
    }
  }
  return dp[0][n][0];
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, s = 0, ind = -1, cnt = 0;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    if (i) cin >> ch[i];
    cin >> a[i];
    s += a[i];
    if (ch[i] == '-' && ind == -1) ind = i;
    if (i && ch[i] == '-') a[i] *= -1, cnt++;
  }
  if (n < 1050) return cout << solve(n), 0;
  if (ind == -1) return cout << s, 0;
  if (cnt == 1) return cout << s + 2 * a[ind], 0;
  ind++;
  s += 2 * a[ind - 1];
  while (ch[ind] != '-') s -= 2 * a[ind++];
  return cout << s, 0;
}
