class Calc0126 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @a, @b, @s = args.shift.map(&:to_i) end def run if @s == 1 (@a - 1).abs + 1 elsif (@a - @s).abs > (@b - @s).abs if (@a - @s).abs > (@s - 1) || @a == 0 (@b - @s).abs + (@s - 1) + (@a - 1).abs + 1 else (@b - @s).abs + (@a - @s).abs + (@a - 1) + 1 end else (@a - @s).abs + @s end end end puts Calc0126.new(STDIN.readlines).run if __FILE__ == $0