program easy_linear

 implicit none
 integer::a,b,c,k,ans

 read*,a,b,c,k

ans=0

aa: if(a<=k) then 
    ans=ans+a
    k=k-a
bb:   if(b<=k) then
      k=k-b
dd:     if(k>=0) then
          ans=ans-k
        end if dd
      else
       go to 200
      end if bb
    else
     ans=ans+k
     go to 200
    end if aa

200 print*,ans

end program easy_linear
  