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(ABS(B-S).lt.ABS(A-S)) then if(B.lt.A) then move = move + ABS(B-S) + (S-1) + 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