#include using namespace std; template bool cmin(T &a, U b) { return a > b && (a = b, true); } template bool cmax(T &a, U b) { return a < b && (a = b, true); } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int A, B, S; cin >> A >> B >> S; if (S == 1 || abs(S - A) <= abs(S - B)) return cout << abs(S - A) + S << "\n", 0; int ans1 = abs(S - B) + abs(S - A) + A; int ans2 = abs(S - B) + abs(S - 1) + A; cout << min(ans1, ans2) << "\n"; }