# frozen_string_literal: true def solve (0..(S.size - 1)).map do |i| s = S.chars.rotate(i).join s.stem? ? [(eval s)] : [] # rubocop:todo Security/Eval end.reduce(:+).max end class String # rubocop:todo Style/Documentation def stem? match?(/^[^+-].*[^+-]$/) end end S = gets.chomp puts solve