class Yukicoder def initialize a, b, s = gets.chomp.split(' ').map(&:to_i) if (a - s).abs <= (b - s).abs puts (a - s).abs + s else if s == 1 puts (a - s).abs + s else dist1 = (b - s).abs + (s - 1) + (a - 1).abs + 1 dist2 = (b - s).abs + (a - s).abs + a + (a.zero? ? 1 : 0) puts [dist1, dist2].min end end end end Yukicoder.new