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