S = gets.chomp len = S.length source = S * 2 max = -1e10 0.upto(len-1) do |i| tmp = source[i, len] if !tmp.start_with?("+", "-") && !tmp.end_with?("+", "-") then max = [max, eval(tmp)].max end end p max