class Yukicoder def initialize a, b, s = gets.chomp.split(' ').map(&:to_i) route1 = (s - a).abs + s route2 = (s - b).abs + (s - a) + a + ((a.zero?) ? 2 : 0) puts [route1, route2].min end end Yukicoder.new