import java.util.Scanner; /** * Created by poly on 11/29/14. */ public class Main { static int[][][] memo; static int solve(int a, int b, int s) { if (s == 1) { return Math.abs(a - 1) + 1; } if (Math.abs(a - s) <= Math.abs(b - s)) { return Math.abs(a - s) + s; } if (memo[a][b][s] > 0) { return memo[a][b][s]; } int bmove = Math.abs(b - s); int ans = bmove + Math.abs(s - 1) + solve(a, 1, 1); if (a != 0) { ans = Math.min(ans, bmove + Math.abs(s - a) + solve(a, a, a)); } memo[a][b][s] = ans; return ans; } public static void main(String[] argv) { Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); int b = scanner.nextInt(); int s = scanner.nextInt(); memo = new int[101][101][101]; int ans = solve(a, b, s); System.out.println(ans); } }