#include #include #include #include using namespace std; vector indexOf(string hay, string needle, uint len) { vector positions; uint needleLen = needle.length(); for (uint i = 0; i <= len - needleLen; i++) { bool match = true; for (uint j = 0; j < needleLen; j++) { if (needle[j] != hay[i+j]) { match = false; break; } } if (match) positions.push_back(i); } return positions; } void findReplace(string& ss, string find, string replace, uint len) { auto positions = indexOf(ss, find, len); uint rlen = replace.length(), flen = find.length(); int difflen = rlen-flen; //difflen = how many characters do we gain/lose upon insertion //Resize ss to fit replacements int offset = 0; uint start = 0; if (difflen < 0) { for (uint i = 0; i < positions.size(); i++) { for (uint j = start; j < positions[i]; j++) { ss[j + offset] = ss[j]; } for (uint j = 0; j < rlen; j++) { ss[positions[i] + j + offset] = replace[j]; } start = positions[i] + flen; offset += difflen; } for (uint i = start; i < len+offset; i++) { ss[i] = ss[i-offset]; } } ss.resize(len + offset); } string resExp(string in) { stringstream ss(""); char lastChar = 0; for (uint i = 0; i < in.length(); i++) { switch (lastChar) { case ')': if (in[i] == '(') ss.put('+'); if (in[i] == ')') { ss.put('+'); ss.put('1'); } break; case '(': if (in[i] == ')') ss.put('1'); break; } lastChar = in[i]; } return ss.str(); } int main() { uint n; cin >> n; string s; cin >> s; string reString = resExp(s); auto plusPos = indexOf(reString, "+", reString.length()); vector strInt(plusPos.size()+1, ""); uint i, lastpos=0; uint res = indexOf(reString, "1", reString.length()).size(); /* for (i = 0; i < plusPos.size(); i++) { strInt[i] = reString.substr(lastpos, plusPos[i] - lastpos); lastpos = plusPos[i]+1; } strInt[i] = reString.substr(lastpos, reString.length() - lastpos); uint res = 0; for (uint i = 0; i < strInt.size(); i++) { res += stoul(strInt[i]); }*/ cout << res << endl; return 0; }