using System.Collections.Generic; using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); var ans = getAns(s); Console.WriteLine(ans); } public static int getAns(string s) { var s2 = ""; var p = ""; var padd = false; for (int i = 0; i < s.Length; i++) { if (padd) { if (s[i] == ')') { s2 += calc(p).ToString(); padd = false; p = ""; } else p += s[i]; } else { if (s[i] == '(') padd = true; else s2 += s[i]; } } return calc(s2); } public static int calc(string s) { string[] line = s.Split('+', '-'); var a = Array.ConvertAll(line, int.Parse); var aL = a.Length; if (aL == 1) return a[0]; var b = new List(); for (int i = 0; i < s.Length; i++) if (s[i] == '+') b.Add(1); else if (s[i] == '-') b.Add(0); int ans; if (b[0] == 1) ans = a[0] + a[1]; else ans = a[0] - a[1]; if (aL == 2) return ans; for (int i = 2; i < aL; i++) if (b[i - 1] == 1) ans += a[i]; else ans -= a[i]; return ans; } }