program main implicit none integer::A,B,S,move=0 read *,A,B,S if(A.eq.0) then move = move + 1 A = 1 end if if(S.eq.1) then move = move + A else if(ABS(B-S).lt.ABS(A-S)) then if(B.lt.A) then move = move + ABS(B-S) + MIN((S-1),ABS(A-S)) + A else move = move + ABS(B-S) + ABS(S-A) + A end if else move = move + ABS(A-S) + S end if print '(i0)', move end program main