#include #include #include #include extern int getchar_unlocked(void); extern int putchar_unlocked(int); #define DEBUGe // --------------------------- #define NOP do{}while(0) #define gc(d) (d)=getchar_unlocked() #define pc(d) putchar_unlocked(d) #define mygc(c) (c)=getchar() #define PRINCR pc('\n') #ifdef DEBUG #include #define TRACE(...) do{fprintf(stderr,__VA_ARGS__);}while(0) #define TRACECR do{fprintf(stderr,"\n");}while(0) static clock_t startclock; void DEBUGSTART(void){TRACE("--DEBUG MODE --\n");startclock=clock();} void DEBUGEND(void){startclock=clock()-startclock;TRACE("--finish --\ntime is %.3fms\n",startclock/1000.);} #else #define TRACE(...) NOP #define TRACECR NOP void DEBUGSTART(void){return;} void DEBUGEND(void){return;} #endif // --------------------------- #define NOCR(strig) do{char *p;p=strchr(strig,'\n');if(p)*p='\0';}while(0) #define SWAP(type,a,b) do{type _c;_c=a;a=b;b=_c;}while(0) #define MAX(a,b) ((a)>(b)?(a):(b)) #define MID(a,b,c) ((a)>(b)?(b)>(c)?(b):(a)>(c)?(c):(a):(c)>(b)?(b):(c)>(a)?(c):(a)) #define MIN(a,b) ((a)<(b)?(a):(b)) #define REP(a,b) for(int a=0;a<(int)(b);++a) #define REP1(a,b) for(int a=1;a<=(int)(b);++a) #define ll long long #define INPUT GETLINE #define ull unsigned ll #define ui unsigned int static char *GETWORD(char* str) {char c;char *cp;cp=&str[0];gc(c);while(c!=EOF){if((c==' ')||(c=='\n'))break;*cp++=c;gc(c);}*cp='\0';return &str[0];} #define GETLINE(str) do{char *p;fgets(str,sizeof(str),stdin);p=strchr(str,'\n');if(p)*p='\0';}while(0) #define REP(a,b) for(int a=0;a<(int)(b);++a) static int GETLINEINT(void) {char s[34];GETLINE(s);return atoi(s);} static int GETWORDINT(void) {char s[34];GETWORD(s);return atoi(s);} static ll GETWORDLL(void) {char s[34];GETWORD(s);return atoll(s);} static long GETLINELONG(void) {char s[34];GETLINE(s);return atol(s);} static ll GETLINELL(void) {char s[34];GETLINE(s);return atoll(s);} static int cmpint123(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;} static int cmpint321(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;} static ll midll(ll a,ll b,ll c){if(a>b){if(b>c){return b;}else if(a>c){return c;} else{return a;}}else{if(c>b){return b;}else if(c>a){return c;}else{return a;}}} static int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;} // 最大公約数 static ll gcdll(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;} // 最大公約数 #define Yes(a) printf("%s\n",((a)?"Yes":"No")) // --------------------------- // グローバル変数 ll A,B,S; // --------------------------- void read(void) { A = GETWORDINT(); B = GETWORDINT(); S = GETWORDINT(); } // ********************* int main( void ) { int moved = 0; read(); //TRACE("A %lld\nB %lld\n",A,B); if( S == 1 ) { TRACE("S==1\n"); moved = abs(A-1)+1; } else { if( abs(A-S) > abs(B-S) ) { TRACE("abs(A-S) > abs(B-S)\n"); if( A > B ) { TRACE("A > B\n"); moved = abs(B-S) + abs(S-1) + A ; } else { TRACE("A <= B\n"); moved = abs(B-S) + abs(S-A) + A + ((A==0)?1:0); } } else { TRACE("abs(A-S) <= abs(B-S)\n"); moved = abs( A-S ) + S; } } printf("%d\n",moved); DEBUGEND(); }