#include #include #include using namespace std; int main() { for(int i = 0; i < 10; ++i) { string s; int maxDepth = 0, maxCount = 0, count = 0, n, depth = 0; list status; cin >> n >> s; for(int j = 0; j < s.size(); ++j) { if(s[j] == '0') { if(depth == 0) break; if(depth > maxDepth) { maxDepth = depth; maxCount = count; } while(depth > 0 && status.back()) { --depth; status.pop_back(); } status.back() = true; } else { ++count; ++depth; status.push_back(false); } } cout << maxCount << endl; } }