#include using namespace std; int multiply(vector vec){ int calc = 1; int i; int start = 0; for (i = 0; i < vec.size(); i++){ if (vec[i] == '*'){ vector substr; for (int j = start; j < i; j++){ substr.push_back(vec[j]); } calc *= atoi(&substr[0]); start = i + 1; } } vector substr; for (int j = start; j < i; j++){ substr.push_back(vec[j]); } calc *= atoi(&substr[0]); return calc; } int fun(vector vec){ vector arr; int start = 0; int i; int sum = 0; for (i = 0; i < vec.size(); i++){ if (vec[i] == '+'){ vector substr; for (int j = start; j < i; j++){ substr.push_back(vec[j]); } //cout <<"fasdf" << multiply(substr); arr.push_back(multiply(substr)); start = i + 1; } } vector substr; for (int j = start; j < i; j++){ substr.push_back(vec[j]); } arr.push_back(multiply(substr)); for (int j = 0; j < arr.size(); j++){ sum += arr[j]; } return sum; } int main() { int n; cin >> n; string s; cin >> s; int number; vector res; for(int i = 1; i < s.length(); i++) { if(s[i-1] == '(' && s[i] == ')') { res.push_back('1'); } else if(s[i-1] == ')' && s[i] == ')') { res.push_back('+'); res.push_back('1'); res.push_back(')'); } else if(s[i-1] == ')' && s[i] == '(') { res.push_back('*'); } else { res.push_back('('); } } /* for (int i = 0; i < res.size(); i++){ cout << res[i]; } cout << endl; */ int start_index = 0; int end_index = 0; int calc = 0; vector array = res; int flag1 = 0; int flag = 0; while(!flag){ int i = 0; while(1){ if (array[i] == '('){ start_index = i; } else if (array[i] == ')'){ end_index = i; if (end_index == array.size()-1) flag = 1; break; } i++; if (i >= array.size()){ flag1 = 1; break; } } if (flag1) break; vector substr; for (int j = start_index + 1; j < end_index; j++){ substr.push_back(array[j]); //cout << array[j]; } calc = fun(substr); string str = to_string(calc); res = array; vector arr2; for (int j = 0; j < start_index; j++){ arr2.push_back(res[j]); } for (int j = 0; j < str.size(); j++){ arr2.push_back(str[j]); } for (int j = end_index + 1; j < res.size(); j++) { arr2.push_back(res[j]); } /*for (int i = 0; i < arr2.size(); i++){ cout << arr2[i]; }*/ array = arr2; if (flag) break; start_index = 0; end_index = 0; } int nn = fun(array); cout<< nn << endl; return 0; }