#include #include #include #include #include #include using namespace std; #define rep(i,n) for(int i=0; i<(int)(n); i++) int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; string S; cin >> N >> S; vector sumQ = {0}; int v = 0, rev = 1, pos = 0; int hi = 0; int ans = 0; for(char c : S){ int dx = 0; sumQ.push_back(sumQ.back()); if(c == '-') dx = -1; if(c == '+') dx = 1; dx *= rev; if(c == '?'){ dx = 1; hi++; } v += dx; hi = max(hi, v); if(v < 0){ ans++; v = hi*2 + 1; rev *= -1; hi = v; } pos++; } ans = (ans + 1) / 2; cout << ans << '\n'; return 0; }