package main import ( "bufio" "fmt" "go/token" "go/types" "os" "strings" ) func main() { stdin := bufio.NewScanner(os.Stdin) stdin.Scan() stdin.Scan() exp := stdin.Text() exp = simplifyExpression(exp) res, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, exp) fmt.Println(res.Value) } func simplifyExpression(exp string) string { var result strings.Builder prevChar := ' ' positive := true for _, char := range exp { if char == '+' || char == '-' { if char == '-' { positive = !positive } } else { if prevChar == '+' || prevChar == '-' { if positive { result.WriteRune('+') } else { result.WriteRune('-') } } result.WriteRune(char) positive = true } prevChar = char } return result.String() }