#include using namespace std; using ll = long long; int main() { int n; string s; cin >> n >> s; char p = '+'; for (int i = 0; i < n; i++) { if (s[i] == '?') { if (p == '+') { s[i] = '+'; } } else { p = s[i]; } } p = '+'; for (int i = n - 1; i >= 0; i--) { if (s[i] == '?') { if (p == '+') { s[i] = '+'; } } else { p = s[i]; } } p = '+'; priority_queue pq; int x = 0, y = 0, r = 0; s.push_back('+'); for (int i = 0; i <= n; i++) { if (s[i] == '+') { if (p == '-') { pq.push(y); if (x < 0) { int t = pq.top(); pq.pop(); x += t * 2; r++; } y = 0; } x++; p = '+'; } else { if (s[i] == '-') x--, y++; else x++; p = '-'; } } cout << r << endl; return 0; }