#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;
long long calc2(int, int);
long long calc(int, int);
void init() {
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      dp[l][r] = dp2[l][r] = -INF;
    }
  }
}
long long calc(int l, int r) {
  if (l > r) {
    return 0;
  }
  if (l == r) {
    return arr[l];
  }
  long long &cur = dp[l][r];
  if (cur != -INF) {
    return cur;
  }
  cur = 0;
  for (int i = l; i <= r; ++i) {
    if (i == l || sign[i - 1] == '+') {
      cur += arr[i];
    } else {
      cur -= arr[i];
    }
  }
  for (int mid = l; mid < r; ++mid) {
    if (sign[mid] == '-') {
      cur = max(cur, calc(l, mid) - calc2(mid + 1, r));
    } else {
      cur = max(cur, calc(l, mid) + calc(mid + 1, r));
    }
  }
  return cur;
}
long long calc2(int l, int r) {
  if (l > r) {
    return 0;
  }
  if (l == r) {
    return arr[l];
  }
  long long &cur = dp2[l][r];
  if (cur != -INF) {
    return cur;
  }
  cur = 0;
  for (int i = l; i <= r; ++i) {
    if (i == l || sign[i - 1] == '+') {
      cur += arr[i];
    } else {
      cur -= arr[i];
    }
  }
  for (int mid = l; mid < r; ++mid) {
    if (sign[mid] == '-') {
      cur = min(cur, calc2(l, mid) - calc(mid + 1, r));
    } else {
      cur = min(cur, calc2(l, mid) + calc2(mid + 1, r));
    }
  }
  return cur;
}
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]);
    }
  }
  init();
  printf("%lld", calc(1, 5));
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
