def solve(s,a,b) if s == 0 0 elsif s == 1 (s - a).abs + 1 elsif (s - a).abs < (s - b).abs (s - a).abs + s else candiate = [(s-b).abs + (s-1).abs + (a - 1).abs + 1] candiate.push((s-b).abs + (s-a).abs + a) if a > 0 candiate.min end end a,b,s = gets.split.map(&:to_i) puts solve(s,a,b)