#include using namespace std; class Solution { public: vector state; Solution() { char tmp; while(cin >> tmp) { if(tmp == '+') state.push_back(true); else state.push_back(false); } } void reverse( size_t start, size_t end ){ vector tmp; tmp.clear(); // cout << start << " " << end << endl; while(end >= start) { tmp.emplace_back(state[end]); end--; } // cout << "reversed this shit: "<< endl; // for(auto j : tmp) // { // cout << j; // } // cout << endl; for(auto j : tmp) { state[start] = j; start++; } } size_t solve() { size_t operations = 0; size_t i = 0; bool prev = !state[i]; while( i < state.size() ){ // cout << "===========" << endl; // cout << "i is: " << i << endl; if( state[i] == prev){ // cout << "found match on: " << i << endl; // print(); operations++; size_t startIndex; size_t endIndex; startIndex = i; while( state[i] == prev ) i++; while( state[i] != prev ){ prev = state[i]; i++; if( i >= state.size() ) break; } endIndex = i - 1; reverse( startIndex, endIndex); i = 0; prev = !state[0]; } prev = state[i]; i++; } return operations; } void print(){ for( auto it : state ){ cout << it; } cout << endl; } }; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); Solution sol; cout << sol.solve() << endl; return 0; }