#include #include #include using namespace std; int main() { int a, b, s; cin >> a >> b >> s; int movement = 0; if (s > 1 && abs(a - s) > abs(b - s)) { movement += abs(b - s); int movement1, movement2; int transit = max(1, a); movement1 = movement + abs(s - transit); movement1 += abs(a - transit) + transit; transit = 1; movement2 = movement + abs(s - transit); movement2 += abs(a - transit) + transit; movement = min(movement1, movement2); } else { movement += abs(a - s) + s; } cout << movement << endl; return 0; }