class Solution {
public:
int calPoints(vector<string>& ops) {
stack<int> st;
for (auto op : ops) {
if (op == "C") {
st.pop();
} else if (op == "D") {
int a = st.top();
st.push(a * 2);
} else if (op == "+") {
int a = st.top(); st.pop();
int b = st.top();
st.push(a);
st.push(a + b);
} else {
st.push(stoi(op));
}
}
int res = 0;
while (!st.empty()) {
cout << st.top() << endl;
res += st.top();
st.pop();
}
return res;
}
};