#include #define rep(i,a,b) for(int i=int(a);i> A >> B >> S; if(S == 1){ cout << (A == 0 ? 2 : A) << endl; //Aが移動する }else if(abs(S - A) <= abs(S - B)){ cout << abs(S - A) + S << endl; }else{ int a = abs(S - B) + abs(S - A) + A; int b = abs(S - B) + (S - 1) + abs(1 - A) + 1; if(A == 0)a += 1; //cout << a << " " << b << endl; cout << min(a,b) << endl; } }