#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 + a; if (s - 1 < a_to_s) { if (a == 0) { res += s + 1; } else { res += s - 1; } } else { res += a_to_s; } } else { res = a_to_s + s; } cout << res << endl; return 0; }