#include #include #include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; int main(){ int N; string S; cin >> N >> S; vector sumQ = {0}; int v = 0, rev = 1, pos = 0; pair hi = {0,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; sumQ.back()++; } v += dx; hi = max(hi, {v,pos+1}); if(v < 0){ ans++; v = hi.first*2 + 1 + (sumQ.back()-sumQ[hi.second])*2; rev *= -1; hi = { v,pos+1 }; } pos++; } ans = (ans + 1) / 2; cout << ans << '\n'; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;