#include #include using namespace std; int main() { int a, b, s; cin >> a >> b >> s; int res; int a_to_s = abs(a - s); int b_to_s = abs(b - s); if (b_to_s < a_to_s && s != 1) { res = b_to_s; if (s < a) { res += s - 1 + a; } else { res += s; } } else { if (a < s) { res = a_to_s + s; } else { res = a; } } cout << res << endl; return 0; }