import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); auto st = SList!Token(Token(Typ.Num, cast(int)(s[0]-'0'))); auto calc() { auto t1 = st.front; st.removeFront(); auto t2 = st.front; st.removeFront(); auto t3 = st.front; st.removeFront(); st.insertFront(Token(Typ.Num, t2.t == Typ.Plus ? t3.v+t1.v : t3.v-t1.v)); } auto i = 1; while (i < s.length) { auto c = s[i++]; if (c == '+') { st.insertFront(Token(Typ.Plus, 0)); } else if (c == '-') { st.insertFront(Token(Typ.Minus, 0)); } else if (c == '(') { st.insertFront(Token(Typ.Num, cast(int)(s[i++]-'0'))); } else if (c == ')') { calc(); } else { st.insertFront(Token(Typ.Num, cast(int)(c-'0'))); calc(); } } writeln(st.front.v); } enum Typ { Num, Plus, Minus } struct Token { Typ t; int v; }