s = gets.chomp #p s max = 0 (0...s.length).each do |i| # print s[0, i], " ", s[i..-1], "\n" s2 = s[i..-1] + s[0, i] next if s2[0] == '+' || s2[0] == '-' || s2[-1] == '+' || s2[-1] == '-' #p s2 sum = 0 ope_index = s2.index(/[+|-]/) sum = s2[0, ope_index].to_i # p sum ope = s2[ope_index] # p ope s2 = s2[ope_index+1..-1] # p s2 while s2 != nil # p ope # p s2 ope_index = s2.index(/[+|-]/) # p ope_index if !ope_index if ope == '+' sum += s2.to_i else sum -= s2.to_i end break else if ope == '+' sum += s2[0..ope_index - 1].to_i else sum -= s2[0..ope_index - 1].to_i end ope = s2[ope_index] s2 = s2[ope_index + 1..-1] end end max = [sum, max].max end puts max