if gets.chomp!.split(/[c+-]/, -1).include?('') puts:ERROR else str = $_.include?(?c)? $_[/c\K[^c]*$/] : $_ ary = str.split(/\b/) ary.each_with_index{|s, i| case s when /^\d+$/ then next when ?+ then ary[i - 1].succ! when ?- then ary[i + 1] = (ary[i + 1].to_i - 1).to_s end ary[i] = nil } puts ary.compact*'' end