def is_valid(formula): n = len(formula) if n < 3: return False if formula[0] in '+-' or formula[-1] in '+-': return False has_operator = False prev_is_op = False for i in range(n): c = formula[i] if c in '+-': if prev_is_op: return False has_operator = True prev_is_op = True else: prev_is_op = False return has_operator def evaluate(formula): tokens = [] current_number = [] for c in formula: if c in '+-': num = int(''.join(current_number)) tokens.append(num) tokens.append(c) current_number = [] else: current_number.append(c) if current_number: num = int(''.join(current_number)) tokens.append(num) else: return None # should not happen for valid formula current = tokens[0] for i in range(1, len(tokens), 2): op = tokens[i] num = tokens[i+1] if op == '+': current += num else: current -= num return current S = input().strip() n = len(S) max_val = -float('inf') for i in range(n): rotated = S[i:] + S[:i] if not is_valid(rotated): continue val = evaluate(rotated) if val is not None and val > max_val: max_val = val print(max_val)