package main import ( "fmt" "math" ) func MinInt(x, y int) int { return int(math.Min(float64(x), float64(y))) } func AbsInt(x int) int { return int(math.Abs(float64(x))) } func resolve(A, B, S int) int { if AbsInt(A-S) <= AbsInt(B-S) { // Move A return AbsInt(A-S) + S } // Move B + A if A == 0 { // goto and upto 1st floor return AbsInt(B-S) + S + 1 } // goto 1st floor tmp1 := AbsInt(B-S) + (S - 1) + A // goto A floor tmp2 := AbsInt(B-S) + AbsInt(A-S) + A return MinInt(tmp1, tmp2) } func main() { var A, B, S int fmt.Scanf("%d %d %d\n", &A, &B, &S) fmt.Println(resolve(A, B, S)) }